Upgrade java 17
[usecase-ui/server.git] / server / src / test / java / org / onap / usecaseui / server / service / lcm / impl / DefaultPackageDistributionServiceTest.java
1 /**
2  * Copyright 2016-2017 ZTE Corporation.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onap.usecaseui.server.service.lcm.impl;
17
18 import org.apache.commons.lang3.StringUtils;
19 import org.junit.Assert;
20 import org.junit.Test;
21 import org.mockito.Mockito;
22 import org.onap.usecaseui.server.bean.ServiceBean;
23 import org.onap.usecaseui.server.bean.lcm.VfNsPackageInfo;
24 import org.onap.usecaseui.server.service.lcm.PackageDistributionService;
25 import org.onap.usecaseui.server.service.lcm.ServiceLcmService;
26 import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService;
27 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.VimInfo;
28 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.VimInfoRsp;
29 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.nsServiceRsp;
30 import org.onap.usecaseui.server.service.lcm.domain.sdc.SDCCatalogService;
31 import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.SDCServiceTemplate;
32 import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.Vnf;
33 import org.onap.usecaseui.server.service.lcm.domain.sdc.exceptions.SDCCatalogException;
34 import org.onap.usecaseui.server.service.lcm.domain.vfc.VfcService;
35 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Csar;
36 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.DistributionResult;
37 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Job;
38 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.JobStatus;
39 import org.onap.usecaseui.server.service.lcm.domain.vfc.exceptions.VfcException;
40
41 import okhttp3.ResponseBody;
42 import retrofit2.Call;
43
44 import java.io.IOException;
45 import java.util.ArrayList;
46 import java.util.Collections;
47 import java.util.List;
48
49 import jakarta.servlet.ReadListener;
50 import jakarta.servlet.ServletInputStream;
51 import jakarta.servlet.http.HttpServletRequest;
52
53 import static org.hamcrest.CoreMatchers.equalTo;
54 import static org.mockito.ArgumentMatchers.eq;
55 import static org.mockito.Mockito.mock;
56 import static org.mockito.Mockito.when;
57 import static org.onap.usecaseui.server.service.lcm.domain.sdc.consts.SDCConsts.*;
58 import static org.onap.usecaseui.server.util.CallStub.emptyBodyCall;
59 import static org.onap.usecaseui.server.util.CallStub.failedCall;
60 import static org.onap.usecaseui.server.util.CallStub.successfulCall;
61
62 public class DefaultPackageDistributionServiceTest {
63         
64         
65     private HttpServletRequest mockRequest() throws IOException {
66         HttpServletRequest request = mock(HttpServletRequest.class);
67         when(request.getContentLength()).thenReturn(0);
68         ServletInputStream inStream = new ServletInputStream() {
69             @Override
70             public boolean isFinished() {
71                 return false;
72             }
73
74             @Override
75             public boolean isReady() {
76                 return false;
77             }
78
79             @Override
80             public void setReadListener(ReadListener readListener) {
81
82             }
83
84             @Override
85             public int read() throws IOException {
86                 return 0;
87             }
88         };
89         when(request.getInputStream()).thenReturn(inStream);
90         return request;
91     }
92
93     @Test
94     public void itCanRetrievePackageFromSDCAndAAI() {
95         List<SDCServiceTemplate> serviceTemplate = Collections.singletonList(new SDCServiceTemplate("1", "1", "service", "V1","", ""));
96         Vnf o = new Vnf();
97         o.setInvariantUUID("2");
98         o.setUuid("2");
99         o.setName("vnf");
100         List<Vnf> vnf = Collections.singletonList(o);
101         SDCCatalogService sdcService = newSDCService(serviceTemplate, vnf);
102
103         List<VimInfo> vim = Collections.singletonList(new VimInfo("owner", "regionId"));
104         AAIService aaiService = newAAIService(vim);
105
106         PackageDistributionService service = new DefaultPackageDistributionService(sdcService, null);
107
108         Assert.assertThat(service.retrievePackageInfo(), equalTo(new VfNsPackageInfo(serviceTemplate, vnf)));
109     }
110
111     private AAIService newAAIService(List<VimInfo> vim) {
112         AAIService aaiService = mock(AAIService.class);
113         VimInfoRsp rsp = new VimInfoRsp();
114         rsp.setCloudRegion(vim);
115         Call<VimInfoRsp> vimCall = successfulCall(rsp);
116         when(aaiService.listVimInfo()).thenReturn(vimCall);
117         return aaiService;
118     }
119
120     private SDCCatalogService newSDCService(List<SDCServiceTemplate> serviceTemplate, List<Vnf> vnf) {
121         SDCCatalogService sdcService = mock(SDCCatalogService.class);
122
123         Call<List<SDCServiceTemplate>> serviceCall = successfulCall(serviceTemplate);
124         when(sdcService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(serviceCall);
125
126         Call<List<Vnf>> vnfCall = successfulCall(vnf);
127         when(sdcService.listResources(RESOURCETYPE_VF)).thenReturn(vnfCall);
128         return sdcService;
129     }
130
131     @Test
132     public void retrievePackageWillThrowExceptionWhenSDCIsNotAvailable() {
133         SDCCatalogService sdcService = mock(SDCCatalogService.class);
134         Call<List<Vnf>> serviceCall = failedCall("SDC is not available!");
135         Call<List<SDCServiceTemplate>> serviceCall1 = failedCall("SDC is not available!");
136         when(sdcService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(serviceCall1);
137         when(sdcService.listResources(RESOURCETYPE_VF)).thenReturn(serviceCall);
138
139         List<VimInfo> vim = Collections.singletonList(new VimInfo("owner", "regionId"));
140         AAIService aaiService = newAAIService(vim);
141
142         PackageDistributionService service = new DefaultPackageDistributionService(sdcService, null);
143         service.retrievePackageInfo();
144     }
145
146     @Test
147     public void retrievePackageWillBeEmptyWhenNoNsServiceAndVfInSDC() {
148         SDCCatalogService sdcService = mock(SDCCatalogService.class);
149         Call<List<SDCServiceTemplate>> serviceCall = emptyBodyCall();
150         when(sdcService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(serviceCall);
151
152         Call<List<Vnf>> resourceCall = emptyBodyCall();
153         when(sdcService.listResources(RESOURCETYPE_VF)).thenReturn(resourceCall);
154
155         PackageDistributionService service = new DefaultPackageDistributionService(sdcService, null);
156         VfNsPackageInfo vfNsPackageInfo = service.retrievePackageInfo();
157
158         Assert.assertTrue("ns should be empty!", vfNsPackageInfo.getNsPackage().isEmpty());
159         Assert.assertTrue("vf should be empty!", vfNsPackageInfo.getVnfPackages().isEmpty());
160     }
161
162     @Test
163     public void itCanPostNsPackageToVFC() {
164         VfcService vfcService = mock(VfcService.class);
165         Csar csar = new Csar();
166         DistributionResult result = new DistributionResult();
167         result.setStatus("status");
168         result.setStatusDescription("description");
169         result.setErrorCode("errorcode");
170         when(vfcService.distributeNsPackage(csar)).thenReturn(successfulCall(result));
171         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
172
173         Assert.assertSame(result, service.postNsPackage(csar));
174     }
175
176     @Test(expected = VfcException.class)
177     public void postNsPackageWillThrowExceptionWhenVFCIsNotAvailable() {
178         VfcService vfcService = mock(VfcService.class);
179         Csar csar = new Csar();
180         when(vfcService.distributeNsPackage(csar)).thenReturn(failedCall("VFC is not available!"));
181         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
182         service.postNsPackage(csar);
183     }
184
185     @Test(expected = VfcException.class)
186     public void postNsPackageWillThrowExceptionWhenVFCResponseError() {
187         VfcService vfcService = mock(VfcService.class);
188         Csar csar = new Csar();
189         when(vfcService.distributeNsPackage(csar)).thenReturn(emptyBodyCall());
190         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
191         service.postNsPackage(csar);
192     }
193
194     @Test
195     public void itCanPostVnfPackageToVFC() {
196         VfcService vfcService = mock(VfcService.class);
197         Csar csar = new Csar();
198         Job job = new Job();
199         when(vfcService.distributeVnfPackage(csar)).thenReturn(successfulCall(job));
200         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
201
202         Assert.assertSame(job, service.postVfPackage(csar));
203     }
204
205     @Test(expected = VfcException.class)
206     public void postVnfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
207         VfcService vfcService = mock(VfcService.class);
208         Csar csar = new Csar();
209         when(vfcService.distributeVnfPackage(csar)).thenReturn(failedCall("VFC is not available!"));
210         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
211         service.postVfPackage(csar);
212     }
213
214     @Test(expected = VfcException.class)
215     public void postVnfPackageWillThrowExceptionWhenVFCResponseError() {
216         VfcService vfcService = mock(VfcService.class);
217         Csar csar = new Csar();
218         when(vfcService.distributeVnfPackage(csar)).thenReturn(emptyBodyCall());
219         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
220         service.postVfPackage(csar);
221     }
222
223     @Test
224     public void itCanGetJobStatusFromVFC() {
225         VfcService vfcService = mock(VfcService.class);
226         String jobId = "1";
227         String responseId = "1";
228         JobStatus jobStatus = new JobStatus();
229         when(vfcService.getJobStatus(jobId, responseId)).thenReturn(successfulCall(jobStatus));
230         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
231
232         Assert.assertSame(jobStatus, service.getJobStatus(jobId, responseId));
233     }
234
235     @Test(expected = VfcException.class)
236     public void getJobStatusWillThrowExceptionWhenVFCIsNotAvailable() {
237         VfcService vfcService = mock(VfcService.class);
238         String jobId = "1";
239         String responseId = "1";
240         when(vfcService.getJobStatus(jobId, responseId)).thenReturn(failedCall("VFC is not available!"));
241         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
242         service.getJobStatus(jobId, responseId);
243     }
244
245     @Test(expected = VfcException.class)
246     public void getJobStatusWillThrowExceptionWhenVFCResponseError() {
247         VfcService vfcService = mock(VfcService.class);
248         String jobId = "1";
249         String responseId = "1";
250         when(vfcService.getJobStatus(jobId, responseId)).thenReturn(emptyBodyCall());
251         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
252         service.getJobStatus(jobId, responseId);
253     }
254
255     @Test
256     public void itCanGetNsLcmJobStatusFromVFC() {
257         VfcService vfcService = mock(VfcService.class);
258         String jobId = "1";
259         String responseId = "1";
260         String serviceId= "1";
261         String operationType= "1";
262         JobStatus jobStatus = new JobStatus();
263         when(vfcService.getNsLcmJobStatus(jobId, responseId)).thenReturn(successfulCall(jobStatus));
264         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
265
266         Assert.assertSame(jobStatus, service.getNsLcmJobStatus(serviceId,jobId, responseId,operationType));
267     }
268
269     @Test(expected = VfcException.class)
270     public void getNsLcmJobStatusWillThrowExceptionWhenVFCIsNotAvailable() {
271         VfcService vfcService = mock(VfcService.class);
272         String jobId = "1";
273         String responseId = "1";
274         String serviceId= "1";
275         String operationType= "1";
276         when(vfcService.getNsLcmJobStatus(jobId, responseId)).thenReturn(failedCall("VFC is not available!"));
277         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
278         service.getNsLcmJobStatus(serviceId,jobId, responseId,operationType);
279     }
280
281     @Test(expected = VfcException.class)
282     public void getNsLcmJobStatusWillThrowExceptionWhenVFCResponseError() {
283         VfcService vfcService = mock(VfcService.class);
284         String jobId = "1";
285         String responseId = "1";
286         String serviceId= "1";
287         String operationType= "1";
288         when(vfcService.getNsLcmJobStatus(jobId, responseId)).thenReturn(emptyBodyCall());
289         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
290         service.getNsLcmJobStatus(serviceId,jobId, responseId,operationType);
291     }
292     
293     @Test
294     public void itCanDeleteNsPackage() {
295         String csarId = "1";
296         DistributionResult result = new DistributionResult();
297         VfcService vfcService = mock(VfcService.class);
298         when(vfcService.deleteNsPackage(csarId)).thenReturn(successfulCall(result));
299         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
300
301         Assert.assertSame(result, service.deleteNsPackage(csarId));
302     }
303
304     @Test(expected = VfcException.class)
305     public void deleteNsPackageWillThrowExceptionWhenVFCIsNotAvailable() {
306         String csarId = "1";
307         VfcService vfcService = mock(VfcService.class);
308         when(vfcService.deleteNsPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
309         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
310         service.deleteNsPackage(csarId);
311     }
312
313     @Test(expected = VfcException.class)
314     public void deleteNsPackageWillThrowExceptionWhenVFCResponseError() {
315         String csarId = "1";
316         VfcService vfcService = mock(VfcService.class);
317         when(vfcService.deleteNsPackage(csarId)).thenReturn(emptyBodyCall());
318         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
319         service.deleteNsPackage(csarId);
320     }
321     
322     @Test
323     public void itCanGetVnfPackages(){
324         ResponseBody result=null;
325         VfcService vfcService = mock(VfcService.class);
326         when(vfcService.getVnfPackages()).thenReturn(successfulCall(result));
327         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
328
329         Assert.assertSame(result, service.getVnfPackages());
330     }
331     
332     @Test
333     public void getVnfPackagesThrowExceptionWhenVFCResponseError(){
334         
335         VfcService vfcService = mock(VfcService.class);
336         when(vfcService.getVnfPackages ()).thenReturn(emptyBodyCall());
337         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
338         service.getVnfPackages();
339     }
340     
341     @Test
342     public void getVnfPackagesThrowException(){
343         VfcService vfcService = mock(VfcService.class);
344         when(vfcService.getVnfPackages ()).thenReturn(failedCall("VFC is not available!"));
345         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
346         service.getVnfPackages();
347     }
348     
349     @Test
350     public void itCanDeleteVFPackage() {
351         String csarId = "1";
352         Job job = new Job();
353         VfcService vfcService = mock(VfcService.class);
354         when(vfcService.deleteVnfPackage(csarId)).thenReturn(successfulCall(job));
355         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
356
357         Assert.assertSame(job, service.deleteVfPackage(csarId));
358     }
359
360     @Test(expected = VfcException.class)
361     public void deleteVfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
362         String csarId = "1";
363         VfcService vfcService = mock(VfcService.class);
364         when(vfcService.deleteVnfPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
365         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
366         service.deleteVfPackage(csarId);
367     }
368
369     @Test(expected = VfcException.class)
370     public void deleteVnfPackageWillThrowExceptionWhenVFCResponseError() {
371         String csarId = "1";
372         VfcService vfcService = mock(VfcService.class);
373         when(vfcService.deleteVnfPackage(csarId)).thenReturn(emptyBodyCall());
374         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
375         service.deleteVnfPackage(csarId);
376     }
377     
378     @Test
379     public void itCanGetNetworkServicePackages() {
380         ResponseBody responseBody = null;
381         VfcService vfcService = mock(VfcService.class);
382         JobStatus jobStatus = new JobStatus();
383         when(vfcService.getNetworkServicePackages()).thenReturn(successfulCall(responseBody));
384         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
385
386         Assert.assertSame(jobStatus, service.getNetworkServicePackages());
387     }
388
389     @Test
390     public void getNetworkServicePackagesWillThrowExceptionWhenVFCIsNotAvailable() {
391         VfcService vfcService = mock(VfcService.class);
392         when(vfcService.getNetworkServicePackages()).thenReturn(failedCall("VFC is not available!"));
393         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
394         service.getNetworkServicePackages();
395     }
396
397     @Test
398     public void getNetworkServicePackagesWillThrowExceptionWhenVFCResponseError() {
399         VfcService vfcService = mock(VfcService.class);
400         when(vfcService.getNetworkServicePackages()).thenReturn(emptyBodyCall());
401         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
402         service.getNetworkServicePackages();
403     }
404     
405     @Test
406     public void itCanGetPnfPackages(){
407         ResponseBody result=null;
408         VfcService vfcService = mock(VfcService.class);
409         when(vfcService.getPnfPackages()).thenReturn(successfulCall(result));
410         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
411
412         Assert.assertSame(result, service.getPnfPackages());
413     }
414     
415     @Test
416     public void getPnfPackagesThrowExceptionWhenVFCResponseError(){
417         
418         VfcService vfcService = mock(VfcService.class);
419         when(vfcService.getPnfPackages ()).thenReturn(emptyBodyCall());
420         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
421         service.getPnfPackages();
422     }
423     
424     @Test
425     public void getPnfPackagesThrowException(){
426         VfcService vfcService = mock(VfcService.class);
427         when(vfcService.getPnfPackages ()).thenReturn(failedCall("VFC is not available!"));
428         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
429         service.getPnfPackages();
430     }
431     
432     @Test
433     public void itDownLoadNsPackage(){
434         String nsdInfoId="1";
435         ResponseBody result=null;
436         VfcService vfcService = mock(VfcService.class);
437         when(vfcService.downLoadNsPackage(nsdInfoId)).thenReturn(successfulCall(result));
438         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
439
440         Assert.assertTrue(StringUtils.isNotEmpty(service.downLoadNsPackage(nsdInfoId)));
441     }
442     
443     @Test
444     public void downLoadNsPackagehrowExceptionWhenVFCResponseError(){
445         String nsdInfoId="1";
446         VfcService vfcService = mock(VfcService.class);
447         when(vfcService.downLoadNsPackage (nsdInfoId)).thenReturn(emptyBodyCall());
448         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
449         service.downLoadNsPackage(nsdInfoId);
450     }
451     
452     @Test
453     public void downLoadNsPackageThrowException(){
454         String nsdInfoId="1";
455         VfcService vfcService = mock(VfcService.class);
456         when(vfcService.downLoadNsPackage (nsdInfoId)).thenReturn(failedCall("VFC is not available!"));
457         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
458         service.downLoadNsPackage(nsdInfoId);
459     }
460     
461     @Test
462     public void itDownLoadPnfPackage(){
463         String pnfInfoId="1";
464         ResponseBody result=null;
465         VfcService vfcService = mock(VfcService.class);
466         when(vfcService.downLoadPnfPackage(pnfInfoId)).thenReturn(successfulCall(result));
467         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
468
469         Assert.assertSame(result, service.downLoadPnfPackage(pnfInfoId));
470     }
471     
472     @Test
473     public void downLoadPnfPackagehrowExceptionWhenVFCResponseError(){
474         String pnfInfoId="1";
475         VfcService vfcService = mock(VfcService.class);
476         when(vfcService.downLoadPnfPackage (pnfInfoId)).thenReturn(emptyBodyCall());
477         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
478         service.downLoadPnfPackage(pnfInfoId);
479     }
480     
481     @Test
482     public void downLoadPnfPackageThrowException(){
483         String pnfInfoId="1";
484         VfcService vfcService = mock(VfcService.class);
485         when(vfcService.downLoadPnfPackage (pnfInfoId)).thenReturn(failedCall("VFC is not available!"));
486         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
487         service.downLoadPnfPackage(pnfInfoId);
488     }
489     
490     @Test
491     public void itDownLoadVnfPackage(){
492         String vnfInfoId="1";
493         ResponseBody result=null;
494         VfcService vfcService = mock(VfcService.class);
495         when(vfcService.downLoadVnfPackage(vnfInfoId)).thenReturn(successfulCall(result));
496         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
497
498         Assert.assertSame("{\"status\":\"FAILED\"}", service.downLoadVnfPackage(vnfInfoId));
499     }
500     
501     @Test
502     public void downLoadVnfPackagehrowExceptionWhenVFCResponseError(){
503         String vnfInfoId="1";
504         VfcService vfcService = mock(VfcService.class);
505         when(vfcService.downLoadVnfPackage (vnfInfoId)).thenReturn(failedCall("VFC is not available!"));
506         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
507         service.downLoadVnfPackage(vnfInfoId);
508     }
509     
510     @Test
511     public void downLoadVnfPackageThrowException(){
512         String vnfInfoId="1";
513         VfcService vfcService = mock(VfcService.class);
514         when(vfcService.downLoadVnfPackage (vnfInfoId)).thenReturn(failedCall("VFC is not available!"));
515         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
516         service.downLoadVnfPackage(vnfInfoId);
517     }
518     
519     @Test
520     public void itCanDeleteNsdPackage() {
521         String csarId = "1";
522         ResponseBody result=null;
523         VfcService vfcService = mock(VfcService.class);
524         when(vfcService.deleteNsdPackage(csarId)).thenReturn(successfulCall(result));
525         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
526
527         Assert.assertSame("{\"status\":\"SUCCESS\"}", service.deleteNsdPackage(csarId));
528     }
529
530     @Test
531     public void deleteNsdPackageWillThrowExceptionWhenVFCIsNotAvailable() {
532         String csarId = "1";
533         VfcService vfcService = mock(VfcService.class);
534         when(vfcService.deleteNsdPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
535         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
536         service.deleteNsdPackage(csarId);
537     }
538
539     @Test
540     public void deleteNsdPackageWillThrowExceptionWhenVFCResponseError() {
541         String csarId = "1";
542         VfcService vfcService = mock(VfcService.class);
543         when(vfcService.deleteNsdPackage(csarId)).thenReturn(emptyBodyCall());
544         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
545         service.deleteNsdPackage(csarId);
546     }
547     
548     @Test
549     public void itCanDeleteVnfPackage() {
550         String csarId = "1";
551         ResponseBody result=null;
552         Job job = new Job();
553         VfcService vfcService = mock(VfcService.class);
554         when(vfcService.deleteVnfPackage(csarId)).thenReturn(successfulCall(job));
555         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
556
557         Assert.assertSame(job, service.deleteVnfPackage(csarId));
558     }
559
560     @Test
561     public void deleteVnfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
562         String csarId = "1";
563         VfcService vfcService = mock(VfcService.class);
564         when(vfcService.deleteVnfPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
565         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
566         service.deleteVnfPackage(csarId);
567     }
568
569     @Test(expected = VfcException.class)
570     public void deleteVnfNsdPackageWillThrowExceptionWhenVFCResponseError() {
571         String csarId = "1";
572         VfcService vfcService = mock(VfcService.class);
573         when(vfcService.deleteVnfPackage(csarId)).thenReturn(emptyBodyCall());
574         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
575         service.deleteVnfPackage(csarId);
576     }
577     
578     @Test
579     public void itCanDeletePnfdPackage() {
580         String csarId = "1";
581         ResponseBody result=null;
582         Job job = new Job();
583         VfcService vfcService = mock(VfcService.class);
584         when(vfcService.deletePnfdPackage(csarId)).thenReturn(successfulCall(result));
585         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
586
587         Assert.assertSame("{\"status\":\"SUCCESS\"}", service.deletePnfPackage(csarId));
588     }
589
590     @Test
591     public void deletePnfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
592         String csarId = "1";
593         VfcService vfcService = mock(VfcService.class);
594         when(vfcService.deletePnfdPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
595         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
596         service.deletePnfPackage(csarId);
597     }
598
599     @Test
600     public void deletePnfPackageWillThrowExceptionWhenVFCResponseError() {
601         String csarId = "1";
602         VfcService vfcService = mock(VfcService.class);
603         when(vfcService.deletePnfdPackage(csarId)).thenReturn(emptyBodyCall());
604         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
605         service.deletePnfPackage(csarId);
606     }
607     
608     @Test
609     public void itCanDeleteNetworkServiceInstance() {
610         String csarId = "1";
611         ResponseBody result=null;
612         Job job = new Job();
613         VfcService vfcService = mock(VfcService.class);
614         when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(successfulCall(result));
615         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
616
617         Assert.assertSame("{\"status\":\"SUCCESS\"}", service.deleteNetworkServiceInstance(csarId));
618     }
619
620     @Test
621     public void deleteNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() {
622         String csarId = "1";
623         VfcService vfcService = mock(VfcService.class);
624         when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(failedCall("VFC is not available!"));
625         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
626         service.deleteNetworkServiceInstance(csarId);
627     }
628
629     @Test
630     public void deleteNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() {
631         String csarId = "1";
632         VfcService vfcService = mock(VfcService.class);
633         when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(emptyBodyCall());
634         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
635         service.deleteNetworkServiceInstance(csarId);
636     }
637     
638     @Test
639     public void itCanCreateNetworkServiceInstance() throws IOException {
640         HttpServletRequest request = mockRequest();
641         ResponseBody result=null;
642         VfcService vfcService = mock(VfcService.class);
643         when(vfcService.createNetworkServiceInstance(Mockito.any())).thenReturn(successfulCall(result));
644         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
645
646         Assert.assertSame("{\"status\":\"FAILED\"}", service.createNetworkServiceInstance(request));
647     }
648
649     @Test
650     public void createNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
651         HttpServletRequest request = mockRequest();
652         VfcService vfcService = mock(VfcService.class);
653         when(vfcService.createNetworkServiceInstance(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
654         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
655         service.createNetworkServiceInstance(request);
656     }
657
658     @Test
659     public void createNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
660         HttpServletRequest request = mockRequest();
661         VfcService vfcService = mock(VfcService.class);
662         when(vfcService.createNetworkServiceInstance(Mockito.any())).thenReturn(emptyBodyCall());
663         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
664         service.createNetworkServiceInstance(request);
665     }
666     
667     @Test
668     public void itCanGetNetworkServiceInfo() throws IOException {
669         nsServiceRsp ns = new nsServiceRsp();
670         List<String> list = new ArrayList<>();
671         String s = "{\"nsInstanceId\":\"nsInstanceId\"}";
672         list.add(s);
673         ns.setNsServices(list);
674         VfcService vfcService = mock(VfcService.class);
675         when(vfcService.getNetworkServiceInfo()).thenReturn(successfulCall(ns));
676         ServiceLcmService serviceLcmService = mock(ServiceLcmService.class);
677         DefaultPackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
678         service.setServiceLcmService(serviceLcmService);
679         when(serviceLcmService.getServiceBeanByServiceInStanceId("nsInstanceId")).thenReturn(new ServiceBean());
680         Assert.assertNotNull( service.getNetworkServiceInfo());
681     }
682
683     @Test
684     public void getNetworkServiceInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
685         VfcService vfcService = mock(VfcService.class);
686         when(vfcService.getNetworkServiceInfo()).thenReturn(failedCall("VFC is not available!"));
687         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
688         service.getNetworkServiceInfo();
689     }
690
691     @Test
692     public void getNetworkServiceInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
693         VfcService vfcService = mock(VfcService.class);
694         when(vfcService.getNetworkServiceInfo()).thenReturn(emptyBodyCall());
695         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
696         service.getNetworkServiceInfo();
697     }
698     
699
700     
701     @Test
702     public void itCanHealNetworkServiceInstance() throws IOException {
703         HttpServletRequest request = mockRequest();
704         String csarId = "1";
705         ResponseBody result=null;
706         VfcService vfcService = mock(VfcService.class);
707         //when(vfcService.healNetworkServiceInstance(csarId,anyObject())).thenReturn(successfulCall(result));
708         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
709
710         //Assert.assertSame(result, service.healNetworkServiceInstance(request,csarId));
711         service.healNetworkServiceInstance(request,csarId);
712     }
713
714     @Test
715     public void healNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
716         HttpServletRequest request = mockRequest();
717         String csarId = "1";
718         VfcService vfcService = mock(VfcService.class);
719         when(vfcService.healNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(failedCall("VFC is not available!"));
720         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
721         service.healNetworkServiceInstance(request,csarId);
722     }
723
724     @Test
725     public void healNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
726         HttpServletRequest request = mockRequest();
727         String csarId = "1";
728         VfcService vfcService = mock(VfcService.class);
729         when(vfcService.healNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(emptyBodyCall());
730         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
731         service.healNetworkServiceInstance(request,csarId);
732     }
733     
734     @Test
735     public void itCanScaleNetworkServiceInstance() throws IOException {
736         HttpServletRequest request = mockRequest();
737         String csarId = "1";
738         ResponseBody result=null;
739         VfcService vfcService = mock(VfcService.class);
740         //when(vfcService.scaleNetworkServiceInstance(csarId,anyObject())).thenReturn(successfulCall(result));
741         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
742
743         Assert.assertTrue(StringUtils.isNotEmpty(service.scaleNetworkServiceInstance(request,csarId)));
744     }
745
746     @Test
747     public void scaleNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
748         HttpServletRequest request = mockRequest();
749         String csarId = "1";
750         VfcService vfcService = mock(VfcService.class);
751         when(vfcService.scaleNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(failedCall("VFC is not available!"));
752         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
753         service.scaleNetworkServiceInstance(request,csarId);
754     }
755
756     @Test
757     public void scaleNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
758         HttpServletRequest request = mockRequest();
759         String csarId = "1";
760         VfcService vfcService = mock(VfcService.class);
761         when(vfcService.scaleNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(emptyBodyCall());
762         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
763         service.scaleNetworkServiceInstance(request,csarId);
764     }
765     
766     
767     @Test
768     public void itCaninstantiateNetworkServiceInstance() throws IOException {
769         HttpServletRequest request = mockRequest();
770         String serviceInstanceId="1";
771         ResponseBody result=null;
772         VfcService vfcService = mock(VfcService.class);
773         //when(vfcService.instantiateNetworkServiceInstance(anyObject(),serviceInstanceId)).thenReturn(successfulCall(result));
774         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
775
776         service.instantiateNetworkServiceInstance(request,serviceInstanceId);
777     }
778
779     @Test
780     public void instantiateNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
781         HttpServletRequest request = mockRequest();
782         String serviceInstanceId="1";
783         VfcService vfcService = mock(VfcService.class);
784         when(vfcService.instantiateNetworkServiceInstance(Mockito.any(),eq(serviceInstanceId))).thenReturn(failedCall("VFC is not available!"));
785         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
786         service.instantiateNetworkServiceInstance(request,serviceInstanceId);
787     }
788
789     @Test
790     public void instantiateNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
791         HttpServletRequest request = mockRequest();
792         String serviceInstanceId="1";
793         VfcService vfcService = mock(VfcService.class);
794         when(vfcService.instantiateNetworkServiceInstance(Mockito.any(),eq(serviceInstanceId))).thenReturn(emptyBodyCall());
795         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
796         service.instantiateNetworkServiceInstance(request,serviceInstanceId);
797     }
798     
799     
800     @Test
801     public void itCanTerminateNetworkServiceInstance() throws IOException {
802         HttpServletRequest request = mockRequest();
803         String csarId = "1";
804         ResponseBody result=null;
805         Job job = new Job();
806         VfcService vfcService = mock(VfcService.class);
807         when(vfcService.terminateNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(successfulCall(result));
808         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
809
810         service.terminateNetworkServiceInstance(request,csarId);
811     }
812
813     @Test
814     public void terminateNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
815         HttpServletRequest request = mockRequest();
816         String csarId = "1";
817         VfcService vfcService = mock(VfcService.class);
818         //when(vfcService.terminateNetworkServiceInstance(csarId,anyObject())).thenReturn(failedCall("VFC is not available!"));
819         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
820         service.terminateNetworkServiceInstance(request,csarId);
821     }
822
823     @Test
824     public void terminateNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
825         HttpServletRequest request = mockRequest();
826         String csarId = "1";
827         VfcService vfcService = mock(VfcService.class);
828         when(vfcService.terminateNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(emptyBodyCall());
829         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
830         service.terminateNetworkServiceInstance(request,csarId);
831     }
832     
833     @Test
834     public void itCreateNetworkServiceData() throws IOException {
835         HttpServletRequest request = mockRequest();
836         ResponseBody result=null;
837         VfcService vfcService = mock(VfcService.class);
838         when(vfcService.createNetworkServiceData(Mockito.any())).thenReturn(successfulCall(result));
839         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
840
841         Assert.assertTrue(StringUtils.isNotEmpty(service.createNetworkServiceData(request)));
842     }
843
844     @Test
845     public void createNetworkServiceDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
846         HttpServletRequest request = mockRequest();
847         VfcService vfcService = mock(VfcService.class);
848         when(vfcService.createNetworkServiceData(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
849         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
850         service.createNetworkServiceData(request);
851     }
852
853     @Test
854     public void createNetworkServiceDataWillThrowExceptionWhenVFCResponseError() throws IOException {
855         HttpServletRequest request = mockRequest();
856         VfcService vfcService = mock(VfcService.class);
857         when(vfcService.createNetworkServiceData(Mockito.any())).thenReturn(emptyBodyCall());
858         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
859         service.createNetworkServiceData(request);
860     }
861     
862     @Test
863     public void itCreateVnfData() throws IOException {
864         HttpServletRequest request = mockRequest();
865         ResponseBody result=null;
866         VfcService vfcService = mock(VfcService.class);
867         when(vfcService.createVnfData(Mockito.any())).thenReturn(successfulCall(result));
868         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
869
870         Assert.assertSame("{\"status\":\"FAILED\"}", service.createVnfData(request));
871     }
872
873     @Test
874     public void createVnfDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
875         HttpServletRequest request = mockRequest();
876         VfcService vfcService = mock(VfcService.class);
877         when(vfcService.createVnfData(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
878         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
879         service.createVnfData(request);
880     }
881
882     @Test
883     public void createVnfDataWillThrowExceptionWhenVFCResponseError() throws IOException {
884         HttpServletRequest request = mockRequest();
885         VfcService vfcService = mock(VfcService.class);
886         when(vfcService.createVnfData(Mockito.any())).thenReturn(emptyBodyCall());
887         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
888         service.createVnfData(request);
889     }
890     
891     @Test
892     public void itCreatePnfData() throws IOException {
893         HttpServletRequest request = mockRequest();
894         ResponseBody result=null;
895         VfcService vfcService = mock(VfcService.class);
896         when(vfcService.createPnfData(Mockito.any())).thenReturn(successfulCall(result));
897         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
898
899         Assert.assertSame("{\"status\":\"FAILED\"}", service.createPnfData(request));
900     }
901
902     @Test
903     public void createPnfDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
904         HttpServletRequest request = mockRequest();
905         VfcService vfcService = mock(VfcService.class);
906         when(vfcService.createPnfData(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
907         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
908         service.createPnfData(request);
909     }
910
911     @Test
912     public void createPnfDataWillThrowExceptionWhenVFCResponseError() throws IOException {
913         HttpServletRequest request = mockRequest();
914         VfcService vfcService = mock(VfcService.class);
915         when(vfcService.createPnfData(Mockito.any())).thenReturn(emptyBodyCall());
916         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
917         service.createPnfData(request);
918     }
919     
920     @Test
921     public void itGetNsdInfo() throws IOException {
922         String nsdId="1";
923         ResponseBody result=null;
924         VfcService vfcService = mock(VfcService.class);
925         when(vfcService.getNsdInfo(nsdId)).thenReturn(successfulCall(result));
926         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
927
928         Assert.assertSame("{\"status\":\"SUCCESS\"}", service.getNsdInfo(nsdId));
929     }
930
931     @Test
932     public void getNsdInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
933         String nsdId="1";
934         VfcService vfcService = mock(VfcService.class);
935         when(vfcService.getNsdInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
936         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
937         service.getNsdInfo(nsdId);
938     }
939
940     @Test
941     public void getNsdInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
942         String nsdId="1";
943         VfcService vfcService = mock(VfcService.class);
944         when(vfcService.getNsdInfo(nsdId)).thenReturn(emptyBodyCall());
945         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
946         service.getNsdInfo(nsdId);
947     }
948     
949     @Test
950     public void itGetVnfInfo() throws IOException {
951         String nsdId="1";
952         ResponseBody result=null;
953         VfcService vfcService = mock(VfcService.class);
954         when(vfcService.getVnfInfo(nsdId)).thenReturn(successfulCall(result));
955         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
956
957         Assert.assertSame("{\"status\":\"SUCCESS\"}", service.getVnfInfo(nsdId));
958     }
959
960     @Test
961     public void getVnfInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
962         String nsdId="1";
963         VfcService vfcService = mock(VfcService.class);
964         when(vfcService.getVnfInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
965         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
966         service.getVnfInfo(nsdId);
967     }
968
969     @Test
970     public void getVnfInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
971         String nsdId="1";
972         VfcService vfcService = mock(VfcService.class);
973         when(vfcService.getVnfInfo(nsdId)).thenReturn(emptyBodyCall());
974         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
975         service.getVnfInfo(nsdId);
976     }
977     
978     @Test
979     public void itGetPnfInfo() throws IOException {
980         String nsdId="1";
981         ResponseBody result=null;
982         VfcService vfcService = mock(VfcService.class);
983         when(vfcService.getPnfInfo(nsdId)).thenReturn(successfulCall(result));
984         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
985
986         Assert.assertSame("{\"status\":\"SUCCESS\"}", service.getPnfInfo(nsdId));
987     }
988
989     @Test
990     public void getPnfInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
991         String nsdId="1";
992         VfcService vfcService = mock(VfcService.class);
993         when(vfcService.getPnfInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
994         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
995         service.getPnfInfo(nsdId);
996     }
997
998     @Test
999     public void getPnfInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
1000         String nsdId="1";
1001         VfcService vfcService = mock(VfcService.class);
1002         when(vfcService.getPnfInfo(nsdId)).thenReturn(emptyBodyCall());
1003         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1004         service.getPnfInfo(nsdId);
1005     }
1006     
1007     @Test
1008     public void itCanListNsTemplates() throws IOException {
1009         ResponseBody result=null;
1010         VfcService vfcService = mock(VfcService.class);
1011         when(vfcService.listNsTemplates()).thenReturn(successfulCall(result));
1012         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1013
1014         Assert.assertSame(result, service.listNsTemplates());
1015     }
1016
1017     @Test
1018     public void listNsTemplatesWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
1019         VfcService vfcService = mock(VfcService.class);
1020         when(vfcService.listNsTemplates()).thenReturn(failedCall("VFC is not available!"));
1021         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1022         service.listNsTemplates();
1023     }
1024
1025     @Test
1026     public void listNsTemplatesWillThrowExceptionWhenVFCResponseError() throws IOException {
1027         VfcService vfcService = mock(VfcService.class);
1028         when(vfcService.listNsTemplates()).thenReturn(emptyBodyCall());
1029         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1030         service.listNsTemplates();
1031     }
1032     
1033     @Test
1034     public void itCanGetVnfInfoById() throws IOException {
1035         String nsdId="1";
1036         ResponseBody result=null;
1037         VfcService vfcService = mock(VfcService.class);
1038         when(vfcService.getVnfInfoById(nsdId)).thenReturn(successfulCall(result));
1039         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1040
1041         Assert.assertSame(result, service.getVnfInfoById(nsdId));
1042     }
1043
1044     @Test
1045     public void getVnfInfoByIdWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
1046         String nsdId="1";
1047         VfcService vfcService = mock(VfcService.class);
1048         when(vfcService.getVnfInfoById(nsdId)).thenReturn(failedCall("VFC is not available!"));
1049         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1050         service.getVnfInfoById(nsdId);
1051     }
1052
1053     @Test
1054     public void getVnfInfoByIdWillThrowExceptionWhenVFCResponseError() throws IOException {
1055         String nsdId="1";
1056         VfcService vfcService = mock(VfcService.class);
1057         when(vfcService.getVnfInfoById(nsdId)).thenReturn(emptyBodyCall());
1058         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1059         service.getVnfInfoById(nsdId);
1060     }
1061     
1062     @Test
1063     public void itCanFetchNsTemplateData() throws IOException {
1064         HttpServletRequest request = mockRequest();
1065         ResponseBody result=null;
1066         VfcService vfcService = mock(VfcService.class);
1067         when(vfcService.fetchNsTemplateData(Mockito.any())).thenReturn(successfulCall(result));
1068         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1069
1070         Assert.assertSame("{\"status\":\"FAILED\"}", service.fetchNsTemplateData(request));
1071     }
1072
1073     @Test
1074     public void fetchNsTemplateDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
1075         HttpServletRequest request = mockRequest();
1076         VfcService vfcService = mock(VfcService.class);
1077         when(vfcService.fetchNsTemplateData(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
1078         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1079         service.fetchNsTemplateData(request);
1080     }
1081
1082     @Test
1083     public void fetchNsTemplateDataWillThrowExceptionWhenVFCResponseError() throws IOException {
1084         HttpServletRequest request = mockRequest();
1085         VfcService vfcService = mock(VfcService.class);
1086         when(vfcService.fetchNsTemplateData(Mockito.any())).thenReturn(emptyBodyCall());
1087         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1088         service.fetchNsTemplateData(request);
1089     }
1090
1091   }