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