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.apache.commons.lang3.StringUtils;
22 import org.jetbrains.annotations.NotNull;
23 import org.jetbrains.annotations.Nullable;
24 import org.junit.Assert;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.mockito.Mockito;
28 import org.onap.usecaseui.server.bean.ServiceBean;
29 import org.onap.usecaseui.server.bean.lcm.VfNsPackageInfo;
30 import org.onap.usecaseui.server.service.lcm.PackageDistributionService;
31 import org.onap.usecaseui.server.service.lcm.ServiceLcmService;
32 import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService;
33 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.VimInfo;
34 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.VimInfoRsp;
35 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.nsServiceRsp;
36 import org.onap.usecaseui.server.service.lcm.domain.sdc.SDCCatalogService;
37 import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.SDCServiceTemplate;
38 import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.Vnf;
39 import org.onap.usecaseui.server.service.lcm.domain.sdc.exceptions.SDCCatalogException;
40 import org.onap.usecaseui.server.service.lcm.domain.vfc.VfcService;
41 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Csar;
42 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.DistributionResult;
43 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Job;
44 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.JobStatus;
45 import org.onap.usecaseui.server.service.lcm.domain.vfc.exceptions.VfcException;
47 import okhttp3.ResponseBody;
48 import retrofit2.Call;
50 import java.io.IOException;
51 import java.util.ArrayList;
52 import java.util.Collections;
53 import java.util.List;
55 import jakarta.servlet.ReadListener;
56 import jakarta.servlet.ServletInputStream;
57 import jakarta.servlet.http.HttpServletRequest;
59 import static org.hamcrest.CoreMatchers.equalTo;
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 AAIService aaiService = newAAIService(vim);
138 PackageDistributionService service = new DefaultPackageDistributionService(sdcService, null);
140 Assert.assertThat(service.retrievePackageInfo(), equalTo(new VfNsPackageInfo(serviceTemplate, vnf)));
143 private AAIService newAAIService(List<VimInfo> vim) {
144 AAIService aaiService = mock(AAIService.class);
145 VimInfoRsp rsp = new VimInfoRsp();
146 rsp.setCloudRegion(vim);
147 Call<VimInfoRsp> vimCall = successfulCall(rsp);
148 when(aaiService.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 AAIService aaiService = newAAIService(vim);
174 PackageDistributionService service = new DefaultPackageDistributionService(sdcService, 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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
458 service.getPnfPackages();
462 public void itDownLoadNsPackage(){
463 String nsdInfoId="1";
464 ResponseBody result=null;
465 VfcService vfcService = mock(VfcService.class);
466 when(vfcService.downLoadNsPackage(nsdInfoId)).thenReturn(successfulCall(result));
467 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
469 Assert.assertTrue(StringUtils.isNotEmpty(service.downLoadNsPackage(nsdInfoId)));
473 public void downLoadNsPackagehrowExceptionWhenVFCResponseError(){
474 String nsdInfoId="1";
475 VfcService vfcService = mock(VfcService.class);
476 when(vfcService.downLoadNsPackage (nsdInfoId)).thenReturn(emptyBodyCall());
477 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
478 service.downLoadNsPackage(nsdInfoId);
482 public void downLoadNsPackageThrowException(){
483 String nsdInfoId="1";
484 VfcService vfcService = mock(VfcService.class);
485 when(vfcService.downLoadNsPackage (nsdInfoId)).thenReturn(failedCall("VFC is not available!"));
486 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
487 service.downLoadNsPackage(nsdInfoId);
491 public void itDownLoadPnfPackage(){
492 String pnfInfoId="1";
493 VfcService vfcService = mock(VfcService.class);
494 when(vfcService.downLoadNsPackage(pnfInfoId)).thenReturn(successfulCall(result));
495 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
497 Assert.assertSame("{\"status\":\"SUCCESS\"}", service.downLoadPnfPackage(pnfInfoId));
501 public void downLoadPnfPackagehrowExceptionWhenVFCResponseError(){
502 String pnfInfoId="1";
503 VfcService vfcService = mock(VfcService.class);
504 when(vfcService.downLoadNsPackage (pnfInfoId)).thenReturn(emptyBodyCall());
505 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
506 service.downLoadPnfPackage(pnfInfoId);
510 public void downLoadPnfPackageThrowException(){
511 String pnfInfoId="1";
512 VfcService vfcService = mock(VfcService.class);
513 when(vfcService.downLoadNsPackage (pnfInfoId)).thenReturn(failedCall("VFC is not available!"));
514 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
515 service.downLoadPnfPackage(pnfInfoId);
519 public void itDownLoadVnfPackage(){
520 String vnfInfoId="1";
521 VfcService vfcService = mock(VfcService.class);
522 when(vfcService.downLoadNsPackage(vnfInfoId)).thenReturn(successfulCall(result));
523 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
525 Assert.assertSame("{\"status\":\"SUCCESS\"}", service.downLoadVnfPackage(vnfInfoId));
529 public void downLoadVnfPackagehrowExceptionWhenVFCResponseError(){
530 String vnfInfoId="1";
531 VfcService vfcService = mock(VfcService.class);
532 when(vfcService.downLoadNsPackage (vnfInfoId)).thenReturn(failedCall("VFC is not available!"));
533 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
534 service.downLoadVnfPackage(vnfInfoId);
538 public void downLoadVnfPackageThrowException(){
539 String vnfInfoId="1";
540 VfcService vfcService = mock(VfcService.class);
541 when(vfcService.downLoadNsPackage (vnfInfoId)).thenReturn(failedCall("VFC is not available!"));
542 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
543 service.downLoadVnfPackage(vnfInfoId);
547 public void itCanDeleteNsdPackage() {
549 ResponseBody result=null;
550 VfcService vfcService = mock(VfcService.class);
551 when(vfcService.deleteNsdPackage(csarId)).thenReturn(successfulCall(result));
552 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
554 Assert.assertSame("{\"status\":\"SUCCESS\"}", service.deleteNsdPackage(csarId));
558 public void deleteNsdPackageWillThrowExceptionWhenVFCIsNotAvailable() {
560 VfcService vfcService = mock(VfcService.class);
561 when(vfcService.deleteNsdPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
562 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
563 service.deleteNsdPackage(csarId);
567 public void deleteNsdPackageWillThrowExceptionWhenVFCResponseError() {
569 VfcService vfcService = mock(VfcService.class);
570 when(vfcService.deleteNsdPackage(csarId)).thenReturn(emptyBodyCall());
571 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
572 service.deleteNsdPackage(csarId);
576 public void itCanDeleteVnfPackage() {
578 VfcService vfcService = mock(VfcService.class);
579 when(vfcService.deleteVnfdPackage(csarId)).thenReturn(successfulCall(result));
580 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
582 Assert.assertNotNull(service.deleteVnfPackage(csarId));
586 public void deleteVnfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
588 VfcService vfcService = mock(VfcService.class);
589 when(vfcService.deleteVnfdPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
590 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
591 service.deleteVnfPackage(csarId);
595 public void deleteVnfNsdPackageWillThrowExceptionWhenVFCResponseError() {
597 VfcService vfcService = mock(VfcService.class);
598 when(vfcService.deleteVnfdPackage(csarId)).thenReturn(emptyBodyCall());
599 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
600 service.deleteVnfPackage(csarId);
601 Assert.assertSame("{\"status\":\"FAILED\"}", service.deleteVnfPackage(csarId));
605 public void itCanDeletePnfdPackage() {
607 ResponseBody result=null;
609 VfcService vfcService = mock(VfcService.class);
610 when(vfcService.deletePnfdPackage(csarId)).thenReturn(successfulCall(result));
611 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
613 Assert.assertSame("{\"status\":\"SUCCESS\"}", service.deletePnfPackage(csarId));
617 public void deletePnfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
619 VfcService vfcService = mock(VfcService.class);
620 when(vfcService.deletePnfdPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
621 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
622 service.deletePnfPackage(csarId);
626 public void deletePnfPackageWillThrowExceptionWhenVFCResponseError() {
628 VfcService vfcService = mock(VfcService.class);
629 when(vfcService.deletePnfdPackage(csarId)).thenReturn(emptyBodyCall());
630 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
631 service.deletePnfPackage(csarId);
635 public void itCanDeleteNetworkServiceInstance() {
637 ResponseBody result=null;
639 VfcService vfcService = mock(VfcService.class);
640 when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(successfulCall(result));
641 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
643 Assert.assertSame("{\"status\":\"SUCCESS\"}", service.deleteNetworkServiceInstance(csarId));
647 public void deleteNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() {
649 VfcService vfcService = mock(VfcService.class);
650 when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(failedCall("VFC is not available!"));
651 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
652 service.deleteNetworkServiceInstance(csarId);
656 public void deleteNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() {
658 VfcService vfcService = mock(VfcService.class);
659 when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(emptyBodyCall());
660 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
661 service.deleteNetworkServiceInstance(csarId);
665 public void itCanCreateNetworkServiceInstance() throws IOException {
666 HttpServletRequest request = mockRequest();
667 ResponseBody result=null;
668 VfcService vfcService = mock(VfcService.class);
669 when(vfcService.createNetworkServiceInstance(Mockito.any())).thenReturn(successfulCall(result));
670 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
672 Assert.assertSame("{\"status\":\"FAILED\"}", service.createNetworkServiceInstance(request));
676 public void createNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
677 HttpServletRequest request = mockRequest();
678 VfcService vfcService = mock(VfcService.class);
679 when(vfcService.createNetworkServiceInstance(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
680 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
681 service.createNetworkServiceInstance(request);
685 public void createNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
686 HttpServletRequest request = mockRequest();
687 VfcService vfcService = mock(VfcService.class);
688 when(vfcService.createNetworkServiceInstance(Mockito.any())).thenReturn(emptyBodyCall());
689 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
690 service.createNetworkServiceInstance(request);
694 public void itCanGetNetworkServiceInfo() throws IOException {
695 nsServiceRsp ns = new nsServiceRsp();
696 List<String> list = new ArrayList<>();
697 String s = "{\"nsInstanceId\":\"nsInstanceId\"}";
699 ns.setNsServices(list);
700 VfcService vfcService = mock(VfcService.class);
701 when(vfcService.getNetworkServiceInfo()).thenReturn(successfulCall(ns));
702 ServiceLcmService serviceLcmService = mock(ServiceLcmService.class);
703 DefaultPackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
704 service.setServiceLcmService(serviceLcmService);
705 when(serviceLcmService.getServiceBeanByServiceInStanceId("nsInstanceId")).thenReturn(new ServiceBean());
706 Assert.assertNotNull( service.getNetworkServiceInfo());
710 public void getNetworkServiceInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
711 VfcService vfcService = mock(VfcService.class);
712 when(vfcService.getNetworkServiceInfo()).thenReturn(failedCall("VFC is not available!"));
713 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
714 service.getNetworkServiceInfo();
718 public void getNetworkServiceInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
719 VfcService vfcService = mock(VfcService.class);
720 when(vfcService.getNetworkServiceInfo()).thenReturn(emptyBodyCall());
721 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
722 service.getNetworkServiceInfo();
728 public void itCanHealNetworkServiceInstance() throws IOException {
729 HttpServletRequest request = mockRequest();
731 ResponseBody result=null;
732 VfcService vfcService = mock(VfcService.class);
733 //when(vfcService.healNetworkServiceInstance(csarId,anyObject())).thenReturn(successfulCall(result));
734 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
736 //Assert.assertSame(result, service.healNetworkServiceInstance(request,csarId));
737 service.healNetworkServiceInstance(request,csarId);
741 public void healNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
742 HttpServletRequest request = mockRequest();
744 VfcService vfcService = mock(VfcService.class);
745 when(vfcService.healNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(failedCall("VFC is not available!"));
746 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
747 service.healNetworkServiceInstance(request,csarId);
751 public void healNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
752 HttpServletRequest request = mockRequest();
754 VfcService vfcService = mock(VfcService.class);
755 when(vfcService.healNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(emptyBodyCall());
756 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
757 service.healNetworkServiceInstance(request,csarId);
761 public void itCanScaleNetworkServiceInstance() throws IOException {
762 HttpServletRequest request = mockRequest();
764 ResponseBody result=null;
765 VfcService vfcService = mock(VfcService.class);
766 //when(vfcService.scaleNetworkServiceInstance(csarId,anyObject())).thenReturn(successfulCall(result));
767 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
769 Assert.assertTrue(StringUtils.isNotEmpty(service.scaleNetworkServiceInstance(request,csarId)));
773 public void scaleNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
774 HttpServletRequest request = mockRequest();
776 VfcService vfcService = mock(VfcService.class);
777 when(vfcService.scaleNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(failedCall("VFC is not available!"));
778 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
779 service.scaleNetworkServiceInstance(request,csarId);
783 public void scaleNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
784 HttpServletRequest request = mockRequest();
786 VfcService vfcService = mock(VfcService.class);
787 when(vfcService.scaleNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(emptyBodyCall());
788 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
789 service.scaleNetworkServiceInstance(request,csarId);
794 public void itCaninstantiateNetworkServiceInstance() throws IOException {
795 HttpServletRequest request = mockRequest();
796 String serviceInstanceId="1";
797 ResponseBody result=null;
798 VfcService vfcService = mock(VfcService.class);
799 //when(vfcService.instantiateNetworkServiceInstance(anyObject(),serviceInstanceId)).thenReturn(successfulCall(result));
800 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
802 service.instantiateNetworkServiceInstance(request,serviceInstanceId);
806 public void instantiateNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
807 HttpServletRequest request = mockRequest();
808 String serviceInstanceId="1";
809 VfcService vfcService = mock(VfcService.class);
810 when(vfcService.instantiateNetworkServiceInstance(Mockito.any(),eq(serviceInstanceId))).thenReturn(failedCall("VFC is not available!"));
811 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
812 service.instantiateNetworkServiceInstance(request,serviceInstanceId);
816 public void instantiateNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
817 HttpServletRequest request = mockRequest();
818 String serviceInstanceId="1";
819 VfcService vfcService = mock(VfcService.class);
820 when(vfcService.instantiateNetworkServiceInstance(Mockito.any(),eq(serviceInstanceId))).thenReturn(emptyBodyCall());
821 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
822 service.instantiateNetworkServiceInstance(request,serviceInstanceId);
827 public void itCanTerminateNetworkServiceInstance() throws IOException {
828 HttpServletRequest request = mockRequest();
830 ResponseBody result=null;
832 VfcService vfcService = mock(VfcService.class);
833 when(vfcService.terminateNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(successfulCall(result));
834 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
836 service.terminateNetworkServiceInstance(request,csarId);
840 public void terminateNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
841 HttpServletRequest request = mockRequest();
843 VfcService vfcService = mock(VfcService.class);
844 //when(vfcService.terminateNetworkServiceInstance(csarId,anyObject())).thenReturn(failedCall("VFC is not available!"));
845 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
846 service.terminateNetworkServiceInstance(request,csarId);
850 public void terminateNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
851 HttpServletRequest request = mockRequest();
853 VfcService vfcService = mock(VfcService.class);
854 when(vfcService.terminateNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(emptyBodyCall());
855 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
856 service.terminateNetworkServiceInstance(request,csarId);
860 public void itCreateNetworkServiceData() throws IOException {
861 HttpServletRequest request = mockRequest();
862 ResponseBody result=null;
863 VfcService vfcService = mock(VfcService.class);
864 when(vfcService.createNetworkServiceData(Mockito.any())).thenReturn(successfulCall(result));
865 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
867 Assert.assertTrue(StringUtils.isNotEmpty(service.createNetworkServiceData(request)));
871 public void createNetworkServiceDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
872 HttpServletRequest request = mockRequest();
873 VfcService vfcService = mock(VfcService.class);
874 when(vfcService.createNetworkServiceData(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
875 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
876 service.createNetworkServiceData(request);
880 public void createNetworkServiceDataWillThrowExceptionWhenVFCResponseError() throws IOException {
881 HttpServletRequest request = mockRequest();
882 VfcService vfcService = mock(VfcService.class);
883 when(vfcService.createNetworkServiceData(Mockito.any())).thenReturn(emptyBodyCall());
884 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
885 service.createNetworkServiceData(request);
889 public void itCreateVnfData() throws IOException {
890 HttpServletRequest request = mockRequest();
891 ResponseBody result=null;
892 VfcService vfcService = mock(VfcService.class);
893 when(vfcService.createVnfData(Mockito.any())).thenReturn(successfulCall(result));
894 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
896 Assert.assertSame("{\"status\":\"FAILED\"}", service.createVnfData(request));
900 public void createVnfDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
901 HttpServletRequest request = mockRequest();
902 VfcService vfcService = mock(VfcService.class);
903 when(vfcService.createVnfData(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
904 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
905 service.createVnfData(request);
909 public void createVnfDataWillThrowExceptionWhenVFCResponseError() throws IOException {
910 HttpServletRequest request = mockRequest();
911 VfcService vfcService = mock(VfcService.class);
912 when(vfcService.createVnfData(Mockito.any())).thenReturn(emptyBodyCall());
913 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
914 service.createVnfData(request);
918 public void itCreatePnfData() throws IOException {
919 HttpServletRequest request = mockRequest();
920 ResponseBody result=null;
921 VfcService vfcService = mock(VfcService.class);
922 when(vfcService.createPnfData(Mockito.any())).thenReturn(successfulCall(result));
923 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
925 Assert.assertSame("{\"status\":\"FAILED\"}", service.createPnfData(request));
929 public void createPnfDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
930 HttpServletRequest request = mockRequest();
931 VfcService vfcService = mock(VfcService.class);
932 when(vfcService.createPnfData(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
933 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
934 service.createPnfData(request);
938 public void createPnfDataWillThrowExceptionWhenVFCResponseError() throws IOException {
939 HttpServletRequest request = mockRequest();
940 VfcService vfcService = mock(VfcService.class);
941 when(vfcService.createPnfData(Mockito.any())).thenReturn(emptyBodyCall());
942 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
943 service.createPnfData(request);
947 public void itGetNsdInfo() throws IOException {
949 ResponseBody result=null;
950 VfcService vfcService = mock(VfcService.class);
951 when(vfcService.getNsdInfo(nsdId)).thenReturn(successfulCall(result));
952 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
954 Assert.assertSame("{\"status\":\"SUCCESS\"}", service.getNsdInfo(nsdId));
958 public void getNsdInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
960 VfcService vfcService = mock(VfcService.class);
961 when(vfcService.getNsdInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
962 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
963 service.getNsdInfo(nsdId);
967 public void getNsdInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
969 VfcService vfcService = mock(VfcService.class);
970 when(vfcService.getNsdInfo(nsdId)).thenReturn(emptyBodyCall());
971 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
972 service.getNsdInfo(nsdId);
976 public void itGetVnfInfo() throws IOException {
978 ResponseBody result=null;
979 VfcService vfcService = mock(VfcService.class);
980 when(vfcService.getVnfInfo(nsdId)).thenReturn(successfulCall(result));
981 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
983 Assert.assertSame("{\"status\":\"SUCCESS\"}", service.getVnfInfo(nsdId));
987 public void getVnfInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
989 VfcService vfcService = mock(VfcService.class);
990 when(vfcService.getVnfInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
991 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
992 service.getVnfInfo(nsdId);
996 public void getVnfInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
998 VfcService vfcService = mock(VfcService.class);
999 when(vfcService.getVnfInfo(nsdId)).thenReturn(emptyBodyCall());
1000 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1001 service.getVnfInfo(nsdId);
1005 public void itGetPnfInfo() throws IOException {
1007 ResponseBody result=null;
1008 VfcService vfcService = mock(VfcService.class);
1009 when(vfcService.getPnfInfo(nsdId)).thenReturn(successfulCall(result));
1010 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1012 Assert.assertSame("{\"status\":\"SUCCESS\"}", service.getPnfInfo(nsdId));
1016 public void getPnfInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
1018 VfcService vfcService = mock(VfcService.class);
1019 when(vfcService.getPnfInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
1020 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1021 service.getPnfInfo(nsdId);
1025 public void getPnfInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
1027 VfcService vfcService = mock(VfcService.class);
1028 when(vfcService.getPnfInfo(nsdId)).thenReturn(emptyBodyCall());
1029 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1030 service.getPnfInfo(nsdId);
1034 public void itCanListNsTemplates() throws IOException {
1035 VfcService vfcService = mock(VfcService.class);
1036 when(vfcService.listNsTemplates()).thenReturn(successfulCall(result));
1037 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1039 Assert.assertNotNull( service.listNsTemplates());
1043 public void listNsTemplatesWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
1044 VfcService vfcService = mock(VfcService.class);
1045 when(vfcService.listNsTemplates()).thenReturn(failedCall("VFC is not available!"));
1046 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1047 service.listNsTemplates();
1051 public void listNsTemplatesWillThrowExceptionWhenVFCResponseError() throws IOException {
1052 VfcService vfcService = mock(VfcService.class);
1053 when(vfcService.listNsTemplates()).thenReturn(emptyBodyCall());
1054 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1055 service.listNsTemplates();
1059 public void itCanGetVnfInfoById() throws IOException {
1061 VfcService vfcService = mock(VfcService.class);
1062 when(vfcService.getVnfInfoById(nsdId)).thenReturn(successfulCall(result));
1063 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1065 Assert.assertNotNull(service.getVnfInfoById(nsdId));
1069 public void getVnfInfoByIdWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
1071 VfcService vfcService = mock(VfcService.class);
1072 when(vfcService.getVnfInfoById(nsdId)).thenReturn(failedCall("VFC is not available!"));
1073 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1074 service.getVnfInfoById(nsdId);
1078 public void getVnfInfoByIdWillThrowExceptionWhenVFCResponseError() throws IOException {
1080 VfcService vfcService = mock(VfcService.class);
1081 when(vfcService.getVnfInfoById(nsdId)).thenReturn(emptyBodyCall());
1082 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1083 service.getVnfInfoById(nsdId);
1087 public void itCanFetchNsTemplateData() throws IOException {
1088 HttpServletRequest request = mockRequest();
1089 ResponseBody result=null;
1090 VfcService vfcService = mock(VfcService.class);
1091 when(vfcService.fetchNsTemplateData(Mockito.any())).thenReturn(successfulCall(result));
1092 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1094 Assert.assertSame("{\"status\":\"FAILED\"}", service.fetchNsTemplateData(request));
1098 public void fetchNsTemplateDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
1099 HttpServletRequest request = mockRequest();
1100 VfcService vfcService = mock(VfcService.class);
1101 when(vfcService.fetchNsTemplateData(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
1102 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1103 service.fetchNsTemplateData(request);
1107 public void fetchNsTemplateDataWillThrowExceptionWhenVFCResponseError() throws IOException {
1108 HttpServletRequest request = mockRequest();
1109 VfcService vfcService = mock(VfcService.class);
1110 when(vfcService.fetchNsTemplateData(Mockito.any())).thenReturn(emptyBodyCall());
1111 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1112 service.fetchNsTemplateData(request);