2 * Copyright 2016-2017 ZTE Corporation.
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.MediaType;
20 import okio.BufferedSource;
21 import org.jetbrains.annotations.NotNull;
22 import org.jetbrains.annotations.Nullable;
23 import org.junit.Assert;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.mockito.Mockito;
27 import org.onap.usecaseui.server.bean.ServiceBean;
28 import org.onap.usecaseui.server.bean.lcm.VfNsPackageInfo;
29 import org.onap.usecaseui.server.service.lcm.PackageDistributionService;
30 import org.onap.usecaseui.server.service.lcm.ServiceLcmService;
31 import org.onap.usecaseui.server.service.lcm.domain.aai.AAIClient;
32 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.VimInfo;
33 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.VimInfoRsp;
34 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.nsServiceRsp;
35 import org.onap.usecaseui.server.service.lcm.domain.sdc.SDCCatalogService;
36 import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.SDCServiceTemplate;
37 import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.Vnf;
38 import org.onap.usecaseui.server.service.lcm.domain.vfc.VfcService;
39 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Csar;
40 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.DistributionResult;
41 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Job;
42 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.JobStatus;
43 import org.onap.usecaseui.server.service.lcm.domain.vfc.exceptions.VfcException;
45 import okhttp3.ResponseBody;
46 import retrofit2.Call;
48 import java.io.IOException;
49 import java.util.ArrayList;
50 import java.util.Collections;
51 import java.util.List;
53 import jakarta.servlet.ReadListener;
54 import jakarta.servlet.ServletInputStream;
55 import jakarta.servlet.http.HttpServletRequest;
57 import static org.hamcrest.CoreMatchers.equalTo;
58 import static org.junit.Assert.assertNotEquals;
59 import static org.junit.Assert.assertNotNull;
60 import static org.mockito.ArgumentMatchers.eq;
61 import static org.mockito.Mockito.mock;
62 import static org.mockito.Mockito.when;
63 import static org.onap.usecaseui.server.service.lcm.domain.sdc.consts.SDCConsts.*;
64 import static org.onap.usecaseui.server.util.CallStub.emptyBodyCall;
65 import static org.onap.usecaseui.server.util.CallStub.failedCall;
66 import static org.onap.usecaseui.server.util.CallStub.successfulCall;
68 public class DefaultPackageDistributionServiceTest {
70 private ResponseBody result;
73 private HttpServletRequest mockRequest() throws IOException {
74 HttpServletRequest request = mock(HttpServletRequest.class);
75 when(request.getContentLength()).thenReturn(0);
76 ServletInputStream inStream = new ServletInputStream() {
78 public boolean isFinished() {
83 public boolean isReady() {
88 public void setReadListener(ReadListener readListener) {
93 public int read() throws IOException {
97 when(request.getInputStream()).thenReturn(inStream);
103 public void before() throws Exception {
104 result= new ResponseBody() {
107 public MediaType contentType() {
108 return MediaType.parse("application/json; charset=utf-8");
112 public long contentLength() {
118 public BufferedSource source() {
126 public void itCanRetrievePackageFromSDCAndAAI() {
127 List<SDCServiceTemplate> serviceTemplate = Collections.singletonList(new SDCServiceTemplate("1", "1", "service", "V1","", ""));
129 o.setInvariantUUID("2");
132 List<Vnf> vnf = Collections.singletonList(o);
133 SDCCatalogService sdcService = newSDCService(serviceTemplate, vnf);
135 List<VimInfo> vim = Collections.singletonList(new VimInfo("owner", "regionId"));
136 AAIClient aaiClient = newAAIService(vim);
138 PackageDistributionService service = new DefaultPackageDistributionService(sdcService, null, null);
140 Assert.assertThat(service.retrievePackageInfo(), equalTo(new VfNsPackageInfo(serviceTemplate, vnf)));
143 private AAIClient newAAIService(List<VimInfo> vim) {
144 AAIClient aaiClient = mock(AAIClient.class);
145 VimInfoRsp rsp = new VimInfoRsp();
146 rsp.setCloudRegion(vim);
147 Call<VimInfoRsp> vimCall = successfulCall(rsp);
148 when(aaiClient.listVimInfo()).thenReturn(vimCall);
152 private SDCCatalogService newSDCService(List<SDCServiceTemplate> serviceTemplate, List<Vnf> vnf) {
153 SDCCatalogService sdcService = mock(SDCCatalogService.class);
155 Call<List<SDCServiceTemplate>> serviceCall = successfulCall(serviceTemplate);
156 when(sdcService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(serviceCall);
158 Call<List<Vnf>> vnfCall = successfulCall(vnf);
159 when(sdcService.listResources(RESOURCETYPE_VF)).thenReturn(vnfCall);
164 public void retrievePackageWillThrowExceptionWhenSDCIsNotAvailable() {
165 SDCCatalogService sdcService = mock(SDCCatalogService.class);
166 Call<List<Vnf>> serviceCall = failedCall("SDC is not available!");
167 Call<List<SDCServiceTemplate>> serviceCall1 = failedCall("SDC is not available!");
168 when(sdcService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(serviceCall1);
169 when(sdcService.listResources(RESOURCETYPE_VF)).thenReturn(serviceCall);
171 List<VimInfo> vim = Collections.singletonList(new VimInfo("owner", "regionId"));
172 AAIClient aaiClient = newAAIService(vim);
174 PackageDistributionService service = new DefaultPackageDistributionService(sdcService, null, null);
175 service.retrievePackageInfo();
179 public void retrievePackageWillBeEmptyWhenNoNsServiceAndVfInSDC() {
180 SDCCatalogService sdcService = mock(SDCCatalogService.class);
181 Call<List<SDCServiceTemplate>> serviceCall = emptyBodyCall();
182 when(sdcService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(serviceCall);
184 Call<List<Vnf>> resourceCall = emptyBodyCall();
185 when(sdcService.listResources(RESOURCETYPE_VF)).thenReturn(resourceCall);
187 PackageDistributionService service = new DefaultPackageDistributionService(sdcService, null, null);
188 VfNsPackageInfo vfNsPackageInfo = service.retrievePackageInfo();
190 Assert.assertTrue("ns should be empty!", vfNsPackageInfo.getNsPackage().isEmpty());
191 Assert.assertTrue("vf should be empty!", vfNsPackageInfo.getVnfPackages().isEmpty());
195 public void itCanPostNsPackageToVFC() {
196 VfcService vfcService = mock(VfcService.class);
197 Csar csar = new Csar();
198 DistributionResult result = new DistributionResult();
199 result.setStatus("status");
200 result.setStatusDescription("description");
201 result.setErrorCode("errorcode");
202 when(vfcService.distributeNsPackage(csar)).thenReturn(successfulCall(result));
203 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
205 Assert.assertSame(result, service.postNsPackage(csar));
208 @Test(expected = VfcException.class)
209 public void postNsPackageWillThrowExceptionWhenVFCIsNotAvailable() {
210 VfcService vfcService = mock(VfcService.class);
211 Csar csar = new Csar();
212 when(vfcService.distributeNsPackage(csar)).thenReturn(failedCall("VFC is not available!"));
213 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
214 service.postNsPackage(csar);
217 @Test(expected = VfcException.class)
218 public void postNsPackageWillThrowExceptionWhenVFCResponseError() {
219 VfcService vfcService = mock(VfcService.class);
220 Csar csar = new Csar();
221 when(vfcService.distributeNsPackage(csar)).thenReturn(emptyBodyCall());
222 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
223 service.postNsPackage(csar);
227 public void itCanPostVnfPackageToVFC() {
228 VfcService vfcService = mock(VfcService.class);
229 Csar csar = new Csar();
231 when(vfcService.distributeVnfPackage(csar)).thenReturn(successfulCall(job));
232 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
234 Assert.assertSame(job, service.postVfPackage(csar));
237 @Test(expected = VfcException.class)
238 public void postVnfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
239 VfcService vfcService = mock(VfcService.class);
240 Csar csar = new Csar();
241 when(vfcService.distributeVnfPackage(csar)).thenReturn(failedCall("VFC is not available!"));
242 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
243 service.postVfPackage(csar);
246 @Test(expected = VfcException.class)
247 public void postVnfPackageWillThrowExceptionWhenVFCResponseError() {
248 VfcService vfcService = mock(VfcService.class);
249 Csar csar = new Csar();
250 when(vfcService.distributeVnfPackage(csar)).thenReturn(emptyBodyCall());
251 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
252 service.postVfPackage(csar);
256 public void itCanGetJobStatusFromVFC() {
257 VfcService vfcService = mock(VfcService.class);
259 String responseId = "1";
260 JobStatus jobStatus = new JobStatus();
261 when(vfcService.getJobStatus(jobId, responseId)).thenReturn(successfulCall(jobStatus));
262 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
264 Assert.assertSame(jobStatus, service.getJobStatus(jobId, responseId));
267 @Test(expected = VfcException.class)
268 public void getJobStatusWillThrowExceptionWhenVFCIsNotAvailable() {
269 VfcService vfcService = mock(VfcService.class);
271 String responseId = "1";
272 when(vfcService.getJobStatus(jobId, responseId)).thenReturn(failedCall("VFC is not available!"));
273 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
274 service.getJobStatus(jobId, responseId);
277 @Test(expected = VfcException.class)
278 public void getJobStatusWillThrowExceptionWhenVFCResponseError() {
279 VfcService vfcService = mock(VfcService.class);
281 String responseId = "1";
282 when(vfcService.getJobStatus(jobId, responseId)).thenReturn(emptyBodyCall());
283 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
284 service.getJobStatus(jobId, responseId);
288 public void itCanGetNsLcmJobStatusFromVFC() {
289 VfcService vfcService = mock(VfcService.class);
291 String responseId = "1";
292 String serviceId= "1";
293 String operationType= "1";
294 JobStatus jobStatus = new JobStatus();
295 when(vfcService.getNsLcmJobStatus(jobId, responseId)).thenReturn(successfulCall(jobStatus));
296 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
298 Assert.assertSame(jobStatus, service.getNsLcmJobStatus(serviceId,jobId, responseId,operationType));
301 @Test(expected = VfcException.class)
302 public void getNsLcmJobStatusWillThrowExceptionWhenVFCIsNotAvailable() {
303 VfcService vfcService = mock(VfcService.class);
305 String responseId = "1";
306 String serviceId= "1";
307 String operationType= "1";
308 when(vfcService.getNsLcmJobStatus(jobId, responseId)).thenReturn(failedCall("VFC is not available!"));
309 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
310 service.getNsLcmJobStatus(serviceId,jobId, responseId,operationType);
313 @Test(expected = VfcException.class)
314 public void getNsLcmJobStatusWillThrowExceptionWhenVFCResponseError() {
315 VfcService vfcService = mock(VfcService.class);
317 String responseId = "1";
318 String serviceId= "1";
319 String operationType= "1";
320 when(vfcService.getNsLcmJobStatus(jobId, responseId)).thenReturn(emptyBodyCall());
321 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
322 service.getNsLcmJobStatus(serviceId,jobId, responseId,operationType);
326 public void itCanDeleteNsPackage() {
328 DistributionResult result = new DistributionResult();
329 VfcService vfcService = mock(VfcService.class);
330 when(vfcService.deleteNsPackage(csarId)).thenReturn(successfulCall(result));
331 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
333 Assert.assertSame(result, service.deleteNsPackage(csarId));
336 @Test(expected = VfcException.class)
337 public void deleteNsPackageWillThrowExceptionWhenVFCIsNotAvailable() {
339 VfcService vfcService = mock(VfcService.class);
340 when(vfcService.deleteNsPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
341 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
342 service.deleteNsPackage(csarId);
345 @Test(expected = VfcException.class)
346 public void deleteNsPackageWillThrowExceptionWhenVFCResponseError() {
348 VfcService vfcService = mock(VfcService.class);
349 when(vfcService.deleteNsPackage(csarId)).thenReturn(emptyBodyCall());
350 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
351 service.deleteNsPackage(csarId);
355 public void itCanGetVnfPackages(){
356 //ResponseBody result=null;
357 VfcService vfcService = mock(VfcService.class);
358 when(vfcService.getVnfPackages()).thenReturn(successfulCall(result));
359 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
361 // Assert.assertSame(result, service.getVnfPackages());
362 Assert.assertNotNull(service.getVnfPackages());
366 public void getVnfPackagesThrowExceptionWhenVFCResponseError(){
368 VfcService vfcService = mock(VfcService.class);
369 when(vfcService.getVnfPackages ()).thenReturn(emptyBodyCall());
370 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
371 service.getVnfPackages();
375 public void getVnfPackagesThrowException(){
376 VfcService vfcService = mock(VfcService.class);
377 when(vfcService.getVnfPackages ()).thenReturn(failedCall("VFC is not available!"));
378 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
379 service.getVnfPackages();
383 public void itCanDeleteVFPackage() {
386 VfcService vfcService = mock(VfcService.class);
387 when(vfcService.deleteVnfPackage(csarId)).thenReturn(successfulCall(job));
388 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
390 Assert.assertSame(job, service.deleteVfPackage(csarId));
394 public void deleteVfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
396 VfcService vfcService = mock(VfcService.class);
397 when(vfcService.deleteVnfdPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
398 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
399 Assert.assertSame("{\"status\":\"FAILED\"}",service.deleteVnfPackage(csarId));
403 public void deleteVnfPackageWillThrowExceptionWhenVFCResponseError() {
405 VfcService vfcService = mock(VfcService.class);
406 when(vfcService.deleteVnfdPackage(csarId)).thenReturn(emptyBodyCall());
407 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
408 service.deleteVnfPackage(csarId);
412 public void itCanGetNetworkServicePackages() {
413 VfcService vfcService = mock(VfcService.class);
414 when(vfcService.getNetworkServicePackages()).thenReturn(successfulCall(result));
415 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
416 Assert.assertNotNull(service.getNetworkServicePackages());
420 public void getNetworkServicePackagesWillThrowExceptionWhenVFCIsNotAvailable() {
421 VfcService vfcService = mock(VfcService.class);
422 when(vfcService.getNetworkServicePackages()).thenReturn(failedCall("VFC is not available!"));
423 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
424 service.getNetworkServicePackages();
428 public void getNetworkServicePackagesWillThrowExceptionWhenVFCResponseError() {
429 VfcService vfcService = mock(VfcService.class);
430 when(vfcService.getNetworkServicePackages()).thenReturn(emptyBodyCall());
431 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
432 service.getNetworkServicePackages();
436 public void itCanGetPnfPackages(){
437 VfcService vfcService = mock(VfcService.class);
438 when(vfcService.getPnfPackages()).thenReturn(successfulCall(result));
439 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
441 Assert.assertNotNull(service.getPnfPackages());
445 public void getPnfPackagesThrowExceptionWhenVFCResponseError(){
447 VfcService vfcService = mock(VfcService.class);
448 when(vfcService.getPnfPackages ()).thenReturn(emptyBodyCall());
449 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
450 service.getPnfPackages();
454 public void getPnfPackagesThrowException(){
455 VfcService vfcService = mock(VfcService.class);
456 when(vfcService.getPnfPackages ()).thenReturn(failedCall("VFC is not available!"));
457 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
458 service.getPnfPackages();
462 public void itDownLoadNsPackage(){
463 String nsdInfoId="1";
464 ResponseBody successResponse=null;
465 VfcService vfcService = mock(VfcService.class);
466 when(vfcService.downLoadNsPackage(nsdInfoId)).thenReturn(successfulCall(successResponse));
467 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
469 String result = service.downLoadNsPackage(nsdInfoId);
470 assertNotNull(result);
471 assertNotEquals("", result);
475 public void downLoadNsPackagehrowExceptionWhenVFCResponseError(){
476 String nsdInfoId="1";
477 VfcService vfcService = mock(VfcService.class);
478 when(vfcService.downLoadNsPackage (nsdInfoId)).thenReturn(emptyBodyCall());
479 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
480 service.downLoadNsPackage(nsdInfoId);
484 public void downLoadNsPackageThrowException(){
485 String nsdInfoId="1";
486 VfcService vfcService = mock(VfcService.class);
487 when(vfcService.downLoadNsPackage (nsdInfoId)).thenReturn(failedCall("VFC is not available!"));
488 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
489 service.downLoadNsPackage(nsdInfoId);
493 public void itDownLoadPnfPackage(){
494 String pnfInfoId="1";
495 VfcService vfcService = mock(VfcService.class);
496 when(vfcService.downLoadNsPackage(pnfInfoId)).thenReturn(successfulCall(result));
497 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
499 Assert.assertSame("{\"status\":\"SUCCESS\"}", service.downLoadPnfPackage(pnfInfoId));
503 public void downLoadPnfPackagehrowExceptionWhenVFCResponseError(){
504 String pnfInfoId="1";
505 VfcService vfcService = mock(VfcService.class);
506 when(vfcService.downLoadNsPackage (pnfInfoId)).thenReturn(emptyBodyCall());
507 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
508 service.downLoadPnfPackage(pnfInfoId);
512 public void downLoadPnfPackageThrowException(){
513 String pnfInfoId="1";
514 VfcService vfcService = mock(VfcService.class);
515 when(vfcService.downLoadNsPackage (pnfInfoId)).thenReturn(failedCall("VFC is not available!"));
516 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
517 service.downLoadPnfPackage(pnfInfoId);
521 public void itDownLoadVnfPackage(){
522 String vnfInfoId="1";
523 VfcService vfcService = mock(VfcService.class);
524 when(vfcService.downLoadNsPackage(vnfInfoId)).thenReturn(successfulCall(result));
525 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
527 Assert.assertSame("{\"status\":\"SUCCESS\"}", service.downLoadVnfPackage(vnfInfoId));
531 public void downLoadVnfPackagehrowExceptionWhenVFCResponseError(){
532 String vnfInfoId="1";
533 VfcService vfcService = mock(VfcService.class);
534 when(vfcService.downLoadNsPackage (vnfInfoId)).thenReturn(failedCall("VFC is not available!"));
535 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
536 service.downLoadVnfPackage(vnfInfoId);
540 public void downLoadVnfPackageThrowException(){
541 String vnfInfoId="1";
542 VfcService vfcService = mock(VfcService.class);
543 when(vfcService.downLoadNsPackage (vnfInfoId)).thenReturn(failedCall("VFC is not available!"));
544 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
545 service.downLoadVnfPackage(vnfInfoId);
549 public void itCanDeleteNsdPackage() {
551 ResponseBody result=null;
552 VfcService vfcService = mock(VfcService.class);
553 when(vfcService.deleteNsdPackage(csarId)).thenReturn(successfulCall(result));
554 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
556 Assert.assertSame("{\"status\":\"SUCCESS\"}", service.deleteNsdPackage(csarId));
560 public void deleteNsdPackageWillThrowExceptionWhenVFCIsNotAvailable() {
562 VfcService vfcService = mock(VfcService.class);
563 when(vfcService.deleteNsdPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
564 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
565 service.deleteNsdPackage(csarId);
569 public void deleteNsdPackageWillThrowExceptionWhenVFCResponseError() {
571 VfcService vfcService = mock(VfcService.class);
572 when(vfcService.deleteNsdPackage(csarId)).thenReturn(emptyBodyCall());
573 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
574 service.deleteNsdPackage(csarId);
578 public void itCanDeleteVnfPackage() {
580 VfcService vfcService = mock(VfcService.class);
581 when(vfcService.deleteVnfdPackage(csarId)).thenReturn(successfulCall(result));
582 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
584 Assert.assertNotNull(service.deleteVnfPackage(csarId));
588 public void deleteVnfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
590 VfcService vfcService = mock(VfcService.class);
591 when(vfcService.deleteVnfdPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
592 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
593 service.deleteVnfPackage(csarId);
597 public void deleteVnfNsdPackageWillThrowExceptionWhenVFCResponseError() {
599 VfcService vfcService = mock(VfcService.class);
600 when(vfcService.deleteVnfdPackage(csarId)).thenReturn(emptyBodyCall());
601 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
602 service.deleteVnfPackage(csarId);
603 Assert.assertSame("{\"status\":\"FAILED\"}", service.deleteVnfPackage(csarId));
607 public void itCanDeletePnfdPackage() {
609 ResponseBody result=null;
611 VfcService vfcService = mock(VfcService.class);
612 when(vfcService.deletePnfdPackage(csarId)).thenReturn(successfulCall(result));
613 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
615 Assert.assertSame("{\"status\":\"SUCCESS\"}", service.deletePnfPackage(csarId));
619 public void deletePnfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
621 VfcService vfcService = mock(VfcService.class);
622 when(vfcService.deletePnfdPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
623 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
624 service.deletePnfPackage(csarId);
628 public void deletePnfPackageWillThrowExceptionWhenVFCResponseError() {
630 VfcService vfcService = mock(VfcService.class);
631 when(vfcService.deletePnfdPackage(csarId)).thenReturn(emptyBodyCall());
632 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
633 service.deletePnfPackage(csarId);
637 public void itCanDeleteNetworkServiceInstance() {
639 ResponseBody result=null;
641 VfcService vfcService = mock(VfcService.class);
642 when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(successfulCall(result));
643 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
645 Assert.assertSame("{\"status\":\"SUCCESS\"}", service.deleteNetworkServiceInstance(csarId));
649 public void deleteNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() {
651 VfcService vfcService = mock(VfcService.class);
652 when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(failedCall("VFC is not available!"));
653 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
654 service.deleteNetworkServiceInstance(csarId);
658 public void deleteNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() {
660 VfcService vfcService = mock(VfcService.class);
661 when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(emptyBodyCall());
662 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
663 service.deleteNetworkServiceInstance(csarId);
667 public void itCanCreateNetworkServiceInstance() throws IOException {
668 HttpServletRequest request = mockRequest();
669 ResponseBody result=null;
670 VfcService vfcService = mock(VfcService.class);
671 when(vfcService.createNetworkServiceInstance(Mockito.any())).thenReturn(successfulCall(result));
672 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
674 Assert.assertSame("{\"status\":\"FAILED\"}", service.createNetworkServiceInstance(request));
678 public void createNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
679 HttpServletRequest request = mockRequest();
680 VfcService vfcService = mock(VfcService.class);
681 when(vfcService.createNetworkServiceInstance(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
682 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
683 service.createNetworkServiceInstance(request);
687 public void createNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
688 HttpServletRequest request = mockRequest();
689 VfcService vfcService = mock(VfcService.class);
690 when(vfcService.createNetworkServiceInstance(Mockito.any())).thenReturn(emptyBodyCall());
691 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
692 service.createNetworkServiceInstance(request);
696 public void itCanGetNetworkServiceInfo() throws IOException {
697 nsServiceRsp ns = new nsServiceRsp();
698 List<String> list = new ArrayList<>();
699 String s = "{\"nsInstanceId\":\"nsInstanceId\"}";
701 ns.setNsServices(list);
702 VfcService vfcService = mock(VfcService.class);
703 when(vfcService.getNetworkServiceInfo()).thenReturn(successfulCall(ns));
704 ServiceLcmService serviceLcmService = mock(ServiceLcmService.class);
705 DefaultPackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, serviceLcmService);
706 when(serviceLcmService.getServiceBeanByServiceInStanceId("nsInstanceId")).thenReturn(new ServiceBean());
707 Assert.assertNotNull( service.getNetworkServiceInfo());
711 public void getNetworkServiceInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
712 VfcService vfcService = mock(VfcService.class);
713 when(vfcService.getNetworkServiceInfo()).thenReturn(failedCall("VFC is not available!"));
714 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
715 service.getNetworkServiceInfo();
719 public void getNetworkServiceInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
720 VfcService vfcService = mock(VfcService.class);
721 when(vfcService.getNetworkServiceInfo()).thenReturn(emptyBodyCall());
722 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
723 service.getNetworkServiceInfo();
729 public void itCanHealNetworkServiceInstance() throws IOException {
730 HttpServletRequest request = mockRequest();
732 ResponseBody result=null;
733 VfcService vfcService = mock(VfcService.class);
734 //when(vfcService.healNetworkServiceInstance(csarId,anyObject())).thenReturn(successfulCall(result));
735 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
737 //Assert.assertSame(result, service.healNetworkServiceInstance(request,csarId));
738 service.healNetworkServiceInstance(request,csarId);
742 public void healNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
743 HttpServletRequest request = mockRequest();
745 VfcService vfcService = mock(VfcService.class);
746 when(vfcService.healNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(failedCall("VFC is not available!"));
747 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
748 service.healNetworkServiceInstance(request,csarId);
752 public void healNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
753 HttpServletRequest request = mockRequest();
755 VfcService vfcService = mock(VfcService.class);
756 when(vfcService.healNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(emptyBodyCall());
757 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
758 service.healNetworkServiceInstance(request,csarId);
762 public void itCanScaleNetworkServiceInstance() throws IOException {
763 HttpServletRequest request = mockRequest();
765 VfcService vfcService = mock(VfcService.class);
766 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
768 String result = service.scaleNetworkServiceInstance(request,csarId);
769 assertNotNull(result);
770 assertNotEquals("", result);
774 public void scaleNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
775 HttpServletRequest request = mockRequest();
777 VfcService vfcService = mock(VfcService.class);
778 when(vfcService.scaleNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(failedCall("VFC is not available!"));
779 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
780 service.scaleNetworkServiceInstance(request,csarId);
784 public void scaleNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
785 HttpServletRequest request = mockRequest();
787 VfcService vfcService = mock(VfcService.class);
788 when(vfcService.scaleNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(emptyBodyCall());
789 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
790 service.scaleNetworkServiceInstance(request,csarId);
795 public void itCaninstantiateNetworkServiceInstance() throws IOException {
796 HttpServletRequest request = mockRequest();
797 String serviceInstanceId="1";
798 ResponseBody result=null;
799 VfcService vfcService = mock(VfcService.class);
800 //when(vfcService.instantiateNetworkServiceInstance(anyObject(),serviceInstanceId)).thenReturn(successfulCall(result));
801 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
803 service.instantiateNetworkServiceInstance(request,serviceInstanceId);
807 public void instantiateNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
808 HttpServletRequest request = mockRequest();
809 String serviceInstanceId="1";
810 VfcService vfcService = mock(VfcService.class);
811 when(vfcService.instantiateNetworkServiceInstance(Mockito.any(),eq(serviceInstanceId))).thenReturn(failedCall("VFC is not available!"));
812 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
813 service.instantiateNetworkServiceInstance(request,serviceInstanceId);
817 public void instantiateNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
818 HttpServletRequest request = mockRequest();
819 String serviceInstanceId="1";
820 VfcService vfcService = mock(VfcService.class);
821 when(vfcService.instantiateNetworkServiceInstance(Mockito.any(),eq(serviceInstanceId))).thenReturn(emptyBodyCall());
822 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
823 service.instantiateNetworkServiceInstance(request,serviceInstanceId);
828 public void itCanTerminateNetworkServiceInstance() throws IOException {
829 HttpServletRequest request = mockRequest();
831 ResponseBody result=null;
833 VfcService vfcService = mock(VfcService.class);
834 when(vfcService.terminateNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(successfulCall(result));
835 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
837 service.terminateNetworkServiceInstance(request,csarId);
841 public void terminateNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
842 HttpServletRequest request = mockRequest();
844 VfcService vfcService = mock(VfcService.class);
845 //when(vfcService.terminateNetworkServiceInstance(csarId,anyObject())).thenReturn(failedCall("VFC is not available!"));
846 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
847 service.terminateNetworkServiceInstance(request,csarId);
851 public void terminateNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
852 HttpServletRequest request = mockRequest();
854 VfcService vfcService = mock(VfcService.class);
855 when(vfcService.terminateNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(emptyBodyCall());
856 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
857 service.terminateNetworkServiceInstance(request,csarId);
861 public void itCreateNetworkServiceData() throws IOException {
862 HttpServletRequest request = mockRequest();
863 ResponseBody responseBody = null;
864 VfcService vfcService = mock(VfcService.class);
865 when(vfcService.createNetworkServiceData(Mockito.any())).thenReturn(successfulCall(responseBody));
866 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
868 String result = service.createNetworkServiceData(request);
869 assertNotNull(result);
870 assertNotEquals("", result);
874 public void createNetworkServiceDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
875 HttpServletRequest request = mockRequest();
876 VfcService vfcService = mock(VfcService.class);
877 when(vfcService.createNetworkServiceData(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
878 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
879 service.createNetworkServiceData(request);
883 public void createNetworkServiceDataWillThrowExceptionWhenVFCResponseError() throws IOException {
884 HttpServletRequest request = mockRequest();
885 VfcService vfcService = mock(VfcService.class);
886 when(vfcService.createNetworkServiceData(Mockito.any())).thenReturn(emptyBodyCall());
887 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
888 service.createNetworkServiceData(request);
892 public void itCreateVnfData() throws IOException {
893 HttpServletRequest request = mockRequest();
894 ResponseBody result=null;
895 VfcService vfcService = mock(VfcService.class);
896 when(vfcService.createVnfData(Mockito.any())).thenReturn(successfulCall(result));
897 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
899 Assert.assertSame("{\"status\":\"FAILED\"}", service.createVnfData(request));
903 public void createVnfDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
904 HttpServletRequest request = mockRequest();
905 VfcService vfcService = mock(VfcService.class);
906 when(vfcService.createVnfData(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
907 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
908 service.createVnfData(request);
912 public void createVnfDataWillThrowExceptionWhenVFCResponseError() throws IOException {
913 HttpServletRequest request = mockRequest();
914 VfcService vfcService = mock(VfcService.class);
915 when(vfcService.createVnfData(Mockito.any())).thenReturn(emptyBodyCall());
916 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
917 service.createVnfData(request);
921 public void itCreatePnfData() throws IOException {
922 HttpServletRequest request = mockRequest();
923 ResponseBody result=null;
924 VfcService vfcService = mock(VfcService.class);
925 when(vfcService.createPnfData(Mockito.any())).thenReturn(successfulCall(result));
926 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
928 Assert.assertSame("{\"status\":\"FAILED\"}", service.createPnfData(request));
932 public void createPnfDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
933 HttpServletRequest request = mockRequest();
934 VfcService vfcService = mock(VfcService.class);
935 when(vfcService.createPnfData(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
936 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
937 service.createPnfData(request);
941 public void createPnfDataWillThrowExceptionWhenVFCResponseError() throws IOException {
942 HttpServletRequest request = mockRequest();
943 VfcService vfcService = mock(VfcService.class);
944 when(vfcService.createPnfData(Mockito.any())).thenReturn(emptyBodyCall());
945 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
946 service.createPnfData(request);
950 public void itGetNsdInfo() throws IOException {
952 ResponseBody result=null;
953 VfcService vfcService = mock(VfcService.class);
954 when(vfcService.getNsdInfo(nsdId)).thenReturn(successfulCall(result));
955 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
957 Assert.assertSame("{\"status\":\"SUCCESS\"}", service.getNsdInfo(nsdId));
961 public void getNsdInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
963 VfcService vfcService = mock(VfcService.class);
964 when(vfcService.getNsdInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
965 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
966 service.getNsdInfo(nsdId);
970 public void getNsdInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
972 VfcService vfcService = mock(VfcService.class);
973 when(vfcService.getNsdInfo(nsdId)).thenReturn(emptyBodyCall());
974 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
975 service.getNsdInfo(nsdId);
979 public void itGetVnfInfo() throws IOException {
981 ResponseBody result=null;
982 VfcService vfcService = mock(VfcService.class);
983 when(vfcService.getVnfInfo(nsdId)).thenReturn(successfulCall(result));
984 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
986 Assert.assertSame("{\"status\":\"SUCCESS\"}", service.getVnfInfo(nsdId));
990 public void getVnfInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
992 VfcService vfcService = mock(VfcService.class);
993 when(vfcService.getVnfInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
994 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
995 service.getVnfInfo(nsdId);
999 public void getVnfInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
1001 VfcService vfcService = mock(VfcService.class);
1002 when(vfcService.getVnfInfo(nsdId)).thenReturn(emptyBodyCall());
1003 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
1004 service.getVnfInfo(nsdId);
1008 public void itGetPnfInfo() throws IOException {
1010 ResponseBody result=null;
1011 VfcService vfcService = mock(VfcService.class);
1012 when(vfcService.getPnfInfo(nsdId)).thenReturn(successfulCall(result));
1013 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
1015 Assert.assertSame("{\"status\":\"SUCCESS\"}", service.getPnfInfo(nsdId));
1019 public void getPnfInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
1021 VfcService vfcService = mock(VfcService.class);
1022 when(vfcService.getPnfInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
1023 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
1024 service.getPnfInfo(nsdId);
1028 public void getPnfInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
1030 VfcService vfcService = mock(VfcService.class);
1031 when(vfcService.getPnfInfo(nsdId)).thenReturn(emptyBodyCall());
1032 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
1033 service.getPnfInfo(nsdId);
1037 public void itCanListNsTemplates() throws IOException {
1038 VfcService vfcService = mock(VfcService.class);
1039 when(vfcService.listNsTemplates()).thenReturn(successfulCall(result));
1040 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
1042 Assert.assertNotNull( service.listNsTemplates());
1046 public void listNsTemplatesWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
1047 VfcService vfcService = mock(VfcService.class);
1048 when(vfcService.listNsTemplates()).thenReturn(failedCall("VFC is not available!"));
1049 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
1050 service.listNsTemplates();
1054 public void listNsTemplatesWillThrowExceptionWhenVFCResponseError() throws IOException {
1055 VfcService vfcService = mock(VfcService.class);
1056 when(vfcService.listNsTemplates()).thenReturn(emptyBodyCall());
1057 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
1058 service.listNsTemplates();
1062 public void itCanGetVnfInfoById() throws IOException {
1064 VfcService vfcService = mock(VfcService.class);
1065 when(vfcService.getVnfInfoById(nsdId)).thenReturn(successfulCall(result));
1066 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
1068 Assert.assertNotNull(service.getVnfInfoById(nsdId));
1072 public void getVnfInfoByIdWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
1074 VfcService vfcService = mock(VfcService.class);
1075 when(vfcService.getVnfInfoById(nsdId)).thenReturn(failedCall("VFC is not available!"));
1076 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
1077 service.getVnfInfoById(nsdId);
1081 public void getVnfInfoByIdWillThrowExceptionWhenVFCResponseError() throws IOException {
1083 VfcService vfcService = mock(VfcService.class);
1084 when(vfcService.getVnfInfoById(nsdId)).thenReturn(emptyBodyCall());
1085 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
1086 service.getVnfInfoById(nsdId);
1090 public void itCanFetchNsTemplateData() throws IOException {
1091 HttpServletRequest request = mockRequest();
1092 ResponseBody result=null;
1093 VfcService vfcService = mock(VfcService.class);
1094 when(vfcService.fetchNsTemplateData(Mockito.any())).thenReturn(successfulCall(result));
1095 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
1097 Assert.assertSame("{\"status\":\"FAILED\"}", service.fetchNsTemplateData(request));
1101 public void fetchNsTemplateDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
1102 HttpServletRequest request = mockRequest();
1103 VfcService vfcService = mock(VfcService.class);
1104 when(vfcService.fetchNsTemplateData(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
1105 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
1106 service.fetchNsTemplateData(request);
1110 public void fetchNsTemplateDataWillThrowExceptionWhenVFCResponseError() throws IOException {
1111 HttpServletRequest request = mockRequest();
1112 VfcService vfcService = mock(VfcService.class);
1113 when(vfcService.fetchNsTemplateData(Mockito.any())).thenReturn(emptyBodyCall());
1114 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
1115 service.fetchNsTemplateData(request);