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 JobStatus jobStatus = new JobStatus();
254 when(vfcService.getNsLcmJobStatus(jobId, responseId)).thenReturn(successfulCall(jobStatus));
255 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
257 Assert.assertSame(jobStatus, service.getNsLcmJobStatus(jobId, responseId));
260 @Test(expected = VfcException.class)
261 public void getNsLcmJobStatusWillThrowExceptionWhenVFCIsNotAvailable() {
262 VfcService vfcService = mock(VfcService.class);
264 String responseId = "1";
265 when(vfcService.getNsLcmJobStatus(jobId, responseId)).thenReturn(failedCall("VFC is not available!"));
266 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
267 service.getNsLcmJobStatus(jobId, responseId);
270 @Test(expected = VfcException.class)
271 public void getNsLcmJobStatusWillThrowExceptionWhenVFCResponseError() {
272 VfcService vfcService = mock(VfcService.class);
274 String responseId = "1";
275 when(vfcService.getNsLcmJobStatus(jobId, responseId)).thenReturn(emptyBodyCall());
276 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
277 service.getNsLcmJobStatus(jobId, responseId);
281 public void itCanDeleteNsPackage() {
283 DistributionResult result = new DistributionResult();
284 VfcService vfcService = mock(VfcService.class);
285 when(vfcService.deleteNsPackage(csarId)).thenReturn(successfulCall(result));
286 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
288 Assert.assertSame(result, service.deleteNsPackage(csarId));
291 @Test(expected = VfcException.class)
292 public void deleteNsPackageWillThrowExceptionWhenVFCIsNotAvailable() {
294 VfcService vfcService = mock(VfcService.class);
295 when(vfcService.deleteNsPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
296 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
297 service.deleteNsPackage(csarId);
300 @Test(expected = VfcException.class)
301 public void deleteNsPackageWillThrowExceptionWhenVFCResponseError() {
303 VfcService vfcService = mock(VfcService.class);
304 when(vfcService.deleteNsPackage(csarId)).thenReturn(emptyBodyCall());
305 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
306 service.deleteNsPackage(csarId);
310 public void itCanGetVnfPackages(){
311 ResponseBody result=null;
312 VfcService vfcService = mock(VfcService.class);
313 when(vfcService.getVnfPackages()).thenReturn(successfulCall(result));
314 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
316 Assert.assertSame(result, service.getVnfPackages());
320 public void getVnfPackagesThrowExceptionWhenVFCResponseError(){
322 VfcService vfcService = mock(VfcService.class);
323 when(vfcService.getVnfPackages ()).thenReturn(emptyBodyCall());
324 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
325 service.getVnfPackages();
329 public void getVnfPackagesThrowException(){
330 VfcService vfcService = mock(VfcService.class);
331 when(vfcService.getVnfPackages ()).thenReturn(failedCall("VFC is not available!"));
332 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
333 service.getVnfPackages();
337 public void itCanDeleteVFPackage() {
340 VfcService vfcService = mock(VfcService.class);
341 when(vfcService.deleteVnfPackage(csarId)).thenReturn(successfulCall(job));
342 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
344 Assert.assertSame(job, service.deleteVfPackage(csarId));
347 @Test(expected = VfcException.class)
348 public void deleteVfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
350 VfcService vfcService = mock(VfcService.class);
351 when(vfcService.deleteVnfPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
352 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
353 service.deleteVfPackage(csarId);
356 @Test(expected = VfcException.class)
357 public void deleteVnfPackageWillThrowExceptionWhenVFCResponseError() {
359 VfcService vfcService = mock(VfcService.class);
360 when(vfcService.deleteVnfPackage(csarId)).thenReturn(emptyBodyCall());
361 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
362 service.deleteVnfPackage(csarId);
366 public void itCanGetNetworkServicePackages() {
367 ResponseBody responseBody = null;
368 VfcService vfcService = mock(VfcService.class);
369 JobStatus jobStatus = new JobStatus();
370 when(vfcService.getNetworkServicePackages()).thenReturn(successfulCall(responseBody));
371 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
373 Assert.assertSame(jobStatus, service.getNetworkServicePackages());
376 @Test(expected = VfcException.class)
377 public void getNetworkServicePackagesWillThrowExceptionWhenVFCIsNotAvailable() {
378 VfcService vfcService = mock(VfcService.class);
379 when(vfcService.getNetworkServicePackages()).thenReturn(failedCall("VFC is not available!"));
380 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
381 service.getNetworkServicePackages();
384 @Test(expected = VfcException.class)
385 public void getNetworkServicePackagesWillThrowExceptionWhenVFCResponseError() {
386 VfcService vfcService = mock(VfcService.class);
387 when(vfcService.getNetworkServicePackages()).thenReturn(emptyBodyCall());
388 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
389 service.getNetworkServicePackages();
393 public void itCanGetPnfPackages(){
394 ResponseBody result=null;
395 VfcService vfcService = mock(VfcService.class);
396 when(vfcService.getPnfPackages()).thenReturn(successfulCall(result));
397 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
399 Assert.assertSame(result, service.getPnfPackages());
403 public void getPnfPackagesThrowExceptionWhenVFCResponseError(){
405 VfcService vfcService = mock(VfcService.class);
406 when(vfcService.getPnfPackages ()).thenReturn(emptyBodyCall());
407 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
408 service.getPnfPackages();
412 public void getPnfPackagesThrowException(){
413 VfcService vfcService = mock(VfcService.class);
414 when(vfcService.getPnfPackages ()).thenReturn(failedCall("VFC is not available!"));
415 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
416 service.getPnfPackages();
420 public void itDownLoadNsPackage(){
421 String nsdInfoId="1";
422 ResponseBody result=null;
423 VfcService vfcService = mock(VfcService.class);
424 when(vfcService.downLoadNsPackage(nsdInfoId)).thenReturn(successfulCall(result));
425 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
427 Assert.assertSame(result, service.downLoadNsPackage(nsdInfoId));
431 public void downLoadNsPackagehrowExceptionWhenVFCResponseError(){
432 String nsdInfoId="1";
433 VfcService vfcService = mock(VfcService.class);
434 when(vfcService.downLoadNsPackage (nsdInfoId)).thenReturn(emptyBodyCall());
435 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
436 service.downLoadNsPackage(nsdInfoId);
440 public void downLoadNsPackageThrowException(){
441 String nsdInfoId="1";
442 VfcService vfcService = mock(VfcService.class);
443 when(vfcService.downLoadNsPackage (nsdInfoId)).thenReturn(failedCall("VFC is not available!"));
444 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
445 service.downLoadNsPackage(nsdInfoId);
449 public void itDownLoadPnfPackage(){
450 String pnfInfoId="1";
451 ResponseBody result=null;
452 VfcService vfcService = mock(VfcService.class);
453 when(vfcService.downLoadPnfPackage(pnfInfoId)).thenReturn(successfulCall(result));
454 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
456 Assert.assertSame(result, service.downLoadPnfPackage(pnfInfoId));
460 public void downLoadPnfPackagehrowExceptionWhenVFCResponseError(){
461 String pnfInfoId="1";
462 VfcService vfcService = mock(VfcService.class);
463 when(vfcService.downLoadPnfPackage (pnfInfoId)).thenReturn(emptyBodyCall());
464 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
465 service.downLoadPnfPackage(pnfInfoId);
469 public void downLoadPnfPackageThrowException(){
470 String pnfInfoId="1";
471 VfcService vfcService = mock(VfcService.class);
472 when(vfcService.downLoadPnfPackage (pnfInfoId)).thenReturn(failedCall("VFC is not available!"));
473 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
474 service.downLoadPnfPackage(pnfInfoId);
478 public void itDownLoadVnfPackage(){
479 String vnfInfoId="1";
480 ResponseBody result=null;
481 VfcService vfcService = mock(VfcService.class);
482 when(vfcService.downLoadVnfPackage(vnfInfoId)).thenReturn(successfulCall(result));
483 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
485 Assert.assertSame(result, service.downLoadVnfPackage(vnfInfoId));
489 public void downLoadVnfPackagehrowExceptionWhenVFCResponseError(){
490 String vnfInfoId="1";
491 VfcService vfcService = mock(VfcService.class);
492 when(vfcService.downLoadVnfPackage (vnfInfoId)).thenReturn(emptyBodyCall());
493 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
494 service.downLoadVnfPackage(vnfInfoId);
498 public void downLoadVnfPackageThrowException(){
499 String vnfInfoId="1";
500 VfcService vfcService = mock(VfcService.class);
501 when(vfcService.downLoadVnfPackage (vnfInfoId)).thenReturn(failedCall("VFC is not available!"));
502 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
503 service.downLoadVnfPackage(vnfInfoId);
507 public void itCanDeleteNsdPackage() {
509 ResponseBody result=null;
510 VfcService vfcService = mock(VfcService.class);
511 when(vfcService.deleteNsdPackage(csarId)).thenReturn(successfulCall(result));
512 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
514 Assert.assertSame(result, service.deleteNsdPackage(csarId));
517 @Test(expected = VfcException.class)
518 public void deleteNsdPackageWillThrowExceptionWhenVFCIsNotAvailable() {
520 VfcService vfcService = mock(VfcService.class);
521 when(vfcService.deleteNsdPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
522 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
523 service.deleteNsdPackage(csarId);
526 @Test(expected = VfcException.class)
527 public void deleteNsdPackageWillThrowExceptionWhenVFCResponseError() {
529 VfcService vfcService = mock(VfcService.class);
530 when(vfcService.deleteNsdPackage(csarId)).thenReturn(emptyBodyCall());
531 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
532 service.deleteNsdPackage(csarId);
536 public void itCanDeleteVnfPackage() {
538 ResponseBody result=null;
540 VfcService vfcService = mock(VfcService.class);
541 when(vfcService.deleteVnfPackage(csarId)).thenReturn(successfulCall(job));
542 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
544 Assert.assertSame(job, service.deleteVnfPackage(csarId));
547 @Test(expected = VfcException.class)
548 public void deleteVnfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
550 VfcService vfcService = mock(VfcService.class);
551 when(vfcService.deleteVnfPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
552 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
553 service.deleteVnfPackage(csarId);
556 @Test(expected = VfcException.class)
557 public void deleteVnfNsdPackageWillThrowExceptionWhenVFCResponseError() {
559 VfcService vfcService = mock(VfcService.class);
560 when(vfcService.deleteVnfPackage(csarId)).thenReturn(emptyBodyCall());
561 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
562 service.deleteVnfPackage(csarId);
566 public void itCanDeletePnfdPackage() {
568 ResponseBody result=null;
570 VfcService vfcService = mock(VfcService.class);
571 when(vfcService.deletePnfdPackage(csarId)).thenReturn(successfulCall(result));
572 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
574 Assert.assertSame(result, service.deletePnfPackage(csarId));
577 @Test(expected = VfcException.class)
578 public void deletePnfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
580 VfcService vfcService = mock(VfcService.class);
581 when(vfcService.deletePnfdPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
582 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
583 service.deletePnfPackage(csarId);
586 @Test(expected = VfcException.class)
587 public void deletePnfPackageWillThrowExceptionWhenVFCResponseError() {
589 VfcService vfcService = mock(VfcService.class);
590 when(vfcService.deletePnfdPackage(csarId)).thenReturn(emptyBodyCall());
591 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
592 service.deletePnfPackage(csarId);
596 public void itCanDeleteNetworkServiceInstance() {
598 ResponseBody result=null;
600 VfcService vfcService = mock(VfcService.class);
601 when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(successfulCall(result));
602 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
604 Assert.assertSame(result, service.deleteNetworkServiceInstance(csarId));
607 @Test(expected = VfcException.class)
608 public void deleteNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() {
610 VfcService vfcService = mock(VfcService.class);
611 when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(failedCall("VFC is not available!"));
612 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
613 service.deleteNetworkServiceInstance(csarId);
616 @Test(expected = VfcException.class)
617 public void deleteNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() {
619 VfcService vfcService = mock(VfcService.class);
620 when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(emptyBodyCall());
621 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
622 service.deleteNetworkServiceInstance(csarId);
626 public void itCanCreateNetworkServiceInstance() throws IOException {
627 HttpServletRequest request = mockRequest();
628 ResponseBody result=null;
629 VfcService vfcService = mock(VfcService.class);
630 when(vfcService.createNetworkServiceInstance(anyObject())).thenReturn(successfulCall(result));
631 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
633 Assert.assertSame(result, service.createNetworkServiceInstance(request));
636 @Test(expected = VfcException.class)
637 public void createNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
638 HttpServletRequest request = mockRequest();
639 VfcService vfcService = mock(VfcService.class);
640 when(vfcService.createNetworkServiceInstance(anyObject())).thenReturn(failedCall("VFC is not available!"));
641 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
642 service.createNetworkServiceInstance(request);
645 @Test(expected = VfcException.class)
646 public void createNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
647 HttpServletRequest request = mockRequest();
648 VfcService vfcService = mock(VfcService.class);
649 when(vfcService.createNetworkServiceInstance(anyObject())).thenReturn(emptyBodyCall());
650 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
651 service.createNetworkServiceInstance(request);
655 public void itCanGetNetworkServiceInfo() throws IOException {
656 ResponseBody result=null;
657 nsServiceRsp ns = new nsServiceRsp();
658 VfcService vfcService = mock(VfcService.class);
659 when(vfcService.getNetworkServiceInfo()).thenReturn(successfulCall(ns));
660 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
662 Assert.assertSame(result, service.getNetworkServiceInfo());
665 @Test(expected = VfcException.class)
666 public void getNetworkServiceInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
667 VfcService vfcService = mock(VfcService.class);
668 when(vfcService.getNetworkServiceInfo()).thenReturn(failedCall("VFC is not available!"));
669 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
670 service.getNetworkServiceInfo();
673 @Test(expected = VfcException.class)
674 public void getNetworkServiceInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
675 VfcService vfcService = mock(VfcService.class);
676 when(vfcService.getNetworkServiceInfo()).thenReturn(emptyBodyCall());
677 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
678 service.getNetworkServiceInfo();
684 public void itCanHealNetworkServiceInstance() throws IOException {
685 HttpServletRequest request = mockRequest();
687 ResponseBody result=null;
688 VfcService vfcService = mock(VfcService.class);
689 //when(vfcService.healNetworkServiceInstance(csarId,anyObject())).thenReturn(successfulCall(result));
690 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
692 //Assert.assertSame(result, service.healNetworkServiceInstance(request,csarId));
693 service.healNetworkServiceInstance(request,csarId);
696 @Test(expected = VfcException.class)
697 public void healNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
698 HttpServletRequest request = mockRequest();
700 VfcService vfcService = mock(VfcService.class);
701 when(vfcService.healNetworkServiceInstance(csarId,anyObject())).thenReturn(failedCall("VFC is not available!"));
702 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
703 service.healNetworkServiceInstance(request,csarId);
706 @Test(expected = VfcException.class)
707 public void healNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
708 HttpServletRequest request = mockRequest();
710 VfcService vfcService = mock(VfcService.class);
711 when(vfcService.healNetworkServiceInstance(csarId,anyObject())).thenReturn(emptyBodyCall());
712 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
713 service.healNetworkServiceInstance(request,csarId);
717 public void itCanScaleNetworkServiceInstance() throws IOException {
718 HttpServletRequest request = mockRequest();
720 ResponseBody result=null;
721 VfcService vfcService = mock(VfcService.class);
722 //when(vfcService.scaleNetworkServiceInstance(csarId,anyObject())).thenReturn(successfulCall(result));
723 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
725 Assert.assertSame(result, service.scaleNetworkServiceInstance(request,csarId));
728 @Test(expected = VfcException.class)
729 public void scaleNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
730 HttpServletRequest request = mockRequest();
732 VfcService vfcService = mock(VfcService.class);
733 when(vfcService.scaleNetworkServiceInstance(csarId,anyObject())).thenReturn(failedCall("VFC is not available!"));
734 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
735 service.scaleNetworkServiceInstance(request,csarId);
738 @Test(expected = VfcException.class)
739 public void scaleNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
740 HttpServletRequest request = mockRequest();
742 VfcService vfcService = mock(VfcService.class);
743 when(vfcService.scaleNetworkServiceInstance(csarId,anyObject())).thenReturn(emptyBodyCall());
744 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
745 service.scaleNetworkServiceInstance(request,csarId);
750 public void itCaninstantiateNetworkServiceInstance() throws IOException {
751 HttpServletRequest request = mockRequest();
752 String serviceInstanceId="1";
753 ResponseBody result=null;
754 VfcService vfcService = mock(VfcService.class);
755 //when(vfcService.instantiateNetworkServiceInstance(anyObject(),serviceInstanceId)).thenReturn(successfulCall(result));
756 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
758 service.instantiateNetworkServiceInstance(request,serviceInstanceId);
761 @Test(expected = VfcException.class)
762 public void instantiateNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
763 HttpServletRequest request = mockRequest();
764 String serviceInstanceId="1";
765 VfcService vfcService = mock(VfcService.class);
766 when(vfcService.instantiateNetworkServiceInstance(anyObject(),serviceInstanceId)).thenReturn(failedCall("VFC is not available!"));
767 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
768 service.instantiateNetworkServiceInstance(request,serviceInstanceId);
771 @Test(expected = VfcException.class)
772 public void instantiateNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
773 HttpServletRequest request = mockRequest();
774 String serviceInstanceId="1";
775 VfcService vfcService = mock(VfcService.class);
776 when(vfcService.instantiateNetworkServiceInstance(anyObject(),serviceInstanceId)).thenReturn(emptyBodyCall());
777 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
778 service.instantiateNetworkServiceInstance(request,serviceInstanceId);
783 public void itCanTerminateNetworkServiceInstance() throws IOException {
784 HttpServletRequest request = mockRequest();
786 ResponseBody result=null;
788 VfcService vfcService = mock(VfcService.class);
789 when(vfcService.terminateNetworkServiceInstance(csarId,anyObject())).thenReturn(successfulCall(result));
790 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
792 service.terminateNetworkServiceInstance(request,csarId);
795 @Test(expected = VfcException.class)
796 public void terminateNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
797 HttpServletRequest request = mockRequest();
799 VfcService vfcService = mock(VfcService.class);
800 //when(vfcService.terminateNetworkServiceInstance(csarId,anyObject())).thenReturn(failedCall("VFC is not available!"));
801 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
802 service.terminateNetworkServiceInstance(request,csarId);
805 @Test(expected = VfcException.class)
806 public void terminateNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
807 HttpServletRequest request = mockRequest();
809 VfcService vfcService = mock(VfcService.class);
810 when(vfcService.terminateNetworkServiceInstance(csarId,anyObject())).thenReturn(emptyBodyCall());
811 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
812 service.terminateNetworkServiceInstance(request,csarId);
816 public void itCreateNetworkServiceData() throws IOException {
817 HttpServletRequest request = mockRequest();
818 ResponseBody result=null;
819 VfcService vfcService = mock(VfcService.class);
820 when(vfcService.createNetworkServiceData(anyObject())).thenReturn(successfulCall(result));
821 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
823 Assert.assertSame(result, service.createNetworkServiceData(request));
826 @Test(expected = VfcException.class)
827 public void createNetworkServiceDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
828 HttpServletRequest request = mockRequest();
829 VfcService vfcService = mock(VfcService.class);
830 when(vfcService.createNetworkServiceData(anyObject())).thenReturn(failedCall("VFC is not available!"));
831 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
832 service.createNetworkServiceData(request);
835 @Test(expected = VfcException.class)
836 public void createNetworkServiceDataWillThrowExceptionWhenVFCResponseError() throws IOException {
837 HttpServletRequest request = mockRequest();
838 VfcService vfcService = mock(VfcService.class);
839 when(vfcService.createNetworkServiceData(anyObject())).thenReturn(emptyBodyCall());
840 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
841 service.createNetworkServiceData(request);
845 public void itCreateVnfData() throws IOException {
846 HttpServletRequest request = mockRequest();
847 ResponseBody result=null;
848 VfcService vfcService = mock(VfcService.class);
849 when(vfcService.createVnfData(anyObject())).thenReturn(successfulCall(result));
850 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
852 Assert.assertSame(result, service.createVnfData(request));
855 @Test(expected = VfcException.class)
856 public void createVnfDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
857 HttpServletRequest request = mockRequest();
858 VfcService vfcService = mock(VfcService.class);
859 when(vfcService.createVnfData(anyObject())).thenReturn(failedCall("VFC is not available!"));
860 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
861 service.createVnfData(request);
864 @Test(expected = VfcException.class)
865 public void createVnfDataWillThrowExceptionWhenVFCResponseError() throws IOException {
866 HttpServletRequest request = mockRequest();
867 VfcService vfcService = mock(VfcService.class);
868 when(vfcService.createVnfData(anyObject())).thenReturn(emptyBodyCall());
869 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
870 service.createVnfData(request);
874 public void itCreatePnfData() throws IOException {
875 HttpServletRequest request = mockRequest();
876 ResponseBody result=null;
877 VfcService vfcService = mock(VfcService.class);
878 when(vfcService.createPnfData(anyObject())).thenReturn(successfulCall(result));
879 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
881 Assert.assertSame(result, service.createPnfData(request));
884 @Test(expected = VfcException.class)
885 public void createPnfDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
886 HttpServletRequest request = mockRequest();
887 VfcService vfcService = mock(VfcService.class);
888 when(vfcService.createPnfData(anyObject())).thenReturn(failedCall("VFC is not available!"));
889 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
890 service.createPnfData(request);
893 @Test(expected = VfcException.class)
894 public void createPnfDataWillThrowExceptionWhenVFCResponseError() throws IOException {
895 HttpServletRequest request = mockRequest();
896 VfcService vfcService = mock(VfcService.class);
897 when(vfcService.createPnfData(anyObject())).thenReturn(emptyBodyCall());
898 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
899 service.createPnfData(request);
903 public void itGetNsdInfo() throws IOException {
905 ResponseBody result=null;
906 VfcService vfcService = mock(VfcService.class);
907 when(vfcService.getNsdInfo(nsdId)).thenReturn(successfulCall(result));
908 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
910 Assert.assertSame(result, service.getNsdInfo(nsdId));
913 @Test(expected = VfcException.class)
914 public void getNsdInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
916 VfcService vfcService = mock(VfcService.class);
917 when(vfcService.getNsdInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
918 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
919 service.getNsdInfo(nsdId);
922 @Test(expected = VfcException.class)
923 public void getNsdInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
925 VfcService vfcService = mock(VfcService.class);
926 when(vfcService.getNsdInfo(nsdId)).thenReturn(emptyBodyCall());
927 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
928 service.getNsdInfo(nsdId);
932 public void itGetVnfInfo() throws IOException {
934 ResponseBody result=null;
935 VfcService vfcService = mock(VfcService.class);
936 when(vfcService.getVnfInfo(nsdId)).thenReturn(successfulCall(result));
937 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
939 Assert.assertSame(result, service.getVnfInfo(nsdId));
942 @Test(expected = VfcException.class)
943 public void getVnfInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
945 VfcService vfcService = mock(VfcService.class);
946 when(vfcService.getVnfInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
947 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
948 service.getVnfInfo(nsdId);
951 @Test(expected = VfcException.class)
952 public void getVnfInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
954 VfcService vfcService = mock(VfcService.class);
955 when(vfcService.getVnfInfo(nsdId)).thenReturn(emptyBodyCall());
956 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
957 service.getVnfInfo(nsdId);
961 public void itGetPnfInfo() throws IOException {
963 ResponseBody result=null;
964 VfcService vfcService = mock(VfcService.class);
965 when(vfcService.getPnfInfo(nsdId)).thenReturn(successfulCall(result));
966 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
968 Assert.assertSame(result, service.getPnfInfo(nsdId));
971 @Test(expected = VfcException.class)
972 public void getPnfInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
974 VfcService vfcService = mock(VfcService.class);
975 when(vfcService.getPnfInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
976 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
977 service.getPnfInfo(nsdId);
980 @Test(expected = VfcException.class)
981 public void getPnfInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
983 VfcService vfcService = mock(VfcService.class);
984 when(vfcService.getPnfInfo(nsdId)).thenReturn(emptyBodyCall());
985 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
986 service.getPnfInfo(nsdId);
990 public void itCanListNsTemplates() throws IOException {
991 ResponseBody result=null;
992 VfcService vfcService = mock(VfcService.class);
993 when(vfcService.listNsTemplates()).thenReturn(successfulCall(result));
994 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
996 Assert.assertSame(result, service.listNsTemplates());
999 @Test(expected = VfcException.class)
1000 public void listNsTemplatesWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
1001 VfcService vfcService = mock(VfcService.class);
1002 when(vfcService.listNsTemplates()).thenReturn(failedCall("VFC is not available!"));
1003 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1004 service.listNsTemplates();
1007 @Test(expected = VfcException.class)
1008 public void listNsTemplatesWillThrowExceptionWhenVFCResponseError() throws IOException {
1009 VfcService vfcService = mock(VfcService.class);
1010 when(vfcService.listNsTemplates()).thenReturn(emptyBodyCall());
1011 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1012 service.listNsTemplates();
1016 public void itCanGetVnfInfoById() throws IOException {
1018 ResponseBody result=null;
1019 VfcService vfcService = mock(VfcService.class);
1020 when(vfcService.getVnfInfoById(nsdId)).thenReturn(successfulCall(result));
1021 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1023 Assert.assertSame(result, service.getVnfInfoById(nsdId));
1026 @Test(expected = VfcException.class)
1027 public void getVnfInfoByIdWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
1029 VfcService vfcService = mock(VfcService.class);
1030 when(vfcService.getVnfInfoById(nsdId)).thenReturn(failedCall("VFC is not available!"));
1031 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1032 service.getVnfInfoById(nsdId);
1035 @Test(expected = VfcException.class)
1036 public void getVnfInfoByIdWillThrowExceptionWhenVFCResponseError() throws IOException {
1038 VfcService vfcService = mock(VfcService.class);
1039 when(vfcService.getVnfInfoById(nsdId)).thenReturn(emptyBodyCall());
1040 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1041 service.getVnfInfoById(nsdId);
1045 public void itCanFetchNsTemplateData() throws IOException {
1046 HttpServletRequest request = mockRequest();
1047 ResponseBody result=null;
1048 VfcService vfcService = mock(VfcService.class);
1049 when(vfcService.fetchNsTemplateData(anyObject())).thenReturn(successfulCall(result));
1050 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1052 Assert.assertSame(result, service.fetchNsTemplateData(request));
1055 @Test(expected = VfcException.class)
1056 public void fetchNsTemplateDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
1057 HttpServletRequest request = mockRequest();
1058 VfcService vfcService = mock(VfcService.class);
1059 when(vfcService.fetchNsTemplateData(anyObject())).thenReturn(failedCall("VFC is not available!"));
1060 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1061 service.fetchNsTemplateData(request);
1064 @Test(expected = VfcException.class)
1065 public void fetchNsTemplateDataWillThrowExceptionWhenVFCResponseError() throws IOException {
1066 HttpServletRequest request = mockRequest();
1067 VfcService vfcService = mock(VfcService.class);
1068 when(vfcService.fetchNsTemplateData(anyObject())).thenReturn(emptyBodyCall());
1069 PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1070 service.fetchNsTemplateData(request);