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