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.AAIService;
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.sdc.exceptions.SDCCatalogException;
39 import org.onap.usecaseui.server.service.lcm.domain.vfc.VfcService;
40 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Csar;
41 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.DistributionResult;
42 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Job;
43 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.JobStatus;
44 import org.onap.usecaseui.server.service.lcm.domain.vfc.exceptions.VfcException;
46 import okhttp3.ResponseBody;
47 import retrofit2.Call;
49 import java.io.IOException;
50 import java.util.ArrayList;
51 import java.util.Collections;
52 import java.util.List;
54 import jakarta.servlet.ReadListener;
55 import jakarta.servlet.ServletInputStream;
56 import jakarta.servlet.http.HttpServletRequest;
58 import static org.hamcrest.CoreMatchers.equalTo;
59 import static org.junit.Assert.assertNotEquals;
60 import static org.junit.Assert.assertNotNull;
61 import static org.mockito.ArgumentMatchers.eq;
62 import static org.mockito.Mockito.mock;
63 import static org.mockito.Mockito.when;
64 import static org.onap.usecaseui.server.service.lcm.domain.sdc.consts.SDCConsts.*;
65 import static org.onap.usecaseui.server.util.CallStub.emptyBodyCall;
66 import static org.onap.usecaseui.server.util.CallStub.failedCall;
67 import static org.onap.usecaseui.server.util.CallStub.successfulCall;
69 public class DefaultPackageDistributionServiceTest {
71 private ResponseBody result;
74 private HttpServletRequest mockRequest() throws IOException {
75 HttpServletRequest request = mock(HttpServletRequest.class);
76 when(request.getContentLength()).thenReturn(0);
77 ServletInputStream inStream = new ServletInputStream() {
79 public boolean isFinished() {
84 public boolean isReady() {
89 public void setReadListener(ReadListener readListener) {
94 public int read() throws IOException {
98 when(request.getInputStream()).thenReturn(inStream);
104 public void before() throws Exception {
105 result= new ResponseBody() {
108 public MediaType contentType() {
109 return MediaType.parse("application/json; charset=utf-8");
113 public long contentLength() {
119 public BufferedSource source() {
127 public void itCanRetrievePackageFromSDCAndAAI() {
128 List<SDCServiceTemplate> serviceTemplate = Collections.singletonList(new SDCServiceTemplate("1", "1", "service", "V1","", ""));
130 o.setInvariantUUID("2");
133 List<Vnf> vnf = Collections.singletonList(o);
134 SDCCatalogService sdcService = newSDCService(serviceTemplate, vnf);
136 List<VimInfo> vim = Collections.singletonList(new VimInfo("owner", "regionId"));
137 AAIService aaiService = newAAIService(vim);
139 PackageDistributionService service = new DefaultPackageDistributionService(sdcService, null);
141 Assert.assertThat(service.retrievePackageInfo(), equalTo(new VfNsPackageInfo(serviceTemplate, vnf)));
144 private AAIService newAAIService(List<VimInfo> vim) {
145 AAIService aaiService = mock(AAIService.class);
146 VimInfoRsp rsp = new VimInfoRsp();
147 rsp.setCloudRegion(vim);
148 Call<VimInfoRsp> vimCall = successfulCall(rsp);
149 when(aaiService.listVimInfo()).thenReturn(vimCall);
153 private SDCCatalogService newSDCService(List<SDCServiceTemplate> serviceTemplate, List<Vnf> vnf) {
154 SDCCatalogService sdcService = mock(SDCCatalogService.class);
156 Call<List<SDCServiceTemplate>> serviceCall = successfulCall(serviceTemplate);
157 when(sdcService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(serviceCall);
159 Call<List<Vnf>> vnfCall = successfulCall(vnf);
160 when(sdcService.listResources(RESOURCETYPE_VF)).thenReturn(vnfCall);
165 public void retrievePackageWillThrowExceptionWhenSDCIsNotAvailable() {
166 SDCCatalogService sdcService = mock(SDCCatalogService.class);
167 Call<List<Vnf>> serviceCall = failedCall("SDC is not available!");
168 Call<List<SDCServiceTemplate>> serviceCall1 = failedCall("SDC is not available!");
169 when(sdcService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(serviceCall1);
170 when(sdcService.listResources(RESOURCETYPE_VF)).thenReturn(serviceCall);
172 List<VimInfo> vim = Collections.singletonList(new VimInfo("owner", "regionId"));
173 AAIService aaiService = newAAIService(vim);
175 PackageDistributionService service = new DefaultPackageDistributionService(sdcService, null);
176 service.retrievePackageInfo();
180 public void retrievePackageWillBeEmptyWhenNoNsServiceAndVfInSDC() {
181 SDCCatalogService sdcService = mock(SDCCatalogService.class);
182 Call<List<SDCServiceTemplate>> serviceCall = emptyBodyCall();
183 when(sdcService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(serviceCall);
185 Call<List<Vnf>> resourceCall = emptyBodyCall();
186 when(sdcService.listResources(RESOURCETYPE_VF)).thenReturn(resourceCall);
188 PackageDistributionService service = new DefaultPackageDistributionService(sdcService, null);
189 VfNsPackageInfo vfNsPackageInfo = service.retrievePackageInfo();
191 Assert.assertTrue("ns should be empty!", vfNsPackageInfo.getNsPackage().isEmpty());
192 Assert.assertTrue("vf should be empty!", vfNsPackageInfo.getVnfPackages().isEmpty());
196 public void itCanPostNsPackageToVFC() {
197 VfcService vfcService = mock(VfcService.class);
198 Csar csar = new Csar();
199 DistributionResult result = new DistributionResult();
200 result.setStatus("status");
201 result.setStatusDescription("description");
202 result.setErrorCode("errorcode");
203 when(vfcService.distributeNsPackage(csar)).thenReturn(successfulCall(result));
204 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
206 Assert.assertSame(result, service.postNsPackage(csar));
209 @Test(expected = VfcException.class)
210 public void postNsPackageWillThrowExceptionWhenVFCIsNotAvailable() {
211 VfcService vfcService = mock(VfcService.class);
212 Csar csar = new Csar();
213 when(vfcService.distributeNsPackage(csar)).thenReturn(failedCall("VFC is not available!"));
214 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
215 service.postNsPackage(csar);
218 @Test(expected = VfcException.class)
219 public void postNsPackageWillThrowExceptionWhenVFCResponseError() {
220 VfcService vfcService = mock(VfcService.class);
221 Csar csar = new Csar();
222 when(vfcService.distributeNsPackage(csar)).thenReturn(emptyBodyCall());
223 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
224 service.postNsPackage(csar);
228 public void itCanPostVnfPackageToVFC() {
229 VfcService vfcService = mock(VfcService.class);
230 Csar csar = new Csar();
232 when(vfcService.distributeVnfPackage(csar)).thenReturn(successfulCall(job));
233 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
235 Assert.assertSame(job, service.postVfPackage(csar));
238 @Test(expected = VfcException.class)
239 public void postVnfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
240 VfcService vfcService = mock(VfcService.class);
241 Csar csar = new Csar();
242 when(vfcService.distributeVnfPackage(csar)).thenReturn(failedCall("VFC is not available!"));
243 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
244 service.postVfPackage(csar);
247 @Test(expected = VfcException.class)
248 public void postVnfPackageWillThrowExceptionWhenVFCResponseError() {
249 VfcService vfcService = mock(VfcService.class);
250 Csar csar = new Csar();
251 when(vfcService.distributeVnfPackage(csar)).thenReturn(emptyBodyCall());
252 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
253 service.postVfPackage(csar);
257 public void itCanGetJobStatusFromVFC() {
258 VfcService vfcService = mock(VfcService.class);
260 String responseId = "1";
261 JobStatus jobStatus = new JobStatus();
262 when(vfcService.getJobStatus(jobId, responseId)).thenReturn(successfulCall(jobStatus));
263 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
265 Assert.assertSame(jobStatus, service.getJobStatus(jobId, responseId));
268 @Test(expected = VfcException.class)
269 public void getJobStatusWillThrowExceptionWhenVFCIsNotAvailable() {
270 VfcService vfcService = mock(VfcService.class);
272 String responseId = "1";
273 when(vfcService.getJobStatus(jobId, responseId)).thenReturn(failedCall("VFC is not available!"));
274 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
275 service.getJobStatus(jobId, responseId);
278 @Test(expected = VfcException.class)
279 public void getJobStatusWillThrowExceptionWhenVFCResponseError() {
280 VfcService vfcService = mock(VfcService.class);
282 String responseId = "1";
283 when(vfcService.getJobStatus(jobId, responseId)).thenReturn(emptyBodyCall());
284 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
285 service.getJobStatus(jobId, responseId);
289 public void itCanGetNsLcmJobStatusFromVFC() {
290 VfcService vfcService = mock(VfcService.class);
292 String responseId = "1";
293 String serviceId= "1";
294 String operationType= "1";
295 JobStatus jobStatus = new JobStatus();
296 when(vfcService.getNsLcmJobStatus(jobId, responseId)).thenReturn(successfulCall(jobStatus));
297 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
299 Assert.assertSame(jobStatus, service.getNsLcmJobStatus(serviceId,jobId, responseId,operationType));
302 @Test(expected = VfcException.class)
303 public void getNsLcmJobStatusWillThrowExceptionWhenVFCIsNotAvailable() {
304 VfcService vfcService = mock(VfcService.class);
306 String responseId = "1";
307 String serviceId= "1";
308 String operationType= "1";
309 when(vfcService.getNsLcmJobStatus(jobId, responseId)).thenReturn(failedCall("VFC is not available!"));
310 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
311 service.getNsLcmJobStatus(serviceId,jobId, responseId,operationType);
314 @Test(expected = VfcException.class)
315 public void getNsLcmJobStatusWillThrowExceptionWhenVFCResponseError() {
316 VfcService vfcService = mock(VfcService.class);
318 String responseId = "1";
319 String serviceId= "1";
320 String operationType= "1";
321 when(vfcService.getNsLcmJobStatus(jobId, responseId)).thenReturn(emptyBodyCall());
322 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
323 service.getNsLcmJobStatus(serviceId,jobId, responseId,operationType);
327 public void itCanDeleteNsPackage() {
329 DistributionResult result = new DistributionResult();
330 VfcService vfcService = mock(VfcService.class);
331 when(vfcService.deleteNsPackage(csarId)).thenReturn(successfulCall(result));
332 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
334 Assert.assertSame(result, service.deleteNsPackage(csarId));
337 @Test(expected = VfcException.class)
338 public void deleteNsPackageWillThrowExceptionWhenVFCIsNotAvailable() {
340 VfcService vfcService = mock(VfcService.class);
341 when(vfcService.deleteNsPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
342 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
343 service.deleteNsPackage(csarId);
346 @Test(expected = VfcException.class)
347 public void deleteNsPackageWillThrowExceptionWhenVFCResponseError() {
349 VfcService vfcService = mock(VfcService.class);
350 when(vfcService.deleteNsPackage(csarId)).thenReturn(emptyBodyCall());
351 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
352 service.deleteNsPackage(csarId);
356 public void itCanGetVnfPackages(){
357 //ResponseBody result=null;
358 VfcService vfcService = mock(VfcService.class);
359 when(vfcService.getVnfPackages()).thenReturn(successfulCall(result));
360 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
362 // Assert.assertSame(result, service.getVnfPackages());
363 Assert.assertNotNull(service.getVnfPackages());
367 public void getVnfPackagesThrowExceptionWhenVFCResponseError(){
369 VfcService vfcService = mock(VfcService.class);
370 when(vfcService.getVnfPackages ()).thenReturn(emptyBodyCall());
371 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
372 service.getVnfPackages();
376 public void getVnfPackagesThrowException(){
377 VfcService vfcService = mock(VfcService.class);
378 when(vfcService.getVnfPackages ()).thenReturn(failedCall("VFC is not available!"));
379 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
380 service.getVnfPackages();
384 public void itCanDeleteVFPackage() {
387 VfcService vfcService = mock(VfcService.class);
388 when(vfcService.deleteVnfPackage(csarId)).thenReturn(successfulCall(job));
389 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
391 Assert.assertSame(job, service.deleteVfPackage(csarId));
395 public void deleteVfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
397 VfcService vfcService = mock(VfcService.class);
398 when(vfcService.deleteVnfdPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
399 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
400 Assert.assertSame("{\"status\":\"FAILED\"}",service.deleteVnfPackage(csarId));
404 public void deleteVnfPackageWillThrowExceptionWhenVFCResponseError() {
406 VfcService vfcService = mock(VfcService.class);
407 when(vfcService.deleteVnfdPackage(csarId)).thenReturn(emptyBodyCall());
408 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
409 service.deleteVnfPackage(csarId);
413 public void itCanGetNetworkServicePackages() {
414 VfcService vfcService = mock(VfcService.class);
415 when(vfcService.getNetworkServicePackages()).thenReturn(successfulCall(result));
416 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
417 Assert.assertNotNull(service.getNetworkServicePackages());
421 public void getNetworkServicePackagesWillThrowExceptionWhenVFCIsNotAvailable() {
422 VfcService vfcService = mock(VfcService.class);
423 when(vfcService.getNetworkServicePackages()).thenReturn(failedCall("VFC is not available!"));
424 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
425 service.getNetworkServicePackages();
429 public void getNetworkServicePackagesWillThrowExceptionWhenVFCResponseError() {
430 VfcService vfcService = mock(VfcService.class);
431 when(vfcService.getNetworkServicePackages()).thenReturn(emptyBodyCall());
432 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
433 service.getNetworkServicePackages();
437 public void itCanGetPnfPackages(){
438 VfcService vfcService = mock(VfcService.class);
439 when(vfcService.getPnfPackages()).thenReturn(successfulCall(result));
440 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
442 Assert.assertNotNull(service.getPnfPackages());
446 public void getPnfPackagesThrowExceptionWhenVFCResponseError(){
448 VfcService vfcService = mock(VfcService.class);
449 when(vfcService.getPnfPackages ()).thenReturn(emptyBodyCall());
450 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
451 service.getPnfPackages();
455 public void getPnfPackagesThrowException(){
456 VfcService vfcService = mock(VfcService.class);
457 when(vfcService.getPnfPackages ()).thenReturn(failedCall("VFC is not available!"));
458 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
459 service.getPnfPackages();
463 public void itDownLoadNsPackage(){
464 String nsdInfoId="1";
465 ResponseBody successResponse=null;
466 VfcService vfcService = mock(VfcService.class);
467 when(vfcService.downLoadNsPackage(nsdInfoId)).thenReturn(successfulCall(successResponse));
468 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
470 String result = service.downLoadNsPackage(nsdInfoId);
471 assertNotNull(result);
472 assertNotEquals("", result);
476 public void downLoadNsPackagehrowExceptionWhenVFCResponseError(){
477 String nsdInfoId="1";
478 VfcService vfcService = mock(VfcService.class);
479 when(vfcService.downLoadNsPackage (nsdInfoId)).thenReturn(emptyBodyCall());
480 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
481 service.downLoadNsPackage(nsdInfoId);
485 public void downLoadNsPackageThrowException(){
486 String nsdInfoId="1";
487 VfcService vfcService = mock(VfcService.class);
488 when(vfcService.downLoadNsPackage (nsdInfoId)).thenReturn(failedCall("VFC is not available!"));
489 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
490 service.downLoadNsPackage(nsdInfoId);
494 public void itDownLoadPnfPackage(){
495 String pnfInfoId="1";
496 VfcService vfcService = mock(VfcService.class);
497 when(vfcService.downLoadNsPackage(pnfInfoId)).thenReturn(successfulCall(result));
498 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
500 Assert.assertSame("{\"status\":\"SUCCESS\"}", service.downLoadPnfPackage(pnfInfoId));
504 public void downLoadPnfPackagehrowExceptionWhenVFCResponseError(){
505 String pnfInfoId="1";
506 VfcService vfcService = mock(VfcService.class);
507 when(vfcService.downLoadNsPackage (pnfInfoId)).thenReturn(emptyBodyCall());
508 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
509 service.downLoadPnfPackage(pnfInfoId);
513 public void downLoadPnfPackageThrowException(){
514 String pnfInfoId="1";
515 VfcService vfcService = mock(VfcService.class);
516 when(vfcService.downLoadNsPackage (pnfInfoId)).thenReturn(failedCall("VFC is not available!"));
517 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
518 service.downLoadPnfPackage(pnfInfoId);
522 public void itDownLoadVnfPackage(){
523 String vnfInfoId="1";
524 VfcService vfcService = mock(VfcService.class);
525 when(vfcService.downLoadNsPackage(vnfInfoId)).thenReturn(successfulCall(result));
526 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
528 Assert.assertSame("{\"status\":\"SUCCESS\"}", service.downLoadVnfPackage(vnfInfoId));
532 public void downLoadVnfPackagehrowExceptionWhenVFCResponseError(){
533 String vnfInfoId="1";
534 VfcService vfcService = mock(VfcService.class);
535 when(vfcService.downLoadNsPackage (vnfInfoId)).thenReturn(failedCall("VFC is not available!"));
536 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
537 service.downLoadVnfPackage(vnfInfoId);
541 public void downLoadVnfPackageThrowException(){
542 String vnfInfoId="1";
543 VfcService vfcService = mock(VfcService.class);
544 when(vfcService.downLoadNsPackage (vnfInfoId)).thenReturn(failedCall("VFC is not available!"));
545 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
546 service.downLoadVnfPackage(vnfInfoId);
550 public void itCanDeleteNsdPackage() {
552 ResponseBody result=null;
553 VfcService vfcService = mock(VfcService.class);
554 when(vfcService.deleteNsdPackage(csarId)).thenReturn(successfulCall(result));
555 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
557 Assert.assertSame("{\"status\":\"SUCCESS\"}", service.deleteNsdPackage(csarId));
561 public void deleteNsdPackageWillThrowExceptionWhenVFCIsNotAvailable() {
563 VfcService vfcService = mock(VfcService.class);
564 when(vfcService.deleteNsdPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
565 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
566 service.deleteNsdPackage(csarId);
570 public void deleteNsdPackageWillThrowExceptionWhenVFCResponseError() {
572 VfcService vfcService = mock(VfcService.class);
573 when(vfcService.deleteNsdPackage(csarId)).thenReturn(emptyBodyCall());
574 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
575 service.deleteNsdPackage(csarId);
579 public void itCanDeleteVnfPackage() {
581 VfcService vfcService = mock(VfcService.class);
582 when(vfcService.deleteVnfdPackage(csarId)).thenReturn(successfulCall(result));
583 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
585 Assert.assertNotNull(service.deleteVnfPackage(csarId));
589 public void deleteVnfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
591 VfcService vfcService = mock(VfcService.class);
592 when(vfcService.deleteVnfdPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
593 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
594 service.deleteVnfPackage(csarId);
598 public void deleteVnfNsdPackageWillThrowExceptionWhenVFCResponseError() {
600 VfcService vfcService = mock(VfcService.class);
601 when(vfcService.deleteVnfdPackage(csarId)).thenReturn(emptyBodyCall());
602 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
603 service.deleteVnfPackage(csarId);
604 Assert.assertSame("{\"status\":\"FAILED\"}", service.deleteVnfPackage(csarId));
608 public void itCanDeletePnfdPackage() {
610 ResponseBody result=null;
612 VfcService vfcService = mock(VfcService.class);
613 when(vfcService.deletePnfdPackage(csarId)).thenReturn(successfulCall(result));
614 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
616 Assert.assertSame("{\"status\":\"SUCCESS\"}", service.deletePnfPackage(csarId));
620 public void deletePnfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
622 VfcService vfcService = mock(VfcService.class);
623 when(vfcService.deletePnfdPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
624 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
625 service.deletePnfPackage(csarId);
629 public void deletePnfPackageWillThrowExceptionWhenVFCResponseError() {
631 VfcService vfcService = mock(VfcService.class);
632 when(vfcService.deletePnfdPackage(csarId)).thenReturn(emptyBodyCall());
633 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
634 service.deletePnfPackage(csarId);
638 public void itCanDeleteNetworkServiceInstance() {
640 ResponseBody result=null;
642 VfcService vfcService = mock(VfcService.class);
643 when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(successfulCall(result));
644 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
646 Assert.assertSame("{\"status\":\"SUCCESS\"}", service.deleteNetworkServiceInstance(csarId));
650 public void deleteNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() {
652 VfcService vfcService = mock(VfcService.class);
653 when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(failedCall("VFC is not available!"));
654 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
655 service.deleteNetworkServiceInstance(csarId);
659 public void deleteNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() {
661 VfcService vfcService = mock(VfcService.class);
662 when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(emptyBodyCall());
663 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
664 service.deleteNetworkServiceInstance(csarId);
668 public void itCanCreateNetworkServiceInstance() throws IOException {
669 HttpServletRequest request = mockRequest();
670 ResponseBody result=null;
671 VfcService vfcService = mock(VfcService.class);
672 when(vfcService.createNetworkServiceInstance(Mockito.any())).thenReturn(successfulCall(result));
673 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
675 Assert.assertSame("{\"status\":\"FAILED\"}", service.createNetworkServiceInstance(request));
679 public void createNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
680 HttpServletRequest request = mockRequest();
681 VfcService vfcService = mock(VfcService.class);
682 when(vfcService.createNetworkServiceInstance(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
683 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
684 service.createNetworkServiceInstance(request);
688 public void createNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
689 HttpServletRequest request = mockRequest();
690 VfcService vfcService = mock(VfcService.class);
691 when(vfcService.createNetworkServiceInstance(Mockito.any())).thenReturn(emptyBodyCall());
692 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
693 service.createNetworkServiceInstance(request);
697 public void itCanGetNetworkServiceInfo() throws IOException {
698 nsServiceRsp ns = new nsServiceRsp();
699 List<String> list = new ArrayList<>();
700 String s = "{\"nsInstanceId\":\"nsInstanceId\"}";
702 ns.setNsServices(list);
703 VfcService vfcService = mock(VfcService.class);
704 when(vfcService.getNetworkServiceInfo()).thenReturn(successfulCall(ns));
705 ServiceLcmService serviceLcmService = mock(ServiceLcmService.class);
706 DefaultPackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
707 service.setServiceLcmService(serviceLcmService);
708 when(serviceLcmService.getServiceBeanByServiceInStanceId("nsInstanceId")).thenReturn(new ServiceBean());
709 Assert.assertNotNull( service.getNetworkServiceInfo());
713 public void getNetworkServiceInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
714 VfcService vfcService = mock(VfcService.class);
715 when(vfcService.getNetworkServiceInfo()).thenReturn(failedCall("VFC is not available!"));
716 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
717 service.getNetworkServiceInfo();
721 public void getNetworkServiceInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
722 VfcService vfcService = mock(VfcService.class);
723 when(vfcService.getNetworkServiceInfo()).thenReturn(emptyBodyCall());
724 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
725 service.getNetworkServiceInfo();
731 public void itCanHealNetworkServiceInstance() throws IOException {
732 HttpServletRequest request = mockRequest();
734 ResponseBody result=null;
735 VfcService vfcService = mock(VfcService.class);
736 //when(vfcService.healNetworkServiceInstance(csarId,anyObject())).thenReturn(successfulCall(result));
737 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
739 //Assert.assertSame(result, service.healNetworkServiceInstance(request,csarId));
740 service.healNetworkServiceInstance(request,csarId);
744 public void healNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
745 HttpServletRequest request = mockRequest();
747 VfcService vfcService = mock(VfcService.class);
748 when(vfcService.healNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(failedCall("VFC is not available!"));
749 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
750 service.healNetworkServiceInstance(request,csarId);
754 public void healNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
755 HttpServletRequest request = mockRequest();
757 VfcService vfcService = mock(VfcService.class);
758 when(vfcService.healNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(emptyBodyCall());
759 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
760 service.healNetworkServiceInstance(request,csarId);
764 public void itCanScaleNetworkServiceInstance() throws IOException {
765 HttpServletRequest request = mockRequest();
767 VfcService vfcService = mock(VfcService.class);
768 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
770 String result = service.scaleNetworkServiceInstance(request,csarId);
771 assertNotNull(result);
772 assertNotEquals("", result);
776 public void scaleNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
777 HttpServletRequest request = mockRequest();
779 VfcService vfcService = mock(VfcService.class);
780 when(vfcService.scaleNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(failedCall("VFC is not available!"));
781 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
782 service.scaleNetworkServiceInstance(request,csarId);
786 public void scaleNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
787 HttpServletRequest request = mockRequest();
789 VfcService vfcService = mock(VfcService.class);
790 when(vfcService.scaleNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(emptyBodyCall());
791 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
792 service.scaleNetworkServiceInstance(request,csarId);
797 public void itCaninstantiateNetworkServiceInstance() throws IOException {
798 HttpServletRequest request = mockRequest();
799 String serviceInstanceId="1";
800 ResponseBody result=null;
801 VfcService vfcService = mock(VfcService.class);
802 //when(vfcService.instantiateNetworkServiceInstance(anyObject(),serviceInstanceId)).thenReturn(successfulCall(result));
803 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
805 service.instantiateNetworkServiceInstance(request,serviceInstanceId);
809 public void instantiateNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
810 HttpServletRequest request = mockRequest();
811 String serviceInstanceId="1";
812 VfcService vfcService = mock(VfcService.class);
813 when(vfcService.instantiateNetworkServiceInstance(Mockito.any(),eq(serviceInstanceId))).thenReturn(failedCall("VFC is not available!"));
814 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
815 service.instantiateNetworkServiceInstance(request,serviceInstanceId);
819 public void instantiateNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
820 HttpServletRequest request = mockRequest();
821 String serviceInstanceId="1";
822 VfcService vfcService = mock(VfcService.class);
823 when(vfcService.instantiateNetworkServiceInstance(Mockito.any(),eq(serviceInstanceId))).thenReturn(emptyBodyCall());
824 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
825 service.instantiateNetworkServiceInstance(request,serviceInstanceId);
830 public void itCanTerminateNetworkServiceInstance() throws IOException {
831 HttpServletRequest request = mockRequest();
833 ResponseBody result=null;
835 VfcService vfcService = mock(VfcService.class);
836 when(vfcService.terminateNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(successfulCall(result));
837 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
839 service.terminateNetworkServiceInstance(request,csarId);
843 public void terminateNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
844 HttpServletRequest request = mockRequest();
846 VfcService vfcService = mock(VfcService.class);
847 //when(vfcService.terminateNetworkServiceInstance(csarId,anyObject())).thenReturn(failedCall("VFC is not available!"));
848 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
849 service.terminateNetworkServiceInstance(request,csarId);
853 public void terminateNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
854 HttpServletRequest request = mockRequest();
856 VfcService vfcService = mock(VfcService.class);
857 when(vfcService.terminateNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(emptyBodyCall());
858 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
859 service.terminateNetworkServiceInstance(request,csarId);
863 public void itCreateNetworkServiceData() throws IOException {
864 HttpServletRequest request = mockRequest();
865 ResponseBody responseBody = null;
866 VfcService vfcService = mock(VfcService.class);
867 when(vfcService.createNetworkServiceData(Mockito.any())).thenReturn(successfulCall(responseBody));
868 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
870 String result = service.createNetworkServiceData(request);
871 assertNotNull(result);
872 assertNotEquals("", result);
876 public void createNetworkServiceDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
877 HttpServletRequest request = mockRequest();
878 VfcService vfcService = mock(VfcService.class);
879 when(vfcService.createNetworkServiceData(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
880 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
881 service.createNetworkServiceData(request);
885 public void createNetworkServiceDataWillThrowExceptionWhenVFCResponseError() throws IOException {
886 HttpServletRequest request = mockRequest();
887 VfcService vfcService = mock(VfcService.class);
888 when(vfcService.createNetworkServiceData(Mockito.any())).thenReturn(emptyBodyCall());
889 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
890 service.createNetworkServiceData(request);
894 public void itCreateVnfData() throws IOException {
895 HttpServletRequest request = mockRequest();
896 ResponseBody result=null;
897 VfcService vfcService = mock(VfcService.class);
898 when(vfcService.createVnfData(Mockito.any())).thenReturn(successfulCall(result));
899 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
901 Assert.assertSame("{\"status\":\"FAILED\"}", service.createVnfData(request));
905 public void createVnfDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
906 HttpServletRequest request = mockRequest();
907 VfcService vfcService = mock(VfcService.class);
908 when(vfcService.createVnfData(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
909 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
910 service.createVnfData(request);
914 public void createVnfDataWillThrowExceptionWhenVFCResponseError() throws IOException {
915 HttpServletRequest request = mockRequest();
916 VfcService vfcService = mock(VfcService.class);
917 when(vfcService.createVnfData(Mockito.any())).thenReturn(emptyBodyCall());
918 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
919 service.createVnfData(request);
923 public void itCreatePnfData() throws IOException {
924 HttpServletRequest request = mockRequest();
925 ResponseBody result=null;
926 VfcService vfcService = mock(VfcService.class);
927 when(vfcService.createPnfData(Mockito.any())).thenReturn(successfulCall(result));
928 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
930 Assert.assertSame("{\"status\":\"FAILED\"}", service.createPnfData(request));
934 public void createPnfDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
935 HttpServletRequest request = mockRequest();
936 VfcService vfcService = mock(VfcService.class);
937 when(vfcService.createPnfData(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
938 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
939 service.createPnfData(request);
943 public void createPnfDataWillThrowExceptionWhenVFCResponseError() throws IOException {
944 HttpServletRequest request = mockRequest();
945 VfcService vfcService = mock(VfcService.class);
946 when(vfcService.createPnfData(Mockito.any())).thenReturn(emptyBodyCall());
947 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
948 service.createPnfData(request);
952 public void itGetNsdInfo() throws IOException {
954 ResponseBody result=null;
955 VfcService vfcService = mock(VfcService.class);
956 when(vfcService.getNsdInfo(nsdId)).thenReturn(successfulCall(result));
957 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
959 Assert.assertSame("{\"status\":\"SUCCESS\"}", service.getNsdInfo(nsdId));
963 public void getNsdInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
965 VfcService vfcService = mock(VfcService.class);
966 when(vfcService.getNsdInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
967 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
968 service.getNsdInfo(nsdId);
972 public void getNsdInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
974 VfcService vfcService = mock(VfcService.class);
975 when(vfcService.getNsdInfo(nsdId)).thenReturn(emptyBodyCall());
976 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
977 service.getNsdInfo(nsdId);
981 public void itGetVnfInfo() throws IOException {
983 ResponseBody result=null;
984 VfcService vfcService = mock(VfcService.class);
985 when(vfcService.getVnfInfo(nsdId)).thenReturn(successfulCall(result));
986 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
988 Assert.assertSame("{\"status\":\"SUCCESS\"}", service.getVnfInfo(nsdId));
992 public void getVnfInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
994 VfcService vfcService = mock(VfcService.class);
995 when(vfcService.getVnfInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
996 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
997 service.getVnfInfo(nsdId);
1001 public void getVnfInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
1003 VfcService vfcService = mock(VfcService.class);
1004 when(vfcService.getVnfInfo(nsdId)).thenReturn(emptyBodyCall());
1005 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1006 service.getVnfInfo(nsdId);
1010 public void itGetPnfInfo() throws IOException {
1012 ResponseBody result=null;
1013 VfcService vfcService = mock(VfcService.class);
1014 when(vfcService.getPnfInfo(nsdId)).thenReturn(successfulCall(result));
1015 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1017 Assert.assertSame("{\"status\":\"SUCCESS\"}", service.getPnfInfo(nsdId));
1021 public void getPnfInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
1023 VfcService vfcService = mock(VfcService.class);
1024 when(vfcService.getPnfInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
1025 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1026 service.getPnfInfo(nsdId);
1030 public void getPnfInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
1032 VfcService vfcService = mock(VfcService.class);
1033 when(vfcService.getPnfInfo(nsdId)).thenReturn(emptyBodyCall());
1034 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1035 service.getPnfInfo(nsdId);
1039 public void itCanListNsTemplates() throws IOException {
1040 VfcService vfcService = mock(VfcService.class);
1041 when(vfcService.listNsTemplates()).thenReturn(successfulCall(result));
1042 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1044 Assert.assertNotNull( service.listNsTemplates());
1048 public void listNsTemplatesWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
1049 VfcService vfcService = mock(VfcService.class);
1050 when(vfcService.listNsTemplates()).thenReturn(failedCall("VFC is not available!"));
1051 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1052 service.listNsTemplates();
1056 public void listNsTemplatesWillThrowExceptionWhenVFCResponseError() throws IOException {
1057 VfcService vfcService = mock(VfcService.class);
1058 when(vfcService.listNsTemplates()).thenReturn(emptyBodyCall());
1059 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1060 service.listNsTemplates();
1064 public void itCanGetVnfInfoById() throws IOException {
1066 VfcService vfcService = mock(VfcService.class);
1067 when(vfcService.getVnfInfoById(nsdId)).thenReturn(successfulCall(result));
1068 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1070 Assert.assertNotNull(service.getVnfInfoById(nsdId));
1074 public void getVnfInfoByIdWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
1076 VfcService vfcService = mock(VfcService.class);
1077 when(vfcService.getVnfInfoById(nsdId)).thenReturn(failedCall("VFC is not available!"));
1078 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1079 service.getVnfInfoById(nsdId);
1083 public void getVnfInfoByIdWillThrowExceptionWhenVFCResponseError() throws IOException {
1085 VfcService vfcService = mock(VfcService.class);
1086 when(vfcService.getVnfInfoById(nsdId)).thenReturn(emptyBodyCall());
1087 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1088 service.getVnfInfoById(nsdId);
1092 public void itCanFetchNsTemplateData() throws IOException {
1093 HttpServletRequest request = mockRequest();
1094 ResponseBody result=null;
1095 VfcService vfcService = mock(VfcService.class);
1096 when(vfcService.fetchNsTemplateData(Mockito.any())).thenReturn(successfulCall(result));
1097 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1099 Assert.assertSame("{\"status\":\"FAILED\"}", service.fetchNsTemplateData(request));
1103 public void fetchNsTemplateDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
1104 HttpServletRequest request = mockRequest();
1105 VfcService vfcService = mock(VfcService.class);
1106 when(vfcService.fetchNsTemplateData(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
1107 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1108 service.fetchNsTemplateData(request);
1112 public void fetchNsTemplateDataWillThrowExceptionWhenVFCResponseError() throws IOException {
1113 HttpServletRequest request = mockRequest();
1114 VfcService vfcService = mock(VfcService.class);
1115 when(vfcService.fetchNsTemplateData(Mockito.any())).thenReturn(emptyBodyCall());
1116 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1117 service.fetchNsTemplateData(request);