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 org.junit.Assert;
19 import org.junit.Test;
20 import org.onap.usecaseui.server.bean.lcm.VfNsPackageInfo;
21 import org.onap.usecaseui.server.service.lcm.PackageDistributionService;
22 import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService;
23 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.VimInfo;
24 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.VimInfoRsp;
25 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.nsServiceRsp;
26 import org.onap.usecaseui.server.service.lcm.domain.sdc.SDCCatalogService;
27 import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.SDCServiceTemplate;
28 import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.Vnf;
29 import org.onap.usecaseui.server.service.lcm.domain.sdc.exceptions.SDCCatalogException;
30 import org.onap.usecaseui.server.service.lcm.domain.vfc.VfcService;
31 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Csar;
32 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.DistributionResult;
33 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Job;
34 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.JobStatus;
35 import org.onap.usecaseui.server.service.lcm.domain.vfc.exceptions.VfcException;
37 import okhttp3.ResponseBody;
38 import retrofit2.Call;
40 import java.io.IOException;
41 import java.util.Collections;
42 import java.util.List;
44 import javax.servlet.ReadListener;
45 import javax.servlet.ServletInputStream;
46 import javax.servlet.http.HttpServletRequest;
48 import static org.mockito.Matchers.anyObject;
49 import static org.hamcrest.CoreMatchers.equalTo;
50 import static org.mockito.Mockito.mock;
51 import static org.mockito.Mockito.when;
52 import static org.onap.usecaseui.server.service.lcm.domain.sdc.consts.SDCConsts.*;
53 import static org.onap.usecaseui.server.util.CallStub.emptyBodyCall;
54 import static org.onap.usecaseui.server.util.CallStub.failedCall;
55 import static org.onap.usecaseui.server.util.CallStub.successfulCall;
57 public class DefaultPackageDistributionServiceTest {
60 private HttpServletRequest mockRequest() throws IOException {
61 HttpServletRequest request = mock(HttpServletRequest.class);
62 when(request.getContentLength()).thenReturn(0);
63 ServletInputStream inStream = new ServletInputStream() {
65 public boolean isFinished() {
70 public boolean isReady() {
75 public void setReadListener(ReadListener readListener) {
80 public int read() throws IOException {
84 when(request.getInputStream()).thenReturn(inStream);
89 public void itCanRetrievePackageFromSDCAndAAI() {
90 List<SDCServiceTemplate> serviceTemplate = Collections.singletonList(new SDCServiceTemplate("1", "1", "service", "V1","", ""));
92 o.setInvariantUUID("2");
95 List<Vnf> vnf = Collections.singletonList(o);
96 SDCCatalogService sdcService = newSDCService(serviceTemplate, vnf);
98 List<VimInfo> vim = Collections.singletonList(new VimInfo("owner", "regionId"));
99 AAIService aaiService = newAAIService(vim);
101 PackageDistributionService service = new DefaultPackageDistributionService(sdcService, null);
103 Assert.assertThat(service.retrievePackageInfo(), equalTo(new VfNsPackageInfo(serviceTemplate, vnf)));
106 private AAIService newAAIService(List<VimInfo> vim) {
107 AAIService aaiService = mock(AAIService.class);
108 VimInfoRsp rsp = new VimInfoRsp();
109 rsp.setCloudRegion(vim);
110 Call<VimInfoRsp> vimCall = successfulCall(rsp);
111 when(aaiService.listVimInfo()).thenReturn(vimCall);
115 private SDCCatalogService newSDCService(List<SDCServiceTemplate> serviceTemplate, List<Vnf> vnf) {
116 SDCCatalogService sdcService = mock(SDCCatalogService.class);
118 Call<List<SDCServiceTemplate>> serviceCall = successfulCall(serviceTemplate);
119 when(sdcService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(serviceCall);
121 Call<List<Vnf>> vnfCall = successfulCall(vnf);
122 when(sdcService.listResources(RESOURCETYPE_VF)).thenReturn(vnfCall);
126 @Test(expected = SDCCatalogException.class)
127 public void retrievePackageWillThrowExceptionWhenSDCIsNotAvailable() {
128 SDCCatalogService sdcService = mock(SDCCatalogService.class);
129 Call<List<SDCServiceTemplate>> serviceCall = failedCall("SDC is not available!");
130 when(sdcService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(serviceCall);
132 List<VimInfo> vim = Collections.singletonList(new VimInfo("owner", "regionId"));
133 AAIService aaiService = newAAIService(vim);
135 PackageDistributionService service = new DefaultPackageDistributionService(sdcService, null);
136 service.retrievePackageInfo();
140 public void retrievePackageWillBeEmptyWhenNoNsServiceAndVfInSDC() {
141 SDCCatalogService sdcService = mock(SDCCatalogService.class);
142 Call<List<SDCServiceTemplate>> serviceCall = emptyBodyCall();
143 when(sdcService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(serviceCall);
145 Call<List<Vnf>> resourceCall = emptyBodyCall();
146 when(sdcService.listResources(RESOURCETYPE_VF)).thenReturn(resourceCall);
148 PackageDistributionService service = new DefaultPackageDistributionService(sdcService, null);
149 VfNsPackageInfo vfNsPackageInfo = service.retrievePackageInfo();
151 Assert.assertTrue("ns should be empty!", vfNsPackageInfo.getNsPackage().isEmpty());
152 Assert.assertTrue("vf should be empty!", vfNsPackageInfo.getVnfPackages().isEmpty());
156 public void itCanPostNsPackageToVFC() {
157 VfcService vfcService = mock(VfcService.class);
158 Csar csar = new Csar();
159 DistributionResult result = new DistributionResult();
160 result.setStatus("status");
161 result.setStatusDescription("description");
162 result.setErrorCode("errorcode");
163 when(vfcService.distributeNsPackage(csar)).thenReturn(successfulCall(result));
164 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
166 Assert.assertSame(result, service.postNsPackage(csar));
169 @Test(expected = VfcException.class)
170 public void postNsPackageWillThrowExceptionWhenVFCIsNotAvailable() {
171 VfcService vfcService = mock(VfcService.class);
172 Csar csar = new Csar();
173 when(vfcService.distributeNsPackage(csar)).thenReturn(failedCall("VFC is not available!"));
174 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
175 service.postNsPackage(csar);
178 @Test(expected = VfcException.class)
179 public void postNsPackageWillThrowExceptionWhenVFCResponseError() {
180 VfcService vfcService = mock(VfcService.class);
181 Csar csar = new Csar();
182 when(vfcService.distributeNsPackage(csar)).thenReturn(emptyBodyCall());
183 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
184 service.postNsPackage(csar);
188 public void itCanPostVnfPackageToVFC() {
189 VfcService vfcService = mock(VfcService.class);
190 Csar csar = new Csar();
192 when(vfcService.distributeVnfPackage(csar)).thenReturn(successfulCall(job));
193 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
195 Assert.assertSame(job, service.postVfPackage(csar));
198 @Test(expected = VfcException.class)
199 public void postVnfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
200 VfcService vfcService = mock(VfcService.class);
201 Csar csar = new Csar();
202 when(vfcService.distributeVnfPackage(csar)).thenReturn(failedCall("VFC is not available!"));
203 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
204 service.postVfPackage(csar);
207 @Test(expected = VfcException.class)
208 public void postVnfPackageWillThrowExceptionWhenVFCResponseError() {
209 VfcService vfcService = mock(VfcService.class);
210 Csar csar = new Csar();
211 when(vfcService.distributeVnfPackage(csar)).thenReturn(emptyBodyCall());
212 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
213 service.postVfPackage(csar);
217 public void itCanGetJobStatusFromVFC() {
218 VfcService vfcService = mock(VfcService.class);
220 String responseId = "1";
221 JobStatus jobStatus = new JobStatus();
222 when(vfcService.getJobStatus(jobId, responseId)).thenReturn(successfulCall(jobStatus));
223 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
225 Assert.assertSame(jobStatus, service.getJobStatus(jobId, responseId));
228 @Test(expected = VfcException.class)
229 public void getJobStatusWillThrowExceptionWhenVFCIsNotAvailable() {
230 VfcService vfcService = mock(VfcService.class);
232 String responseId = "1";
233 when(vfcService.getJobStatus(jobId, responseId)).thenReturn(failedCall("VFC is not available!"));
234 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
235 service.getJobStatus(jobId, responseId);
238 @Test(expected = VfcException.class)
239 public void getJobStatusWillThrowExceptionWhenVFCResponseError() {
240 VfcService vfcService = mock(VfcService.class);
242 String responseId = "1";
243 when(vfcService.getJobStatus(jobId, responseId)).thenReturn(emptyBodyCall());
244 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
245 service.getJobStatus(jobId, responseId);
249 public void itCanGetNsLcmJobStatusFromVFC() {
250 VfcService vfcService = mock(VfcService.class);
252 String responseId = "1";
253 String serviceId= "1";
254 String operationType= "1";
255 JobStatus jobStatus = new JobStatus();
256 when(vfcService.getNsLcmJobStatus(jobId, responseId)).thenReturn(successfulCall(jobStatus));
257 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
259 Assert.assertSame(jobStatus, service.getNsLcmJobStatus(serviceId,jobId, responseId,operationType));
262 @Test(expected = VfcException.class)
263 public void getNsLcmJobStatusWillThrowExceptionWhenVFCIsNotAvailable() {
264 VfcService vfcService = mock(VfcService.class);
266 String responseId = "1";
267 String serviceId= "1";
268 String operationType= "1";
269 when(vfcService.getNsLcmJobStatus(jobId, responseId)).thenReturn(failedCall("VFC is not available!"));
270 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
271 service.getNsLcmJobStatus(serviceId,jobId, responseId,operationType);
274 @Test(expected = VfcException.class)
275 public void getNsLcmJobStatusWillThrowExceptionWhenVFCResponseError() {
276 VfcService vfcService = mock(VfcService.class);
278 String responseId = "1";
279 String serviceId= "1";
280 String operationType= "1";
281 when(vfcService.getNsLcmJobStatus(jobId, responseId)).thenReturn(emptyBodyCall());
282 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
283 service.getNsLcmJobStatus(serviceId,jobId, responseId,operationType);
287 public void itCanDeleteNsPackage() {
289 DistributionResult result = new DistributionResult();
290 VfcService vfcService = mock(VfcService.class);
291 when(vfcService.deleteNsPackage(csarId)).thenReturn(successfulCall(result));
292 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
294 Assert.assertSame(result, service.deleteNsPackage(csarId));
297 @Test(expected = VfcException.class)
298 public void deleteNsPackageWillThrowExceptionWhenVFCIsNotAvailable() {
300 VfcService vfcService = mock(VfcService.class);
301 when(vfcService.deleteNsPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
302 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
303 service.deleteNsPackage(csarId);
306 @Test(expected = VfcException.class)
307 public void deleteNsPackageWillThrowExceptionWhenVFCResponseError() {
309 VfcService vfcService = mock(VfcService.class);
310 when(vfcService.deleteNsPackage(csarId)).thenReturn(emptyBodyCall());
311 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
312 service.deleteNsPackage(csarId);
316 public void itCanGetVnfPackages(){
317 ResponseBody result=null;
318 VfcService vfcService = mock(VfcService.class);
319 when(vfcService.getVnfPackages()).thenReturn(successfulCall(result));
320 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
322 Assert.assertSame(result, service.getVnfPackages());
326 public void getVnfPackagesThrowExceptionWhenVFCResponseError(){
328 VfcService vfcService = mock(VfcService.class);
329 when(vfcService.getVnfPackages ()).thenReturn(emptyBodyCall());
330 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
331 service.getVnfPackages();
335 public void getVnfPackagesThrowException(){
336 VfcService vfcService = mock(VfcService.class);
337 when(vfcService.getVnfPackages ()).thenReturn(failedCall("VFC is not available!"));
338 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
339 service.getVnfPackages();
343 public void itCanDeleteVFPackage() {
346 VfcService vfcService = mock(VfcService.class);
347 when(vfcService.deleteVnfPackage(csarId)).thenReturn(successfulCall(job));
348 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
350 Assert.assertSame(job, service.deleteVfPackage(csarId));
353 @Test(expected = VfcException.class)
354 public void deleteVfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
356 VfcService vfcService = mock(VfcService.class);
357 when(vfcService.deleteVnfPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
358 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
359 service.deleteVfPackage(csarId);
362 @Test(expected = VfcException.class)
363 public void deleteVnfPackageWillThrowExceptionWhenVFCResponseError() {
365 VfcService vfcService = mock(VfcService.class);
366 when(vfcService.deleteVnfPackage(csarId)).thenReturn(emptyBodyCall());
367 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
368 service.deleteVnfPackage(csarId);
372 public void itCanGetNetworkServicePackages() {
373 ResponseBody responseBody = null;
374 VfcService vfcService = mock(VfcService.class);
375 JobStatus jobStatus = new JobStatus();
376 when(vfcService.getNetworkServicePackages()).thenReturn(successfulCall(responseBody));
377 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
379 Assert.assertSame(jobStatus, service.getNetworkServicePackages());
382 @Test(expected = VfcException.class)
383 public void getNetworkServicePackagesWillThrowExceptionWhenVFCIsNotAvailable() {
384 VfcService vfcService = mock(VfcService.class);
385 when(vfcService.getNetworkServicePackages()).thenReturn(failedCall("VFC is not available!"));
386 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
387 service.getNetworkServicePackages();
390 @Test(expected = VfcException.class)
391 public void getNetworkServicePackagesWillThrowExceptionWhenVFCResponseError() {
392 VfcService vfcService = mock(VfcService.class);
393 when(vfcService.getNetworkServicePackages()).thenReturn(emptyBodyCall());
394 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
395 service.getNetworkServicePackages();
399 public void itCanGetPnfPackages(){
400 ResponseBody result=null;
401 VfcService vfcService = mock(VfcService.class);
402 when(vfcService.getPnfPackages()).thenReturn(successfulCall(result));
403 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
405 Assert.assertSame(result, service.getPnfPackages());
409 public void getPnfPackagesThrowExceptionWhenVFCResponseError(){
411 VfcService vfcService = mock(VfcService.class);
412 when(vfcService.getPnfPackages ()).thenReturn(emptyBodyCall());
413 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
414 service.getPnfPackages();
418 public void getPnfPackagesThrowException(){
419 VfcService vfcService = mock(VfcService.class);
420 when(vfcService.getPnfPackages ()).thenReturn(failedCall("VFC is not available!"));
421 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
422 service.getPnfPackages();
426 public void itDownLoadNsPackage(){
427 String nsdInfoId="1";
428 ResponseBody result=null;
429 VfcService vfcService = mock(VfcService.class);
430 when(vfcService.downLoadNsPackage(nsdInfoId)).thenReturn(successfulCall(result));
431 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
433 Assert.assertSame(result, service.downLoadNsPackage(nsdInfoId));
437 public void downLoadNsPackagehrowExceptionWhenVFCResponseError(){
438 String nsdInfoId="1";
439 VfcService vfcService = mock(VfcService.class);
440 when(vfcService.downLoadNsPackage (nsdInfoId)).thenReturn(emptyBodyCall());
441 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
442 service.downLoadNsPackage(nsdInfoId);
446 public void downLoadNsPackageThrowException(){
447 String nsdInfoId="1";
448 VfcService vfcService = mock(VfcService.class);
449 when(vfcService.downLoadNsPackage (nsdInfoId)).thenReturn(failedCall("VFC is not available!"));
450 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
451 service.downLoadNsPackage(nsdInfoId);
455 public void itDownLoadPnfPackage(){
456 String pnfInfoId="1";
457 ResponseBody result=null;
458 VfcService vfcService = mock(VfcService.class);
459 when(vfcService.downLoadPnfPackage(pnfInfoId)).thenReturn(successfulCall(result));
460 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
462 Assert.assertSame(result, service.downLoadPnfPackage(pnfInfoId));
466 public void downLoadPnfPackagehrowExceptionWhenVFCResponseError(){
467 String pnfInfoId="1";
468 VfcService vfcService = mock(VfcService.class);
469 when(vfcService.downLoadPnfPackage (pnfInfoId)).thenReturn(emptyBodyCall());
470 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
471 service.downLoadPnfPackage(pnfInfoId);
475 public void downLoadPnfPackageThrowException(){
476 String pnfInfoId="1";
477 VfcService vfcService = mock(VfcService.class);
478 when(vfcService.downLoadPnfPackage (pnfInfoId)).thenReturn(failedCall("VFC is not available!"));
479 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
480 service.downLoadPnfPackage(pnfInfoId);
484 public void itDownLoadVnfPackage(){
485 String vnfInfoId="1";
486 ResponseBody result=null;
487 VfcService vfcService = mock(VfcService.class);
488 when(vfcService.downLoadVnfPackage(vnfInfoId)).thenReturn(successfulCall(result));
489 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
491 Assert.assertSame(result, service.downLoadVnfPackage(vnfInfoId));
495 public void downLoadVnfPackagehrowExceptionWhenVFCResponseError(){
496 String vnfInfoId="1";
497 VfcService vfcService = mock(VfcService.class);
498 when(vfcService.downLoadVnfPackage (vnfInfoId)).thenReturn(emptyBodyCall());
499 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
500 service.downLoadVnfPackage(vnfInfoId);
504 public void downLoadVnfPackageThrowException(){
505 String vnfInfoId="1";
506 VfcService vfcService = mock(VfcService.class);
507 when(vfcService.downLoadVnfPackage (vnfInfoId)).thenReturn(failedCall("VFC is not available!"));
508 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
509 service.downLoadVnfPackage(vnfInfoId);
513 public void itCanDeleteNsdPackage() {
515 ResponseBody result=null;
516 VfcService vfcService = mock(VfcService.class);
517 when(vfcService.deleteNsdPackage(csarId)).thenReturn(successfulCall(result));
518 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
520 Assert.assertSame(result, service.deleteNsdPackage(csarId));
523 @Test(expected = VfcException.class)
524 public void deleteNsdPackageWillThrowExceptionWhenVFCIsNotAvailable() {
526 VfcService vfcService = mock(VfcService.class);
527 when(vfcService.deleteNsdPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
528 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
529 service.deleteNsdPackage(csarId);
532 @Test(expected = VfcException.class)
533 public void deleteNsdPackageWillThrowExceptionWhenVFCResponseError() {
535 VfcService vfcService = mock(VfcService.class);
536 when(vfcService.deleteNsdPackage(csarId)).thenReturn(emptyBodyCall());
537 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
538 service.deleteNsdPackage(csarId);
542 public void itCanDeleteVnfPackage() {
544 ResponseBody result=null;
546 VfcService vfcService = mock(VfcService.class);
547 when(vfcService.deleteVnfPackage(csarId)).thenReturn(successfulCall(job));
548 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
550 Assert.assertSame(job, service.deleteVnfPackage(csarId));
553 @Test(expected = VfcException.class)
554 public void deleteVnfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
556 VfcService vfcService = mock(VfcService.class);
557 when(vfcService.deleteVnfPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
558 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
559 service.deleteVnfPackage(csarId);
562 @Test(expected = VfcException.class)
563 public void deleteVnfNsdPackageWillThrowExceptionWhenVFCResponseError() {
565 VfcService vfcService = mock(VfcService.class);
566 when(vfcService.deleteVnfPackage(csarId)).thenReturn(emptyBodyCall());
567 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
568 service.deleteVnfPackage(csarId);
572 public void itCanDeletePnfdPackage() {
574 ResponseBody result=null;
576 VfcService vfcService = mock(VfcService.class);
577 when(vfcService.deletePnfdPackage(csarId)).thenReturn(successfulCall(result));
578 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
580 Assert.assertSame(result, service.deletePnfPackage(csarId));
583 @Test(expected = VfcException.class)
584 public void deletePnfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
586 VfcService vfcService = mock(VfcService.class);
587 when(vfcService.deletePnfdPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
588 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
589 service.deletePnfPackage(csarId);
592 @Test(expected = VfcException.class)
593 public void deletePnfPackageWillThrowExceptionWhenVFCResponseError() {
595 VfcService vfcService = mock(VfcService.class);
596 when(vfcService.deletePnfdPackage(csarId)).thenReturn(emptyBodyCall());
597 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
598 service.deletePnfPackage(csarId);
602 public void itCanDeleteNetworkServiceInstance() {
604 ResponseBody result=null;
606 VfcService vfcService = mock(VfcService.class);
607 when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(successfulCall(result));
608 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
610 Assert.assertSame(result, service.deleteNetworkServiceInstance(csarId));
613 @Test(expected = VfcException.class)
614 public void deleteNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() {
616 VfcService vfcService = mock(VfcService.class);
617 when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(failedCall("VFC is not available!"));
618 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
619 service.deleteNetworkServiceInstance(csarId);
622 @Test(expected = VfcException.class)
623 public void deleteNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() {
625 VfcService vfcService = mock(VfcService.class);
626 when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(emptyBodyCall());
627 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
628 service.deleteNetworkServiceInstance(csarId);
632 public void itCanCreateNetworkServiceInstance() throws IOException {
633 HttpServletRequest request = mockRequest();
634 ResponseBody result=null;
635 VfcService vfcService = mock(VfcService.class);
636 when(vfcService.createNetworkServiceInstance(anyObject())).thenReturn(successfulCall(result));
637 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
639 Assert.assertSame(result, service.createNetworkServiceInstance(request));
642 @Test(expected = VfcException.class)
643 public void createNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
644 HttpServletRequest request = mockRequest();
645 VfcService vfcService = mock(VfcService.class);
646 when(vfcService.createNetworkServiceInstance(anyObject())).thenReturn(failedCall("VFC is not available!"));
647 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
648 service.createNetworkServiceInstance(request);
651 @Test(expected = VfcException.class)
652 public void createNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
653 HttpServletRequest request = mockRequest();
654 VfcService vfcService = mock(VfcService.class);
655 when(vfcService.createNetworkServiceInstance(anyObject())).thenReturn(emptyBodyCall());
656 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
657 service.createNetworkServiceInstance(request);
661 public void itCanGetNetworkServiceInfo() throws IOException {
662 ResponseBody result=null;
663 nsServiceRsp ns = new nsServiceRsp();
664 VfcService vfcService = mock(VfcService.class);
665 when(vfcService.getNetworkServiceInfo()).thenReturn(successfulCall(ns));
666 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
668 Assert.assertSame(result, service.getNetworkServiceInfo());
671 @Test(expected = VfcException.class)
672 public void getNetworkServiceInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
673 VfcService vfcService = mock(VfcService.class);
674 when(vfcService.getNetworkServiceInfo()).thenReturn(failedCall("VFC is not available!"));
675 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
676 service.getNetworkServiceInfo();
679 @Test(expected = VfcException.class)
680 public void getNetworkServiceInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
681 VfcService vfcService = mock(VfcService.class);
682 when(vfcService.getNetworkServiceInfo()).thenReturn(emptyBodyCall());
683 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
684 service.getNetworkServiceInfo();
690 public void itCanHealNetworkServiceInstance() throws IOException {
691 HttpServletRequest request = mockRequest();
693 ResponseBody result=null;
694 VfcService vfcService = mock(VfcService.class);
695 //when(vfcService.healNetworkServiceInstance(csarId,anyObject())).thenReturn(successfulCall(result));
696 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
698 //Assert.assertSame(result, service.healNetworkServiceInstance(request,csarId));
699 service.healNetworkServiceInstance(request,csarId);
702 @Test(expected = VfcException.class)
703 public void healNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
704 HttpServletRequest request = mockRequest();
706 VfcService vfcService = mock(VfcService.class);
707 when(vfcService.healNetworkServiceInstance(csarId,anyObject())).thenReturn(failedCall("VFC is not available!"));
708 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
709 service.healNetworkServiceInstance(request,csarId);
712 @Test(expected = VfcException.class)
713 public void healNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
714 HttpServletRequest request = mockRequest();
716 VfcService vfcService = mock(VfcService.class);
717 when(vfcService.healNetworkServiceInstance(csarId,anyObject())).thenReturn(emptyBodyCall());
718 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
719 service.healNetworkServiceInstance(request,csarId);
723 public void itCanScaleNetworkServiceInstance() throws IOException {
724 HttpServletRequest request = mockRequest();
726 ResponseBody result=null;
727 VfcService vfcService = mock(VfcService.class);
728 //when(vfcService.scaleNetworkServiceInstance(csarId,anyObject())).thenReturn(successfulCall(result));
729 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
731 Assert.assertSame(result, service.scaleNetworkServiceInstance(request,csarId));
734 @Test(expected = VfcException.class)
735 public void scaleNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
736 HttpServletRequest request = mockRequest();
738 VfcService vfcService = mock(VfcService.class);
739 when(vfcService.scaleNetworkServiceInstance(csarId,anyObject())).thenReturn(failedCall("VFC is not available!"));
740 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
741 service.scaleNetworkServiceInstance(request,csarId);
744 @Test(expected = VfcException.class)
745 public void scaleNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
746 HttpServletRequest request = mockRequest();
748 VfcService vfcService = mock(VfcService.class);
749 when(vfcService.scaleNetworkServiceInstance(csarId,anyObject())).thenReturn(emptyBodyCall());
750 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
751 service.scaleNetworkServiceInstance(request,csarId);
756 public void itCaninstantiateNetworkServiceInstance() throws IOException {
757 HttpServletRequest request = mockRequest();
758 String serviceInstanceId="1";
759 ResponseBody result=null;
760 VfcService vfcService = mock(VfcService.class);
761 //when(vfcService.instantiateNetworkServiceInstance(anyObject(),serviceInstanceId)).thenReturn(successfulCall(result));
762 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
764 service.instantiateNetworkServiceInstance(request,serviceInstanceId);
767 @Test(expected = VfcException.class)
768 public void instantiateNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
769 HttpServletRequest request = mockRequest();
770 String serviceInstanceId="1";
771 VfcService vfcService = mock(VfcService.class);
772 when(vfcService.instantiateNetworkServiceInstance(anyObject(),serviceInstanceId)).thenReturn(failedCall("VFC is not available!"));
773 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
774 service.instantiateNetworkServiceInstance(request,serviceInstanceId);
777 @Test(expected = VfcException.class)
778 public void instantiateNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
779 HttpServletRequest request = mockRequest();
780 String serviceInstanceId="1";
781 VfcService vfcService = mock(VfcService.class);
782 when(vfcService.instantiateNetworkServiceInstance(anyObject(),serviceInstanceId)).thenReturn(emptyBodyCall());
783 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
784 service.instantiateNetworkServiceInstance(request,serviceInstanceId);
789 public void itCanTerminateNetworkServiceInstance() throws IOException {
790 HttpServletRequest request = mockRequest();
792 ResponseBody result=null;
794 VfcService vfcService = mock(VfcService.class);
795 when(vfcService.terminateNetworkServiceInstance(csarId,anyObject())).thenReturn(successfulCall(result));
796 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
798 service.terminateNetworkServiceInstance(request,csarId);
801 @Test(expected = VfcException.class)
802 public void terminateNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
803 HttpServletRequest request = mockRequest();
805 VfcService vfcService = mock(VfcService.class);
806 //when(vfcService.terminateNetworkServiceInstance(csarId,anyObject())).thenReturn(failedCall("VFC is not available!"));
807 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
808 service.terminateNetworkServiceInstance(request,csarId);
811 @Test(expected = VfcException.class)
812 public void terminateNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
813 HttpServletRequest request = mockRequest();
815 VfcService vfcService = mock(VfcService.class);
816 when(vfcService.terminateNetworkServiceInstance(csarId,anyObject())).thenReturn(emptyBodyCall());
817 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
818 service.terminateNetworkServiceInstance(request,csarId);
822 public void itCreateNetworkServiceData() throws IOException {
823 HttpServletRequest request = mockRequest();
824 ResponseBody result=null;
825 VfcService vfcService = mock(VfcService.class);
826 when(vfcService.createNetworkServiceData(anyObject())).thenReturn(successfulCall(result));
827 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
829 Assert.assertSame(result, service.createNetworkServiceData(request));
832 @Test(expected = VfcException.class)
833 public void createNetworkServiceDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
834 HttpServletRequest request = mockRequest();
835 VfcService vfcService = mock(VfcService.class);
836 when(vfcService.createNetworkServiceData(anyObject())).thenReturn(failedCall("VFC is not available!"));
837 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
838 service.createNetworkServiceData(request);
841 @Test(expected = VfcException.class)
842 public void createNetworkServiceDataWillThrowExceptionWhenVFCResponseError() throws IOException {
843 HttpServletRequest request = mockRequest();
844 VfcService vfcService = mock(VfcService.class);
845 when(vfcService.createNetworkServiceData(anyObject())).thenReturn(emptyBodyCall());
846 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
847 service.createNetworkServiceData(request);
851 public void itCreateVnfData() throws IOException {
852 HttpServletRequest request = mockRequest();
853 ResponseBody result=null;
854 VfcService vfcService = mock(VfcService.class);
855 when(vfcService.createVnfData(anyObject())).thenReturn(successfulCall(result));
856 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
858 Assert.assertSame(result, service.createVnfData(request));
861 @Test(expected = VfcException.class)
862 public void createVnfDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
863 HttpServletRequest request = mockRequest();
864 VfcService vfcService = mock(VfcService.class);
865 when(vfcService.createVnfData(anyObject())).thenReturn(failedCall("VFC is not available!"));
866 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
867 service.createVnfData(request);
870 @Test(expected = VfcException.class)
871 public void createVnfDataWillThrowExceptionWhenVFCResponseError() throws IOException {
872 HttpServletRequest request = mockRequest();
873 VfcService vfcService = mock(VfcService.class);
874 when(vfcService.createVnfData(anyObject())).thenReturn(emptyBodyCall());
875 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
876 service.createVnfData(request);
880 public void itCreatePnfData() throws IOException {
881 HttpServletRequest request = mockRequest();
882 ResponseBody result=null;
883 VfcService vfcService = mock(VfcService.class);
884 when(vfcService.createPnfData(anyObject())).thenReturn(successfulCall(result));
885 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
887 Assert.assertSame(result, service.createPnfData(request));
890 @Test(expected = VfcException.class)
891 public void createPnfDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
892 HttpServletRequest request = mockRequest();
893 VfcService vfcService = mock(VfcService.class);
894 when(vfcService.createPnfData(anyObject())).thenReturn(failedCall("VFC is not available!"));
895 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
896 service.createPnfData(request);
899 @Test(expected = VfcException.class)
900 public void createPnfDataWillThrowExceptionWhenVFCResponseError() throws IOException {
901 HttpServletRequest request = mockRequest();
902 VfcService vfcService = mock(VfcService.class);
903 when(vfcService.createPnfData(anyObject())).thenReturn(emptyBodyCall());
904 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
905 service.createPnfData(request);
909 public void itGetNsdInfo() throws IOException {
911 ResponseBody result=null;
912 VfcService vfcService = mock(VfcService.class);
913 when(vfcService.getNsdInfo(nsdId)).thenReturn(successfulCall(result));
914 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
916 Assert.assertSame(result, service.getNsdInfo(nsdId));
919 @Test(expected = VfcException.class)
920 public void getNsdInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
922 VfcService vfcService = mock(VfcService.class);
923 when(vfcService.getNsdInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
924 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
925 service.getNsdInfo(nsdId);
928 @Test(expected = VfcException.class)
929 public void getNsdInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
931 VfcService vfcService = mock(VfcService.class);
932 when(vfcService.getNsdInfo(nsdId)).thenReturn(emptyBodyCall());
933 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
934 service.getNsdInfo(nsdId);
938 public void itGetVnfInfo() throws IOException {
940 ResponseBody result=null;
941 VfcService vfcService = mock(VfcService.class);
942 when(vfcService.getVnfInfo(nsdId)).thenReturn(successfulCall(result));
943 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
945 Assert.assertSame(result, service.getVnfInfo(nsdId));
948 @Test(expected = VfcException.class)
949 public void getVnfInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
951 VfcService vfcService = mock(VfcService.class);
952 when(vfcService.getVnfInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
953 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
954 service.getVnfInfo(nsdId);
957 @Test(expected = VfcException.class)
958 public void getVnfInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
960 VfcService vfcService = mock(VfcService.class);
961 when(vfcService.getVnfInfo(nsdId)).thenReturn(emptyBodyCall());
962 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
963 service.getVnfInfo(nsdId);
967 public void itGetPnfInfo() throws IOException {
969 ResponseBody result=null;
970 VfcService vfcService = mock(VfcService.class);
971 when(vfcService.getPnfInfo(nsdId)).thenReturn(successfulCall(result));
972 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
974 Assert.assertSame(result, service.getPnfInfo(nsdId));
977 @Test(expected = VfcException.class)
978 public void getPnfInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
980 VfcService vfcService = mock(VfcService.class);
981 when(vfcService.getPnfInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
982 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
983 service.getPnfInfo(nsdId);
986 @Test(expected = VfcException.class)
987 public void getPnfInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
989 VfcService vfcService = mock(VfcService.class);
990 when(vfcService.getPnfInfo(nsdId)).thenReturn(emptyBodyCall());
991 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
992 service.getPnfInfo(nsdId);
996 public void itCanListNsTemplates() throws IOException {
997 ResponseBody result=null;
998 VfcService vfcService = mock(VfcService.class);
999 when(vfcService.listNsTemplates()).thenReturn(successfulCall(result));
1000 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1002 Assert.assertSame(result, service.listNsTemplates());
1005 @Test(expected = VfcException.class)
1006 public void listNsTemplatesWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
1007 VfcService vfcService = mock(VfcService.class);
1008 when(vfcService.listNsTemplates()).thenReturn(failedCall("VFC is not available!"));
1009 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1010 service.listNsTemplates();
1013 @Test(expected = VfcException.class)
1014 public void listNsTemplatesWillThrowExceptionWhenVFCResponseError() throws IOException {
1015 VfcService vfcService = mock(VfcService.class);
1016 when(vfcService.listNsTemplates()).thenReturn(emptyBodyCall());
1017 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1018 service.listNsTemplates();
1022 public void itCanGetVnfInfoById() throws IOException {
1024 ResponseBody result=null;
1025 VfcService vfcService = mock(VfcService.class);
1026 when(vfcService.getVnfInfoById(nsdId)).thenReturn(successfulCall(result));
1027 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1029 Assert.assertSame(result, service.getVnfInfoById(nsdId));
1032 @Test(expected = VfcException.class)
1033 public void getVnfInfoByIdWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
1035 VfcService vfcService = mock(VfcService.class);
1036 when(vfcService.getVnfInfoById(nsdId)).thenReturn(failedCall("VFC is not available!"));
1037 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1038 service.getVnfInfoById(nsdId);
1041 @Test(expected = VfcException.class)
1042 public void getVnfInfoByIdWillThrowExceptionWhenVFCResponseError() throws IOException {
1044 VfcService vfcService = mock(VfcService.class);
1045 when(vfcService.getVnfInfoById(nsdId)).thenReturn(emptyBodyCall());
1046 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1047 service.getVnfInfoById(nsdId);
1051 public void itCanFetchNsTemplateData() throws IOException {
1052 HttpServletRequest request = mockRequest();
1053 ResponseBody result=null;
1054 VfcService vfcService = mock(VfcService.class);
1055 when(vfcService.fetchNsTemplateData(anyObject())).thenReturn(successfulCall(result));
1056 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1058 Assert.assertSame(result, service.fetchNsTemplateData(request));
1061 @Test(expected = VfcException.class)
1062 public void fetchNsTemplateDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
1063 HttpServletRequest request = mockRequest();
1064 VfcService vfcService = mock(VfcService.class);
1065 when(vfcService.fetchNsTemplateData(anyObject())).thenReturn(failedCall("VFC is not available!"));
1066 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1067 service.fetchNsTemplateData(request);
1070 @Test(expected = VfcException.class)
1071 public void fetchNsTemplateDataWillThrowExceptionWhenVFCResponseError() throws IOException {
1072 HttpServletRequest request = mockRequest();
1073 VfcService vfcService = mock(VfcService.class);
1074 when(vfcService.fetchNsTemplateData(anyObject())).thenReturn(emptyBodyCall());
1075 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1076 service.fetchNsTemplateData(request);