2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * ================================================================================
9 * Modifications (C) 2019 Ericsson
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.provider.topology;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.Mock;
32 import org.mockito.Mockito;
33 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.UUID;
34 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.common.request.header.CommonRequestHeader;
35 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.config.payload.ConfigPayload;
36 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.vnf.resource.VnfResource;
37 import org.onap.appc.configuration.Configuration;
38 import org.onap.appc.configuration.ConfigurationFactory;
39 import org.onap.appc.provider.AppcProvider;
40 import org.powermock.core.classloader.annotations.PrepareForTest;
41 import org.powermock.modules.junit4.PowerMockRunner;
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.when;
49 import java.util.Properties;
51 @RunWith(PowerMockRunner.class)
52 @PrepareForTest(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();
76 topologyService.modifyConfig(commonRequestHeader, configPayload);
78 Mockito.verify(topologyService, times(1)).callGraph(Mockito.any(Properties.class));
82 public void migrate() throws Exception {
83 CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
84 doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
85 VnfResource vnfResource = mock(VnfResource.class);
86 UUID uuid = mock(UUID.class);
87 doReturn("uuid-value").when(uuid).getValue();
88 doReturn(uuid).when(vnfResource).getVmId();
90 topologyService.migrate(commonRequestHeader, vnfResource);
92 Mockito.verify(topologyService, times(1)).callGraph(Mockito.any(Properties.class));
96 public void restart() throws Exception {
97 CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
98 doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
99 VnfResource vnfResource = mock(VnfResource.class);
100 UUID uuid = mock(UUID.class);
101 doReturn("uuid-value").when(uuid).getValue();
102 doReturn(uuid).when(vnfResource).getVmId();
104 topologyService.restart(commonRequestHeader, vnfResource);
106 Mockito.verify(topologyService, times(1)).callGraph(Mockito.any(Properties.class));
110 public void rebuild() throws Exception {
111 CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
112 doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
113 VnfResource vnfResource = mock(VnfResource.class);
114 UUID uuid = mock(UUID.class);
115 doReturn("uuid-value").when(uuid).getValue();
116 doReturn(uuid).when(vnfResource).getVmId();
118 topologyService.rebuild(commonRequestHeader, vnfResource);
120 Mockito.verify(topologyService, times(1)).callGraph(Mockito.any(Properties.class));
124 public void snapshot() throws Exception {
125 CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
126 doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
127 VnfResource vnfResource = mock(VnfResource.class);
128 UUID uuid = mock(UUID.class);
129 doReturn("uuid-value").when(uuid).getValue();
130 doReturn(uuid).when(vnfResource).getVmId();
132 topologyService.snapshot(commonRequestHeader, vnfResource);
134 Mockito.verify(topologyService, times(1)).callGraph(Mockito.any(Properties.class));
138 public void vmstatuscheck() throws Exception {
139 CommonRequestHeader commonRequestHeader = mock(CommonRequestHeader.class);
140 doReturn("request-id").when(commonRequestHeader).getServiceRequestId();
141 VnfResource vnfResource = mock(VnfResource.class);
142 UUID uuid = mock(UUID.class);
143 doReturn("uuid-value").when(uuid).getValue();
144 doReturn(uuid).when(vnfResource).getVmId();
146 topologyService.vmstatuscheck(commonRequestHeader, vnfResource);
148 Mockito.verify(topologyService, times(1)).callGraph(Mockito.any(Properties.class));