47013247c80f644bb14711373c7b693dd5518190
[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.AAIClient;
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.vfc.VfcService;
39 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Csar;
40 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.DistributionResult;
41 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Job;
42 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.JobStatus;
43 import org.onap.usecaseui.server.service.lcm.domain.vfc.exceptions.VfcException;
44
45 import okhttp3.ResponseBody;
46 import retrofit2.Call;
47
48 import java.io.IOException;
49 import java.util.ArrayList;
50 import java.util.Collections;
51 import java.util.List;
52
53 import jakarta.servlet.ReadListener;
54 import jakarta.servlet.ServletInputStream;
55 import jakarta.servlet.http.HttpServletRequest;
56
57 import static org.hamcrest.CoreMatchers.equalTo;
58 import static org.junit.Assert.assertNotEquals;
59 import static org.junit.Assert.assertNotNull;
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         AAIClient aaiClient = newAAIService(vim);
137
138         PackageDistributionService service = new DefaultPackageDistributionService(sdcService, null, null);
139
140         Assert.assertThat(service.retrievePackageInfo(), equalTo(new VfNsPackageInfo(serviceTemplate, vnf)));
141     }
142
143     private AAIClient newAAIService(List<VimInfo> vim) {
144         AAIClient aaiClient = mock(AAIClient.class);
145         VimInfoRsp rsp = new VimInfoRsp();
146         rsp.setCloudRegion(vim);
147         Call<VimInfoRsp> vimCall = successfulCall(rsp);
148         when(aaiClient.listVimInfo()).thenReturn(vimCall);
149         return aaiClient;
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         AAIClient aaiClient = newAAIService(vim);
173
174         PackageDistributionService service = new DefaultPackageDistributionService(sdcService, null, 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, 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, null);
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, null);
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, null);
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, null);
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, null);
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, null);
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, null);
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, null);
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, null);
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, null);
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, null);
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, null);
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, null);
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, null);
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, null);
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, null);
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, null);
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, null);
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, null);
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, null);
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, null);
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, null);
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, null);
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, null);
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, null);
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, null);
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, null);
458         service.getPnfPackages();
459     }
460
461     @Test
462     public void itDownLoadNsPackage(){
463         String nsdInfoId="1";
464         ResponseBody successResponse=null;
465         VfcService vfcService = mock(VfcService.class);
466         when(vfcService.downLoadNsPackage(nsdInfoId)).thenReturn(successfulCall(successResponse));
467         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
468
469         String result = service.downLoadNsPackage(nsdInfoId);
470         assertNotNull(result);
471         assertNotEquals("", result);
472     }
473
474     @Test
475     public void downLoadNsPackagehrowExceptionWhenVFCResponseError(){
476         String nsdInfoId="1";
477         VfcService vfcService = mock(VfcService.class);
478         when(vfcService.downLoadNsPackage (nsdInfoId)).thenReturn(emptyBodyCall());
479         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
480         service.downLoadNsPackage(nsdInfoId);
481     }
482
483     @Test
484     public void downLoadNsPackageThrowException(){
485         String nsdInfoId="1";
486         VfcService vfcService = mock(VfcService.class);
487         when(vfcService.downLoadNsPackage (nsdInfoId)).thenReturn(failedCall("VFC is not available!"));
488         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
489         service.downLoadNsPackage(nsdInfoId);
490     }
491
492     @Test
493     public void itDownLoadPnfPackage(){
494         String pnfInfoId="1";
495         VfcService vfcService = mock(VfcService.class);
496         when(vfcService.downLoadNsPackage(pnfInfoId)).thenReturn(successfulCall(result));
497         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
498
499         Assert.assertSame("{\"status\":\"SUCCESS\"}", service.downLoadPnfPackage(pnfInfoId));
500     }
501
502     @Test
503     public void downLoadPnfPackagehrowExceptionWhenVFCResponseError(){
504         String pnfInfoId="1";
505         VfcService vfcService = mock(VfcService.class);
506         when(vfcService.downLoadNsPackage (pnfInfoId)).thenReturn(emptyBodyCall());
507         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
508         service.downLoadPnfPackage(pnfInfoId);
509     }
510
511     @Test
512     public void downLoadPnfPackageThrowException(){
513         String pnfInfoId="1";
514         VfcService vfcService = mock(VfcService.class);
515         when(vfcService.downLoadNsPackage (pnfInfoId)).thenReturn(failedCall("VFC is not available!"));
516         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
517         service.downLoadPnfPackage(pnfInfoId);
518     }
519
520     @Test
521     public void itDownLoadVnfPackage(){
522         String vnfInfoId="1";
523         VfcService vfcService = mock(VfcService.class);
524         when(vfcService.downLoadNsPackage(vnfInfoId)).thenReturn(successfulCall(result));
525         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
526
527         Assert.assertSame("{\"status\":\"SUCCESS\"}", service.downLoadVnfPackage(vnfInfoId));
528     }
529
530     @Test
531     public void downLoadVnfPackagehrowExceptionWhenVFCResponseError(){
532         String vnfInfoId="1";
533         VfcService vfcService = mock(VfcService.class);
534         when(vfcService.downLoadNsPackage (vnfInfoId)).thenReturn(failedCall("VFC is not available!"));
535         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
536         service.downLoadVnfPackage(vnfInfoId);
537     }
538
539     @Test
540     public void downLoadVnfPackageThrowException(){
541         String vnfInfoId="1";
542         VfcService vfcService = mock(VfcService.class);
543         when(vfcService.downLoadNsPackage (vnfInfoId)).thenReturn(failedCall("VFC is not available!"));
544         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
545         service.downLoadVnfPackage(vnfInfoId);
546     }
547
548     @Test
549     public void itCanDeleteNsdPackage() {
550         String csarId = "1";
551         ResponseBody result=null;
552         VfcService vfcService = mock(VfcService.class);
553         when(vfcService.deleteNsdPackage(csarId)).thenReturn(successfulCall(result));
554         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
555
556         Assert.assertSame("{\"status\":\"SUCCESS\"}", service.deleteNsdPackage(csarId));
557     }
558
559     @Test
560     public void deleteNsdPackageWillThrowExceptionWhenVFCIsNotAvailable() {
561         String csarId = "1";
562         VfcService vfcService = mock(VfcService.class);
563         when(vfcService.deleteNsdPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
564         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
565         service.deleteNsdPackage(csarId);
566     }
567
568     @Test
569     public void deleteNsdPackageWillThrowExceptionWhenVFCResponseError() {
570         String csarId = "1";
571         VfcService vfcService = mock(VfcService.class);
572         when(vfcService.deleteNsdPackage(csarId)).thenReturn(emptyBodyCall());
573         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
574         service.deleteNsdPackage(csarId);
575     }
576
577     @Test
578     public void itCanDeleteVnfPackage() {
579         String csarId = "1";
580         VfcService vfcService = mock(VfcService.class);
581         when(vfcService.deleteVnfdPackage(csarId)).thenReturn(successfulCall(result));
582         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
583
584         Assert.assertNotNull(service.deleteVnfPackage(csarId));
585     }
586
587     @Test
588     public void deleteVnfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
589         String csarId = "1";
590         VfcService vfcService = mock(VfcService.class);
591         when(vfcService.deleteVnfdPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
592         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
593         service.deleteVnfPackage(csarId);
594     }
595
596     @Test
597     public void deleteVnfNsdPackageWillThrowExceptionWhenVFCResponseError() {
598         String csarId = "1";
599         VfcService vfcService = mock(VfcService.class);
600         when(vfcService.deleteVnfdPackage(csarId)).thenReturn(emptyBodyCall());
601         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
602         service.deleteVnfPackage(csarId);
603         Assert.assertSame("{\"status\":\"FAILED\"}", service.deleteVnfPackage(csarId));
604     }
605
606     @Test
607     public void itCanDeletePnfdPackage() {
608         String csarId = "1";
609         ResponseBody result=null;
610         Job job = new Job();
611         VfcService vfcService = mock(VfcService.class);
612         when(vfcService.deletePnfdPackage(csarId)).thenReturn(successfulCall(result));
613         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
614
615         Assert.assertSame("{\"status\":\"SUCCESS\"}", service.deletePnfPackage(csarId));
616     }
617
618     @Test
619     public void deletePnfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
620         String csarId = "1";
621         VfcService vfcService = mock(VfcService.class);
622         when(vfcService.deletePnfdPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
623         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
624         service.deletePnfPackage(csarId);
625     }
626
627     @Test
628     public void deletePnfPackageWillThrowExceptionWhenVFCResponseError() {
629         String csarId = "1";
630         VfcService vfcService = mock(VfcService.class);
631         when(vfcService.deletePnfdPackage(csarId)).thenReturn(emptyBodyCall());
632         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
633         service.deletePnfPackage(csarId);
634     }
635
636     @Test
637     public void itCanDeleteNetworkServiceInstance() {
638         String csarId = "1";
639         ResponseBody result=null;
640         Job job = new Job();
641         VfcService vfcService = mock(VfcService.class);
642         when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(successfulCall(result));
643         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
644
645         Assert.assertSame("{\"status\":\"SUCCESS\"}", service.deleteNetworkServiceInstance(csarId));
646     }
647
648     @Test
649     public void deleteNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() {
650         String csarId = "1";
651         VfcService vfcService = mock(VfcService.class);
652         when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(failedCall("VFC is not available!"));
653         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
654         service.deleteNetworkServiceInstance(csarId);
655     }
656
657     @Test
658     public void deleteNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() {
659         String csarId = "1";
660         VfcService vfcService = mock(VfcService.class);
661         when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(emptyBodyCall());
662         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
663         service.deleteNetworkServiceInstance(csarId);
664     }
665
666     @Test
667     public void itCanCreateNetworkServiceInstance() throws IOException {
668         HttpServletRequest request = mockRequest();
669         ResponseBody result=null;
670         VfcService vfcService = mock(VfcService.class);
671         when(vfcService.createNetworkServiceInstance(Mockito.any())).thenReturn(successfulCall(result));
672         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
673
674         Assert.assertSame("{\"status\":\"FAILED\"}", service.createNetworkServiceInstance(request));
675     }
676
677     @Test
678     public void createNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
679         HttpServletRequest request = mockRequest();
680         VfcService vfcService = mock(VfcService.class);
681         when(vfcService.createNetworkServiceInstance(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
682         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
683         service.createNetworkServiceInstance(request);
684     }
685
686     @Test
687     public void createNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
688         HttpServletRequest request = mockRequest();
689         VfcService vfcService = mock(VfcService.class);
690         when(vfcService.createNetworkServiceInstance(Mockito.any())).thenReturn(emptyBodyCall());
691         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
692         service.createNetworkServiceInstance(request);
693     }
694
695     @Test
696     public void itCanGetNetworkServiceInfo() throws IOException {
697         nsServiceRsp ns = new nsServiceRsp();
698         List<String> list = new ArrayList<>();
699         String s = "{\"nsInstanceId\":\"nsInstanceId\"}";
700         list.add(s);
701         ns.setNsServices(list);
702         VfcService vfcService = mock(VfcService.class);
703         when(vfcService.getNetworkServiceInfo()).thenReturn(successfulCall(ns));
704         ServiceLcmService serviceLcmService = mock(ServiceLcmService.class);
705         DefaultPackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, serviceLcmService);
706         when(serviceLcmService.getServiceBeanByServiceInStanceId("nsInstanceId")).thenReturn(new ServiceBean());
707         Assert.assertNotNull( service.getNetworkServiceInfo());
708     }
709
710     @Test
711     public void getNetworkServiceInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
712         VfcService vfcService = mock(VfcService.class);
713         when(vfcService.getNetworkServiceInfo()).thenReturn(failedCall("VFC is not available!"));
714         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
715         service.getNetworkServiceInfo();
716     }
717
718     @Test
719     public void getNetworkServiceInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
720         VfcService vfcService = mock(VfcService.class);
721         when(vfcService.getNetworkServiceInfo()).thenReturn(emptyBodyCall());
722         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
723         service.getNetworkServiceInfo();
724     }
725
726
727
728     @Test
729     public void itCanHealNetworkServiceInstance() throws IOException {
730         HttpServletRequest request = mockRequest();
731         String csarId = "1";
732         ResponseBody result=null;
733         VfcService vfcService = mock(VfcService.class);
734         //when(vfcService.healNetworkServiceInstance(csarId,anyObject())).thenReturn(successfulCall(result));
735         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
736
737         //Assert.assertSame(result, service.healNetworkServiceInstance(request,csarId));
738         service.healNetworkServiceInstance(request,csarId);
739     }
740
741     @Test
742     public void healNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
743         HttpServletRequest request = mockRequest();
744         String csarId = "1";
745         VfcService vfcService = mock(VfcService.class);
746         when(vfcService.healNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(failedCall("VFC is not available!"));
747         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
748         service.healNetworkServiceInstance(request,csarId);
749     }
750
751     @Test
752     public void healNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
753         HttpServletRequest request = mockRequest();
754         String csarId = "1";
755         VfcService vfcService = mock(VfcService.class);
756         when(vfcService.healNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(emptyBodyCall());
757         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
758         service.healNetworkServiceInstance(request,csarId);
759     }
760
761     @Test
762     public void itCanScaleNetworkServiceInstance() throws IOException {
763         HttpServletRequest request = mockRequest();
764         String csarId = "1";
765         VfcService vfcService = mock(VfcService.class);
766         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
767
768         String result = service.scaleNetworkServiceInstance(request,csarId);
769         assertNotNull(result);
770         assertNotEquals("", result);
771     }
772
773     @Test
774     public void scaleNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
775         HttpServletRequest request = mockRequest();
776         String csarId = "1";
777         VfcService vfcService = mock(VfcService.class);
778         when(vfcService.scaleNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(failedCall("VFC is not available!"));
779         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
780         service.scaleNetworkServiceInstance(request,csarId);
781     }
782
783     @Test
784     public void scaleNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
785         HttpServletRequest request = mockRequest();
786         String csarId = "1";
787         VfcService vfcService = mock(VfcService.class);
788         when(vfcService.scaleNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(emptyBodyCall());
789         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
790         service.scaleNetworkServiceInstance(request,csarId);
791     }
792
793
794     @Test
795     public void itCaninstantiateNetworkServiceInstance() throws IOException {
796         HttpServletRequest request = mockRequest();
797         String serviceInstanceId="1";
798         ResponseBody result=null;
799         VfcService vfcService = mock(VfcService.class);
800         //when(vfcService.instantiateNetworkServiceInstance(anyObject(),serviceInstanceId)).thenReturn(successfulCall(result));
801         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
802
803         service.instantiateNetworkServiceInstance(request,serviceInstanceId);
804     }
805
806     @Test
807     public void instantiateNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
808         HttpServletRequest request = mockRequest();
809         String serviceInstanceId="1";
810         VfcService vfcService = mock(VfcService.class);
811         when(vfcService.instantiateNetworkServiceInstance(Mockito.any(),eq(serviceInstanceId))).thenReturn(failedCall("VFC is not available!"));
812         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
813         service.instantiateNetworkServiceInstance(request,serviceInstanceId);
814     }
815
816     @Test
817     public void instantiateNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
818         HttpServletRequest request = mockRequest();
819         String serviceInstanceId="1";
820         VfcService vfcService = mock(VfcService.class);
821         when(vfcService.instantiateNetworkServiceInstance(Mockito.any(),eq(serviceInstanceId))).thenReturn(emptyBodyCall());
822         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
823         service.instantiateNetworkServiceInstance(request,serviceInstanceId);
824     }
825
826
827     @Test
828     public void itCanTerminateNetworkServiceInstance() throws IOException {
829         HttpServletRequest request = mockRequest();
830         String csarId = "1";
831         ResponseBody result=null;
832         Job job = new Job();
833         VfcService vfcService = mock(VfcService.class);
834         when(vfcService.terminateNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(successfulCall(result));
835         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
836
837         service.terminateNetworkServiceInstance(request,csarId);
838     }
839
840     @Test
841     public void terminateNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
842         HttpServletRequest request = mockRequest();
843         String csarId = "1";
844         VfcService vfcService = mock(VfcService.class);
845         //when(vfcService.terminateNetworkServiceInstance(csarId,anyObject())).thenReturn(failedCall("VFC is not available!"));
846         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
847         service.terminateNetworkServiceInstance(request,csarId);
848     }
849
850     @Test
851     public void terminateNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
852         HttpServletRequest request = mockRequest();
853         String csarId = "1";
854         VfcService vfcService = mock(VfcService.class);
855         when(vfcService.terminateNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(emptyBodyCall());
856         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
857         service.terminateNetworkServiceInstance(request,csarId);
858     }
859
860     @Test
861     public void itCreateNetworkServiceData() throws IOException {
862         HttpServletRequest request = mockRequest();
863         ResponseBody responseBody = null;
864         VfcService vfcService = mock(VfcService.class);
865         when(vfcService.createNetworkServiceData(Mockito.any())).thenReturn(successfulCall(responseBody));
866         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
867
868         String result = service.createNetworkServiceData(request);
869         assertNotNull(result);
870         assertNotEquals("", result);
871     }
872
873     @Test
874     public void createNetworkServiceDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
875         HttpServletRequest request = mockRequest();
876         VfcService vfcService = mock(VfcService.class);
877         when(vfcService.createNetworkServiceData(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
878         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
879         service.createNetworkServiceData(request);
880     }
881
882     @Test
883     public void createNetworkServiceDataWillThrowExceptionWhenVFCResponseError() throws IOException {
884         HttpServletRequest request = mockRequest();
885         VfcService vfcService = mock(VfcService.class);
886         when(vfcService.createNetworkServiceData(Mockito.any())).thenReturn(emptyBodyCall());
887         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
888         service.createNetworkServiceData(request);
889     }
890
891     @Test
892     public void itCreateVnfData() throws IOException {
893         HttpServletRequest request = mockRequest();
894         ResponseBody result=null;
895         VfcService vfcService = mock(VfcService.class);
896         when(vfcService.createVnfData(Mockito.any())).thenReturn(successfulCall(result));
897         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
898
899         Assert.assertSame("{\"status\":\"FAILED\"}", service.createVnfData(request));
900     }
901
902     @Test
903     public void createVnfDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
904         HttpServletRequest request = mockRequest();
905         VfcService vfcService = mock(VfcService.class);
906         when(vfcService.createVnfData(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
907         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
908         service.createVnfData(request);
909     }
910
911     @Test
912     public void createVnfDataWillThrowExceptionWhenVFCResponseError() throws IOException {
913         HttpServletRequest request = mockRequest();
914         VfcService vfcService = mock(VfcService.class);
915         when(vfcService.createVnfData(Mockito.any())).thenReturn(emptyBodyCall());
916         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
917         service.createVnfData(request);
918     }
919
920     @Test
921     public void itCreatePnfData() throws IOException {
922         HttpServletRequest request = mockRequest();
923         ResponseBody result=null;
924         VfcService vfcService = mock(VfcService.class);
925         when(vfcService.createPnfData(Mockito.any())).thenReturn(successfulCall(result));
926         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
927
928         Assert.assertSame("{\"status\":\"FAILED\"}", service.createPnfData(request));
929     }
930
931     @Test
932     public void createPnfDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
933         HttpServletRequest request = mockRequest();
934         VfcService vfcService = mock(VfcService.class);
935         when(vfcService.createPnfData(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
936         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
937         service.createPnfData(request);
938     }
939
940     @Test
941     public void createPnfDataWillThrowExceptionWhenVFCResponseError() throws IOException {
942         HttpServletRequest request = mockRequest();
943         VfcService vfcService = mock(VfcService.class);
944         when(vfcService.createPnfData(Mockito.any())).thenReturn(emptyBodyCall());
945         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
946         service.createPnfData(request);
947     }
948
949     @Test
950     public void itGetNsdInfo() throws IOException {
951         String nsdId="1";
952         ResponseBody result=null;
953         VfcService vfcService = mock(VfcService.class);
954         when(vfcService.getNsdInfo(nsdId)).thenReturn(successfulCall(result));
955         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
956
957         Assert.assertSame("{\"status\":\"SUCCESS\"}", service.getNsdInfo(nsdId));
958     }
959
960     @Test
961     public void getNsdInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
962         String nsdId="1";
963         VfcService vfcService = mock(VfcService.class);
964         when(vfcService.getNsdInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
965         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
966         service.getNsdInfo(nsdId);
967     }
968
969     @Test
970     public void getNsdInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
971         String nsdId="1";
972         VfcService vfcService = mock(VfcService.class);
973         when(vfcService.getNsdInfo(nsdId)).thenReturn(emptyBodyCall());
974         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
975         service.getNsdInfo(nsdId);
976     }
977
978     @Test
979     public void itGetVnfInfo() throws IOException {
980         String nsdId="1";
981         ResponseBody result=null;
982         VfcService vfcService = mock(VfcService.class);
983         when(vfcService.getVnfInfo(nsdId)).thenReturn(successfulCall(result));
984         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
985
986         Assert.assertSame("{\"status\":\"SUCCESS\"}", service.getVnfInfo(nsdId));
987     }
988
989     @Test
990     public void getVnfInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
991         String nsdId="1";
992         VfcService vfcService = mock(VfcService.class);
993         when(vfcService.getVnfInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
994         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
995         service.getVnfInfo(nsdId);
996     }
997
998     @Test
999     public void getVnfInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
1000         String nsdId="1";
1001         VfcService vfcService = mock(VfcService.class);
1002         when(vfcService.getVnfInfo(nsdId)).thenReturn(emptyBodyCall());
1003         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
1004         service.getVnfInfo(nsdId);
1005     }
1006
1007     @Test
1008     public void itGetPnfInfo() throws IOException {
1009         String nsdId="1";
1010         ResponseBody result=null;
1011         VfcService vfcService = mock(VfcService.class);
1012         when(vfcService.getPnfInfo(nsdId)).thenReturn(successfulCall(result));
1013         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
1014
1015         Assert.assertSame("{\"status\":\"SUCCESS\"}", service.getPnfInfo(nsdId));
1016     }
1017
1018     @Test
1019     public void getPnfInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
1020         String nsdId="1";
1021         VfcService vfcService = mock(VfcService.class);
1022         when(vfcService.getPnfInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
1023         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
1024         service.getPnfInfo(nsdId);
1025     }
1026
1027     @Test
1028     public void getPnfInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
1029         String nsdId="1";
1030         VfcService vfcService = mock(VfcService.class);
1031         when(vfcService.getPnfInfo(nsdId)).thenReturn(emptyBodyCall());
1032         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
1033         service.getPnfInfo(nsdId);
1034     }
1035
1036     @Test
1037     public void itCanListNsTemplates() throws IOException {
1038         VfcService vfcService = mock(VfcService.class);
1039         when(vfcService.listNsTemplates()).thenReturn(successfulCall(result));
1040         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
1041
1042         Assert.assertNotNull( service.listNsTemplates());
1043     }
1044
1045     @Test
1046     public void listNsTemplatesWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
1047         VfcService vfcService = mock(VfcService.class);
1048         when(vfcService.listNsTemplates()).thenReturn(failedCall("VFC is not available!"));
1049         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
1050         service.listNsTemplates();
1051     }
1052
1053     @Test
1054     public void listNsTemplatesWillThrowExceptionWhenVFCResponseError() throws IOException {
1055         VfcService vfcService = mock(VfcService.class);
1056         when(vfcService.listNsTemplates()).thenReturn(emptyBodyCall());
1057         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
1058         service.listNsTemplates();
1059     }
1060
1061     @Test
1062     public void itCanGetVnfInfoById() throws IOException {
1063         String nsdId="1";
1064         VfcService vfcService = mock(VfcService.class);
1065         when(vfcService.getVnfInfoById(nsdId)).thenReturn(successfulCall(result));
1066         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
1067
1068         Assert.assertNotNull(service.getVnfInfoById(nsdId));
1069     }
1070
1071     @Test
1072     public void getVnfInfoByIdWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
1073         String nsdId="1";
1074         VfcService vfcService = mock(VfcService.class);
1075         when(vfcService.getVnfInfoById(nsdId)).thenReturn(failedCall("VFC is not available!"));
1076         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
1077         service.getVnfInfoById(nsdId);
1078     }
1079
1080     @Test
1081     public void getVnfInfoByIdWillThrowExceptionWhenVFCResponseError() throws IOException {
1082         String nsdId="1";
1083         VfcService vfcService = mock(VfcService.class);
1084         when(vfcService.getVnfInfoById(nsdId)).thenReturn(emptyBodyCall());
1085         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
1086         service.getVnfInfoById(nsdId);
1087     }
1088
1089     @Test
1090     public void itCanFetchNsTemplateData() throws IOException {
1091         HttpServletRequest request = mockRequest();
1092         ResponseBody result=null;
1093         VfcService vfcService = mock(VfcService.class);
1094         when(vfcService.fetchNsTemplateData(Mockito.any())).thenReturn(successfulCall(result));
1095         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
1096
1097         Assert.assertSame("{\"status\":\"FAILED\"}", service.fetchNsTemplateData(request));
1098     }
1099
1100     @Test
1101     public void fetchNsTemplateDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
1102         HttpServletRequest request = mockRequest();
1103         VfcService vfcService = mock(VfcService.class);
1104         when(vfcService.fetchNsTemplateData(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
1105         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
1106         service.fetchNsTemplateData(request);
1107     }
1108
1109     @Test
1110     public void fetchNsTemplateDataWillThrowExceptionWhenVFCResponseError() throws IOException {
1111         HttpServletRequest request = mockRequest();
1112         VfcService vfcService = mock(VfcService.class);
1113         when(vfcService.fetchNsTemplateData(Mockito.any())).thenReturn(emptyBodyCall());
1114         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService, null);
1115         service.fetchNsTemplateData(request);
1116     }
1117
1118   }