2 * Copyright (C) 2020 Huawei, Inc. and others. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.usecaseui.server.service.lcm.impl;
18 import okhttp3.RequestBody;
19 import okhttp3.Response;
20 import okhttp3.ResponseBody;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.onap.usecaseui.server.bean.lcm.sotne2eservice.E2EServiceInstanceRequest;
24 import org.onap.usecaseui.server.bean.lcm.sotne2eservice.ModelConfig;
25 import org.onap.usecaseui.server.service.lcm.SotnServiceTemplateService;
26 import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService;
27 import org.onap.usecaseui.server.service.lcm.domain.so.SOService;
28 import org.onap.usecaseui.server.service.lcm.domain.so.bean.ServiceOperation;
29 import org.onap.usecaseui.server.service.sotn.impl.SOTNServiceImpl;
31 import java.util.HashMap;
33 import static org.mockito.Matchers.anyObject;
34 import static org.mockito.Matchers.eq;
35 import static org.mockito.Mockito.mock;
36 import static org.mockito.Mockito.when;
37 import static org.onap.usecaseui.server.util.CallStub.failedCall;
38 import static org.onap.usecaseui.server.util.CallStub.successfulCall;
40 public class SotnServiceTemplateServiceImplTest {
42 AAIService aaiService;
44 ServiceOperation serviceOperation;
45 SotnServiceTemplateServiceImpl sotnServiceTemplateService;
47 public void before() throws Exception {
48 aaiService = mock(AAIService.class);
49 soService = mock(SOService.class);
50 sotnServiceTemplateService = new SotnServiceTemplateServiceImpl();
54 public void instantiate_CCVPN_ServiceTest() {
55 when(soService.instantiateSOTNService(new E2EServiceInstanceRequest())).thenReturn(successfulCall(serviceOperation));
56 sotnServiceTemplateService.instantiate_CCVPN_Service(new HashMap<String, Object>());
60 public void instantiate_CCVPN_ServiceWithThrowException() {
61 when(soService.instantiateSOTNService(new E2EServiceInstanceRequest())).thenReturn(failedCall("failed to create Service"));
62 sotnServiceTemplateService.instantiate_CCVPN_Service(new HashMap<String, Object>());
66 public void createSotnServiceTest() {
67 when(soService.instantiateSOTNService(new E2EServiceInstanceRequest())).thenReturn(successfulCall(serviceOperation));
68 sotnServiceTemplateService.createSotnService(new E2EServiceInstanceRequest());
72 public void createSotnServiceWithThrowException() {
73 when(soService.instantiateSOTNService(new E2EServiceInstanceRequest())).thenReturn(failedCall("failed to create Service"));
74 sotnServiceTemplateService.createSotnService(new E2EServiceInstanceRequest());
78 public void getServiceInstancesInfoTest() throws Exception {
79 ResponseBody result=null;
80 when(aaiService.getServiceInstancesForEdge("ISAAC","SOTN","ISAAC")).thenReturn(successfulCall(result));
81 sotnServiceTemplateService.getServiceInstancesInfo("ISAAC","SOTN","ISAAC");
85 public void getServiceInstancesInfoWithThrowException() throws Exception {
86 when(aaiService.getServiceInstancesForEdge("ISAAC","SOTN","ISAAC")).thenReturn(failedCall("Failed to get Service Instance"));
87 sotnServiceTemplateService.getServiceInstancesInfo("ISAAC","SOTN","ISAAC");
91 public void getTerminationPointTest() throws Exception {
92 ResponseBody result = null;
93 when(aaiService.getTerminationPoint("SOTN","123")).thenReturn(successfulCall(result));
94 sotnServiceTemplateService.getTerminationPoint("SOTN", "123");
98 public void getTerminationPointWithThrowException() throws Exception {
99 when(aaiService.getTerminationPoint("SOTN","123")).thenReturn(failedCall("Failed to get connectivity information."));
100 sotnServiceTemplateService.getTerminationPoint("SOTN", "123");
104 public void getSOTNPinterfaceByVpnIdTest() throws Exception {
105 ResponseBody result = null;
106 when(aaiService.getPinterfaceByVpnId("1")).thenReturn(successfulCall(result));
107 sotnServiceTemplateService.getSOTNPinterfaceByVpnId("1");
111 public void getSOTNPinterfaceByVpnIdWithThrowException() throws Exception {
112 when(aaiService.getPinterfaceByVpnId("1")).thenReturn(failedCall("failed to get VPN ID"));
113 sotnServiceTemplateService.getSOTNPinterfaceByVpnId("1");
117 public void getSOTNPnfTest() throws Exception {
118 ResponseBody result = null;
119 when(aaiService.getPnfInfo("test")).thenReturn(successfulCall(result));
120 sotnServiceTemplateService.getSOTNPnf("test");
124 public void getSOTNPnfWithThrowException() throws Exception {
125 when(aaiService.getPnfInfo("test")).thenReturn(failedCall("Failed to get PNF info."));
126 sotnServiceTemplateService.getSOTNPnf("test");
130 public void getSOTNLinkbyNameTest() throws Exception {
131 ResponseBody result = null;
132 when(aaiService.getSpecificLogicalLink("link")).thenReturn(successfulCall(result));
133 sotnServiceTemplateService.getSOTNLinkbyName("link");
137 public void getSOTNLinkbyNameWithThrowException() throws Exception {
138 when(aaiService.getSpecificLogicalLink("link")).thenReturn(failedCall("Failed to get link info."));
139 sotnServiceTemplateService.getSOTNLinkbyName("link");
144 public void getUNIInfoTest() throws Exception {
145 ResponseBody result = null;
146 when(aaiService.getUNIInfo("uni-id")).thenReturn(successfulCall(result));
147 sotnServiceTemplateService.getUNIInfo("uni-id");
150 public void getUNIInfoWithThrowException() throws Exception {
151 when(aaiService.getUNIInfo("uni-id")).thenReturn(failedCall("Failed to get link info."));
152 sotnServiceTemplateService.getUNIInfo("uni-id");
155 public void getVnfsTest() throws Exception {
156 ResponseBody result = null;
157 when(aaiService.getVNFsDetail("vnf-id")).thenReturn(successfulCall(result));
158 sotnServiceTemplateService.getVnfs("vnf-id");
161 public void getVnfsWithThrowException() throws Exception {
162 when(aaiService.getVNFsDetail("vnf-id")).thenReturn(failedCall("Failed to get link info."));
163 sotnServiceTemplateService.getVnfs("vnf-id");
166 public void getReadFile_unniTest() throws Exception {
167 ModelConfig mdl = new ModelConfig();
168 sotnServiceTemplateService.readFile_unni();
171 public void getReadFileTest() throws Exception {
172 ModelConfig mdl = new ModelConfig();
173 sotnServiceTemplateService.readFile();
176 public void getSOTNSiteInformationTopologyTest() throws Exception {
177 ResponseBody result = null;
178 when(aaiService.getServiceInstancesForEdge("1","SOTN","ISAAC")).thenReturn(successfulCall(result));
179 sotnServiceTemplateService.getSOTNSiteInformationTopology("SOTN", "ISAAC");
182 public void getSOTNSiteInformationTopologyWithThrowException() throws Exception {
183 when(aaiService.getServiceInstancesForEdge("1","SOTN","ISAAC")).thenReturn(failedCall("Failed to get connectivity."));
184 sotnServiceTemplateService.getSOTNSiteInformationTopology("SOTN", "ISAAC");
187 public void getServiceTest() throws Exception {
188 ResponseBody result = null;
189 when(aaiService.getServiceInstancesForEdge("1","SOTN","ISAAC")).thenReturn(successfulCall(result));
190 ResponseBody result1 = null;
191 when(aaiService.getConnectivityInformation("1")).thenReturn(successfulCall(result1));
192 ResponseBody result2 = null;
193 when(aaiService.getAllotedResourceFor5G("1", "SONT", "ISAAC", "2")).thenReturn(successfulCall(result2));
194 sotnServiceTemplateService.getService("SOTN", "ISAAC");
197 public void getServiceWithThrowException() throws Exception {
198 ResponseBody result = null;
199 when(aaiService.getServiceInstancesForEdge("1","SOTN","ISAAC")).thenReturn(failedCall("failed to get instances"));
200 ResponseBody result1 = null;
201 when(aaiService.getConnectivityInformation("1")).thenReturn(failedCall("Failed to get connectivity"));
202 ResponseBody result2 = null;
203 when(aaiService.getAllotedResourceFor5G("1", "SONT", "ISAAC", "2")).thenReturn(failedCall("failed to get allocated resource"));
204 sotnServiceTemplateService.getService("SOTN", "ISAAC");
207 public void getSOTNServiceInformationTopologyTest() throws Exception {
208 ResponseBody result = null;
209 when(aaiService.getServiceInstancesForEdge("ISAAC", "example-service-type-val-52265", "NNI-001")).thenReturn(successfulCall(result));
210 sotnServiceTemplateService.getServiceInformationTopology("example-service-type-val-52265", "NNI-001");
213 public void getSOTNServiceInformationTopologyWithThrowException() throws Exception {
214 when(aaiService.getServiceInstancesForEdge("1","SOTN","ISAAC")).thenReturn(failedCall("Failed to get connectivity."));
215 sotnServiceTemplateService.getServiceInformationTopology("SOTN", "ISAAC");
218 public void getVPNBindingInformationTopologyTest() throws Exception {
219 ResponseBody result = null;
220 when(aaiService.getServiceInstancesForEdge("ISAAC", "example-service-type-val-52265", "NNI-001")).thenReturn(successfulCall(result));
221 sotnServiceTemplateService.getVPNBindingInformationTopology("example-service-type-val-52265", "NNI-001", "vpn-bind-1");
224 public void getVPNBindingInformationTopologyWithThrowException() throws Exception {
225 ResponseBody result = null;
226 when(aaiService.getServiceInstancesForEdge("ISAAC", "example-service-type-val-52265", "NNI-001")).thenReturn(failedCall("failed to get vpn binding topology."));
227 sotnServiceTemplateService.getVPNBindingInformationTopology("example-service-type-val-52265", "NNI-001", "vpn-bind-1");
230 public void deleteServiceTest() throws Exception {
231 Response result = null;
232 RequestBody requestBody = null;
233 when(soService.terminateService("serviceId",requestBody)).thenReturn(successfulCall(null));
234 sotnServiceTemplateService.deleteService("NNI-001", "vpn-bind-1");
237 public void deleteServiceWithThrowException() throws Exception {
238 Response result = null;
239 RequestBody requestBody = null;
240 when(soService.terminateService("serviceId",requestBody)).thenReturn(failedCall("failed to delete the server."));
241 sotnServiceTemplateService.deleteService("NNI-001", "vpn-bind-1");
244 public void getNodeTest() throws Exception {
245 sotnServiceTemplateService.getNode("001", "vpn-bind-1","image.png");
248 public void getEdgeTest() throws Exception {
249 sotnServiceTemplateService.getEdge("fromid", "toId");
252 public void getSOTNResourceInformationTopologyTest() throws Exception {
253 ResponseBody result = null;
254 when(aaiService.getServiceInstancesForEdge("ISAAC", "example-service-type-val-52265", "NNI-001")).thenReturn(successfulCall(result));
255 sotnServiceTemplateService.getSOTNResourceInformationTopology("example-service-type-val-52265", "NNI-001");
258 public void getSOTNResourceInformationTopologyWithThrowException() throws Exception {
259 ResponseBody result = null;
260 when(aaiService.getServiceInstancesForEdge("ISAAC", "example-service-type-val-52265", "NNI-001")).thenReturn(failedCall("failed to get sotn resource topology."));
261 sotnServiceTemplateService.getSOTNResourceInformationTopology("example-service-type-val-52265", "NNI-001");