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