ffc63d70e5c69ddcf84300a0e433a724b29ff1a5
[usecase-ui/server.git] / server / src / test / java / org / onap / usecaseui / server / service / lcm / impl / SotnServiceTemplateServiceImplTest.java
1 /**
2  * Copyright (C) 2020 Huawei, Inc. and others. All rights reserved.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onap.usecaseui.server.service.lcm.impl;
17
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;
30
31 import java.util.HashMap;
32
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;
39
40 public class SotnServiceTemplateServiceImplTest {
41
42     AAIService aaiService;
43     SOService soService;
44     ServiceOperation serviceOperation;
45     SotnServiceTemplateServiceImpl sotnServiceTemplateService;
46     @Before
47     public void before() throws Exception {
48         aaiService = mock(AAIService.class);
49         soService = mock(SOService.class);
50         sotnServiceTemplateService = new SotnServiceTemplateServiceImpl();
51     }
52
53     @Test
54     public void instantiate_CCVPN_ServiceTest() {
55         when(soService.instantiateSOTNService(new E2EServiceInstanceRequest())).thenReturn(successfulCall(serviceOperation));
56         sotnServiceTemplateService.instantiate_CCVPN_Service(new HashMap<String, Object>());
57     }
58
59     @Test
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>());
63     }
64
65     @Test
66     public void createSotnServiceTest() {
67         when(soService.instantiateSOTNService(new E2EServiceInstanceRequest())).thenReturn(successfulCall(serviceOperation));
68         sotnServiceTemplateService.createSotnService(new E2EServiceInstanceRequest());
69     }
70
71     @Test
72     public void createSotnServiceWithThrowException() {
73         when(soService.instantiateSOTNService(new E2EServiceInstanceRequest())).thenReturn(failedCall("failed to create Service"));
74         sotnServiceTemplateService.createSotnService(new E2EServiceInstanceRequest());
75     }
76
77     @Test
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");
82     }
83
84     @Test
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");
88     }
89
90     @Test
91     public void getTerminationPointTest() throws Exception {
92         ResponseBody result = null;
93         when(aaiService.getTerminationPoint("SOTN","123")).thenReturn(successfulCall(result));
94         sotnServiceTemplateService.getTerminationPoint("SOTN", "123");
95     }
96
97     @Test
98     public void getTerminationPointWithThrowException() throws Exception {
99         when(aaiService.getTerminationPoint("SOTN","123")).thenReturn(failedCall("Failed to get connectivity information."));
100         sotnServiceTemplateService.getTerminationPoint("SOTN", "123");
101     }
102
103     @Test
104     public void getSOTNPinterfaceByVpnIdTest() throws Exception {
105         ResponseBody result = null;
106         when(aaiService.getPinterfaceByVpnId("1")).thenReturn(successfulCall(result));
107         sotnServiceTemplateService.getSOTNPinterfaceByVpnId("1");
108     }
109
110     @Test
111     public void getSOTNPinterfaceByVpnIdWithThrowException() throws Exception {
112         when(aaiService.getPinterfaceByVpnId("1")).thenReturn(failedCall("failed to get VPN ID"));
113         sotnServiceTemplateService.getSOTNPinterfaceByVpnId("1");
114     }
115
116     @Test
117     public void getSOTNPnfTest() throws Exception {
118         ResponseBody result = null;
119         when(aaiService.getPnfInfo("test")).thenReturn(successfulCall(result));
120         sotnServiceTemplateService.getSOTNPnf("test");
121     }
122
123     @Test
124     public void getSOTNPnfWithThrowException() throws Exception {
125         when(aaiService.getPnfInfo("test")).thenReturn(failedCall("Failed to get PNF info."));
126         sotnServiceTemplateService.getSOTNPnf("test");
127     }
128
129     @Test
130     public void getSOTNLinkbyNameTest() throws Exception {
131         ResponseBody result = null;
132         when(aaiService.getSpecificLogicalLink("link")).thenReturn(successfulCall(result));
133         sotnServiceTemplateService.getSOTNLinkbyName("link");
134     }
135
136     @Test
137     public void getSOTNLinkbyNameWithThrowException() throws Exception {
138         when(aaiService.getSpecificLogicalLink("link")).thenReturn(failedCall("Failed to get link info."));
139         sotnServiceTemplateService.getSOTNLinkbyName("link");
140     }
141
142
143     @Test
144     public void getUNIInfoTest() throws Exception {
145         ResponseBody result = null;
146         when(aaiService.getUNIInfo("uni-id")).thenReturn(successfulCall(result));
147         sotnServiceTemplateService.getUNIInfo("uni-id");
148     }
149     @Test
150     public void getUNIInfoWithThrowException() throws Exception {
151         when(aaiService.getUNIInfo("uni-id")).thenReturn(failedCall("Failed to get link info."));
152         sotnServiceTemplateService.getUNIInfo("uni-id");
153     }
154     @Test
155     public void getVnfsTest() throws Exception {
156         ResponseBody result = null;
157         when(aaiService.getVNFsDetail("vnf-id")).thenReturn(successfulCall(result));
158         sotnServiceTemplateService.getVnfs("vnf-id");
159     }
160     @Test
161     public void getVnfsWithThrowException() throws Exception {
162         when(aaiService.getVNFsDetail("vnf-id")).thenReturn(failedCall("Failed to get link info."));
163         sotnServiceTemplateService.getVnfs("vnf-id");
164     }
165     @Test
166     public void getReadFile_unniTest() throws Exception {
167         ModelConfig mdl = new ModelConfig();
168         sotnServiceTemplateService.readFile_unni();
169     }
170     @Test
171     public void getReadFileTest() throws Exception {
172         ModelConfig mdl = new ModelConfig();
173         sotnServiceTemplateService.readFile();
174     }
175     @Test
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");
180     }
181     @Test
182     public void getSOTNSiteInformationTopologyWithThrowException() throws Exception {
183         when(aaiService.getServiceInstancesForEdge("1","SOTN","ISAAC")).thenReturn(failedCall("Failed to get connectivity."));
184         sotnServiceTemplateService.getSOTNSiteInformationTopology("SOTN", "ISAAC");
185     }
186     @Test
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");
195     }
196     @Test
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");
205     }
206     @Test
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");
211     }
212     @Test
213     public void getSOTNServiceInformationTopologyWithThrowException() throws Exception {
214         when(aaiService.getServiceInstancesForEdge("1","SOTN","ISAAC")).thenReturn(failedCall("Failed to get connectivity."));
215         sotnServiceTemplateService.getServiceInformationTopology("SOTN", "ISAAC");
216     }
217     @Test
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");
222     }
223     @Test
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");
228     }
229     @Test
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");
235     }
236     @Test
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");
242     }
243     @Test
244     public void getNodeTest() throws Exception {
245         sotnServiceTemplateService.getNode("001", "vpn-bind-1","image.png");
246     }
247     @Test
248     public void getEdgeTest() throws Exception {
249         sotnServiceTemplateService.getEdge("fromid", "toId");
250     }
251     @Test
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");
256     }
257     @Test
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");
262     }
263 }
264