2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.openecomp.appc.provider.topology;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.mockito.Mock;
31 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.UUID;
32 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.common.request.header.CommonRequestHeader;
33 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.config.payload.ConfigPayload;
34 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.vnf.resource.VnfResource;
35 import org.openecomp.appc.configuration.Configuration;
36 import org.openecomp.appc.configuration.ConfigurationFactory;
37 import org.openecomp.appc.provider.AppcProvider;
38 import org.powermock.api.mockito.PowerMockito;
39 import org.powermock.core.classloader.annotations.PrepareForTest;
40 import org.powermock.modules.junit4.PowerMockRunner;
42 import static org.mockito.Matchers.any;
43 import static org.mockito.Mockito.doReturn;
44 import static org.mockito.Mockito.mock;
45 import static org.mockito.internal.verification.VerificationModeFactory.times;
46 import static org.powermock.api.mockito.PowerMockito.mockStatic;
47 import static org.powermock.api.mockito.PowerMockito.spy;
48 import static org.powermock.api.mockito.PowerMockito.verifyPrivate;
49 import static org.powermock.api.mockito.PowerMockito.when;
51 @RunWith(PowerMockRunner.class)
52 @PrepareForTest({TopologyService.class, ConfigurationFactory.class})
53 public class TopologyServiceTest {
55 private AppcProvider appcProvider;
56 private TopologyService topologyService;
59 public void setUp() throws Exception {
60 mockStatic(ConfigurationFactory.class);
61 Configuration configuration = mock(Configuration.class);
62 when(ConfigurationFactory.getConfiguration()).thenReturn(configuration);
63 doReturn("NODE_NAME").when(configuration).getProperty("appc.provider.vfodl.url");
65 topologyService = spy(new TopologyService(appcProvider));
69 public void modifyConfig() throws Exception {
70 CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
71 doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
72 ConfigPayload configPayload = mock(ConfigPayload.class);
73 doReturn("url").when(configPayload).getConfigUrl();
74 doReturn("configJson").when(configPayload).getConfigJson();
75 PowerMockito.doReturn(true).when(topologyService, "callGraph", any());
77 topologyService.modifyConfig(commonRequestHeader, configPayload);
79 verifyPrivate(topologyService, times(1)).invoke("callGraph", any());
83 public void migrate() throws Exception {
84 CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
85 doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
86 VnfResource vnfResource = mock(VnfResource.class);
87 UUID uuid = mock(UUID.class);
88 doReturn("uuid-value").when(uuid).getValue();
89 doReturn(uuid).when(vnfResource).getVmId();
90 PowerMockito.doReturn(true).when(topologyService, "callGraph", any());
92 topologyService.migrate(commonRequestHeader, vnfResource);
94 verifyPrivate(topologyService, times(1)).invoke("callGraph", any());
98 public void restart() throws Exception {
99 CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
100 doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
101 VnfResource vnfResource = mock(VnfResource.class);
102 UUID uuid = mock(UUID.class);
103 doReturn("uuid-value").when(uuid).getValue();
104 doReturn(uuid).when(vnfResource).getVmId();
105 PowerMockito.doReturn(true).when(topologyService, "callGraph", any());
107 topologyService.restart(commonRequestHeader, vnfResource);
109 verifyPrivate(topologyService, times(1)).invoke("callGraph", any());
113 public void rebuild() throws Exception {
114 CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
115 doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
116 VnfResource vnfResource = mock(VnfResource.class);
117 UUID uuid = mock(UUID.class);
118 doReturn("uuid-value").when(uuid).getValue();
119 doReturn(uuid).when(vnfResource).getVmId();
120 PowerMockito.doReturn(true).when(topologyService, "callGraph", any());
122 topologyService.rebuild(commonRequestHeader, vnfResource);
124 verifyPrivate(topologyService, times(1)).invoke("callGraph", any());
128 public void snapshot() throws Exception {
129 CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
130 doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
131 VnfResource vnfResource = mock(VnfResource.class);
132 UUID uuid = mock(UUID.class);
133 doReturn("uuid-value").when(uuid).getValue();
134 doReturn(uuid).when(vnfResource).getVmId();
135 PowerMockito.doReturn(true).when(topologyService, "callGraph", any());
137 topologyService.snapshot(commonRequestHeader, vnfResource);
139 verifyPrivate(topologyService, times(1)).invoke("callGraph", any());
143 public void vmstatuscheck() throws Exception {
144 CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
145 doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
146 VnfResource vnfResource = mock(VnfResource.class);
147 UUID uuid = mock(UUID.class);
148 doReturn("uuid-value").when(uuid).getValue();
149 doReturn(uuid).when(vnfResource).getVmId();
150 PowerMockito.doReturn(true).when(topologyService, "callGraph", any());
152 topologyService.vmstatuscheck(commonRequestHeader, vnfResource);
154 verifyPrivate(topologyService, times(1)).invoke("callGraph", any());