add junit function for insert
[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         JobStatus jobStatus = new JobStatus();
254         when(vfcService.getNsLcmJobStatus(jobId, responseId)).thenReturn(successfulCall(jobStatus));
255         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
256
257         Assert.assertSame(jobStatus, service.getNsLcmJobStatus(jobId, responseId));
258     }
259
260     @Test(expected = VfcException.class)
261     public void getNsLcmJobStatusWillThrowExceptionWhenVFCIsNotAvailable() {
262         VfcService vfcService = mock(VfcService.class);
263         String jobId = "1";
264         String responseId = "1";
265         when(vfcService.getNsLcmJobStatus(jobId, responseId)).thenReturn(failedCall("VFC is not available!"));
266         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
267         service.getNsLcmJobStatus(jobId, responseId);
268     }
269
270     @Test(expected = VfcException.class)
271     public void getNsLcmJobStatusWillThrowExceptionWhenVFCResponseError() {
272         VfcService vfcService = mock(VfcService.class);
273         String jobId = "1";
274         String responseId = "1";
275         when(vfcService.getNsLcmJobStatus(jobId, responseId)).thenReturn(emptyBodyCall());
276         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
277         service.getNsLcmJobStatus(jobId, responseId);
278     }
279     
280     @Test
281     public void itCanDeleteNsPackage() {
282         String csarId = "1";
283         DistributionResult result = new DistributionResult();
284         VfcService vfcService = mock(VfcService.class);
285         when(vfcService.deleteNsPackage(csarId)).thenReturn(successfulCall(result));
286         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
287
288         Assert.assertSame(result, service.deleteNsPackage(csarId));
289     }
290
291     @Test(expected = VfcException.class)
292     public void deleteNsPackageWillThrowExceptionWhenVFCIsNotAvailable() {
293         String csarId = "1";
294         VfcService vfcService = mock(VfcService.class);
295         when(vfcService.deleteNsPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
296         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
297         service.deleteNsPackage(csarId);
298     }
299
300     @Test(expected = VfcException.class)
301     public void deleteNsPackageWillThrowExceptionWhenVFCResponseError() {
302         String csarId = "1";
303         VfcService vfcService = mock(VfcService.class);
304         when(vfcService.deleteNsPackage(csarId)).thenReturn(emptyBodyCall());
305         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
306         service.deleteNsPackage(csarId);
307     }
308     
309     @Test
310     public void itCanGetVnfPackages(){
311         ResponseBody result=null;
312         VfcService vfcService = mock(VfcService.class);
313         when(vfcService.getVnfPackages()).thenReturn(successfulCall(result));
314         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
315
316         Assert.assertSame(result, service.getVnfPackages());
317     }
318     
319     @Test
320     public void getVnfPackagesThrowExceptionWhenVFCResponseError(){
321         
322         VfcService vfcService = mock(VfcService.class);
323         when(vfcService.getVnfPackages ()).thenReturn(emptyBodyCall());
324         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
325         service.getVnfPackages();
326     }
327     
328     @Test
329     public void getVnfPackagesThrowException(){
330         VfcService vfcService = mock(VfcService.class);
331         when(vfcService.getVnfPackages ()).thenReturn(failedCall("VFC is not available!"));
332         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
333         service.getVnfPackages();
334     }
335     
336     @Test
337     public void itCanDeleteVFPackage() {
338         String csarId = "1";
339         Job job = new Job();
340         VfcService vfcService = mock(VfcService.class);
341         when(vfcService.deleteVnfPackage(csarId)).thenReturn(successfulCall(job));
342         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
343
344         Assert.assertSame(job, service.deleteVfPackage(csarId));
345     }
346
347     @Test(expected = VfcException.class)
348     public void deleteVfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
349         String csarId = "1";
350         VfcService vfcService = mock(VfcService.class);
351         when(vfcService.deleteVnfPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
352         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
353         service.deleteVfPackage(csarId);
354     }
355
356     @Test(expected = VfcException.class)
357     public void deleteVnfPackageWillThrowExceptionWhenVFCResponseError() {
358         String csarId = "1";
359         VfcService vfcService = mock(VfcService.class);
360         when(vfcService.deleteVnfPackage(csarId)).thenReturn(emptyBodyCall());
361         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
362         service.deleteVnfPackage(csarId);
363     }
364     
365     @Test
366     public void itCanGetNetworkServicePackages() {
367         ResponseBody responseBody = null;
368         VfcService vfcService = mock(VfcService.class);
369         JobStatus jobStatus = new JobStatus();
370         when(vfcService.getNetworkServicePackages()).thenReturn(successfulCall(responseBody));
371         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
372
373         Assert.assertSame(jobStatus, service.getNetworkServicePackages());
374     }
375
376     @Test(expected = VfcException.class)
377     public void getNetworkServicePackagesWillThrowExceptionWhenVFCIsNotAvailable() {
378         VfcService vfcService = mock(VfcService.class);
379         when(vfcService.getNetworkServicePackages()).thenReturn(failedCall("VFC is not available!"));
380         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
381         service.getNetworkServicePackages();
382     }
383
384     @Test(expected = VfcException.class)
385     public void getNetworkServicePackagesWillThrowExceptionWhenVFCResponseError() {
386         VfcService vfcService = mock(VfcService.class);
387         when(vfcService.getNetworkServicePackages()).thenReturn(emptyBodyCall());
388         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
389         service.getNetworkServicePackages();
390     }
391     
392     @Test
393     public void itCanGetPnfPackages(){
394         ResponseBody result=null;
395         VfcService vfcService = mock(VfcService.class);
396         when(vfcService.getPnfPackages()).thenReturn(successfulCall(result));
397         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
398
399         Assert.assertSame(result, service.getPnfPackages());
400     }
401     
402     @Test
403     public void getPnfPackagesThrowExceptionWhenVFCResponseError(){
404         
405         VfcService vfcService = mock(VfcService.class);
406         when(vfcService.getPnfPackages ()).thenReturn(emptyBodyCall());
407         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
408         service.getPnfPackages();
409     }
410     
411     @Test
412     public void getPnfPackagesThrowException(){
413         VfcService vfcService = mock(VfcService.class);
414         when(vfcService.getPnfPackages ()).thenReturn(failedCall("VFC is not available!"));
415         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
416         service.getPnfPackages();
417     }
418     
419     @Test
420     public void itDownLoadNsPackage(){
421         String nsdInfoId="1";
422         ResponseBody result=null;
423         VfcService vfcService = mock(VfcService.class);
424         when(vfcService.downLoadNsPackage(nsdInfoId)).thenReturn(successfulCall(result));
425         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
426
427         Assert.assertSame(result, service.downLoadNsPackage(nsdInfoId));
428     }
429     
430     @Test
431     public void downLoadNsPackagehrowExceptionWhenVFCResponseError(){
432         String nsdInfoId="1";
433         VfcService vfcService = mock(VfcService.class);
434         when(vfcService.downLoadNsPackage (nsdInfoId)).thenReturn(emptyBodyCall());
435         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
436         service.downLoadNsPackage(nsdInfoId);
437     }
438     
439     @Test
440     public void downLoadNsPackageThrowException(){
441         String nsdInfoId="1";
442         VfcService vfcService = mock(VfcService.class);
443         when(vfcService.downLoadNsPackage (nsdInfoId)).thenReturn(failedCall("VFC is not available!"));
444         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
445         service.downLoadNsPackage(nsdInfoId);
446     }
447     
448     @Test
449     public void itDownLoadPnfPackage(){
450         String pnfInfoId="1";
451         ResponseBody result=null;
452         VfcService vfcService = mock(VfcService.class);
453         when(vfcService.downLoadPnfPackage(pnfInfoId)).thenReturn(successfulCall(result));
454         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
455
456         Assert.assertSame(result, service.downLoadPnfPackage(pnfInfoId));
457     }
458     
459     @Test
460     public void downLoadPnfPackagehrowExceptionWhenVFCResponseError(){
461         String pnfInfoId="1";
462         VfcService vfcService = mock(VfcService.class);
463         when(vfcService.downLoadPnfPackage (pnfInfoId)).thenReturn(emptyBodyCall());
464         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
465         service.downLoadPnfPackage(pnfInfoId);
466     }
467     
468     @Test
469     public void downLoadPnfPackageThrowException(){
470         String pnfInfoId="1";
471         VfcService vfcService = mock(VfcService.class);
472         when(vfcService.downLoadPnfPackage (pnfInfoId)).thenReturn(failedCall("VFC is not available!"));
473         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
474         service.downLoadPnfPackage(pnfInfoId);
475     }
476     
477     @Test
478     public void itDownLoadVnfPackage(){
479         String vnfInfoId="1";
480         ResponseBody result=null;
481         VfcService vfcService = mock(VfcService.class);
482         when(vfcService.downLoadVnfPackage(vnfInfoId)).thenReturn(successfulCall(result));
483         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
484
485         Assert.assertSame(result, service.downLoadVnfPackage(vnfInfoId));
486     }
487     
488     @Test
489     public void downLoadVnfPackagehrowExceptionWhenVFCResponseError(){
490         String vnfInfoId="1";
491         VfcService vfcService = mock(VfcService.class);
492         when(vfcService.downLoadVnfPackage (vnfInfoId)).thenReturn(emptyBodyCall());
493         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
494         service.downLoadVnfPackage(vnfInfoId);
495     }
496     
497     @Test
498     public void downLoadVnfPackageThrowException(){
499         String vnfInfoId="1";
500         VfcService vfcService = mock(VfcService.class);
501         when(vfcService.downLoadVnfPackage (vnfInfoId)).thenReturn(failedCall("VFC is not available!"));
502         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
503         service.downLoadVnfPackage(vnfInfoId);
504     }
505     
506     @Test
507     public void itCanDeleteNsdPackage() {
508         String csarId = "1";
509         ResponseBody result=null;
510         VfcService vfcService = mock(VfcService.class);
511         when(vfcService.deleteNsdPackage(csarId)).thenReturn(successfulCall(result));
512         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
513
514         Assert.assertSame(result, service.deleteNsdPackage(csarId));
515     }
516
517     @Test(expected = VfcException.class)
518     public void deleteNsdPackageWillThrowExceptionWhenVFCIsNotAvailable() {
519         String csarId = "1";
520         VfcService vfcService = mock(VfcService.class);
521         when(vfcService.deleteNsdPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
522         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
523         service.deleteNsdPackage(csarId);
524     }
525
526     @Test(expected = VfcException.class)
527     public void deleteNsdPackageWillThrowExceptionWhenVFCResponseError() {
528         String csarId = "1";
529         VfcService vfcService = mock(VfcService.class);
530         when(vfcService.deleteNsdPackage(csarId)).thenReturn(emptyBodyCall());
531         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
532         service.deleteNsdPackage(csarId);
533     }
534     
535     @Test
536     public void itCanDeleteVnfPackage() {
537         String csarId = "1";
538         ResponseBody result=null;
539         Job job = new Job();
540         VfcService vfcService = mock(VfcService.class);
541         when(vfcService.deleteVnfPackage(csarId)).thenReturn(successfulCall(job));
542         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
543
544         Assert.assertSame(job, service.deleteVnfPackage(csarId));
545     }
546
547     @Test(expected = VfcException.class)
548     public void deleteVnfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
549         String csarId = "1";
550         VfcService vfcService = mock(VfcService.class);
551         when(vfcService.deleteVnfPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
552         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
553         service.deleteVnfPackage(csarId);
554     }
555
556     @Test(expected = VfcException.class)
557     public void deleteVnfNsdPackageWillThrowExceptionWhenVFCResponseError() {
558         String csarId = "1";
559         VfcService vfcService = mock(VfcService.class);
560         when(vfcService.deleteVnfPackage(csarId)).thenReturn(emptyBodyCall());
561         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
562         service.deleteVnfPackage(csarId);
563     }
564     
565     @Test
566     public void itCanDeletePnfdPackage() {
567         String csarId = "1";
568         ResponseBody result=null;
569         Job job = new Job();
570         VfcService vfcService = mock(VfcService.class);
571         when(vfcService.deletePnfdPackage(csarId)).thenReturn(successfulCall(result));
572         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
573
574         Assert.assertSame(result, service.deletePnfPackage(csarId));
575     }
576
577     @Test(expected = VfcException.class)
578     public void deletePnfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
579         String csarId = "1";
580         VfcService vfcService = mock(VfcService.class);
581         when(vfcService.deletePnfdPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
582         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
583         service.deletePnfPackage(csarId);
584     }
585
586     @Test(expected = VfcException.class)
587     public void deletePnfPackageWillThrowExceptionWhenVFCResponseError() {
588         String csarId = "1";
589         VfcService vfcService = mock(VfcService.class);
590         when(vfcService.deletePnfdPackage(csarId)).thenReturn(emptyBodyCall());
591         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
592         service.deletePnfPackage(csarId);
593     }
594     
595     @Test
596     public void itCanDeleteNetworkServiceInstance() {
597         String csarId = "1";
598         ResponseBody result=null;
599         Job job = new Job();
600         VfcService vfcService = mock(VfcService.class);
601         when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(successfulCall(result));
602         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
603
604         Assert.assertSame(result, service.deleteNetworkServiceInstance(csarId));
605     }
606
607     @Test(expected = VfcException.class)
608     public void deleteNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() {
609         String csarId = "1";
610         VfcService vfcService = mock(VfcService.class);
611         when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(failedCall("VFC is not available!"));
612         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
613         service.deleteNetworkServiceInstance(csarId);
614     }
615
616     @Test(expected = VfcException.class)
617     public void deleteNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() {
618         String csarId = "1";
619         VfcService vfcService = mock(VfcService.class);
620         when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(emptyBodyCall());
621         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
622         service.deleteNetworkServiceInstance(csarId);
623     }
624     
625     @Test
626     public void itCanCreateNetworkServiceInstance() throws IOException {
627         HttpServletRequest request = mockRequest();
628         ResponseBody result=null;
629         VfcService vfcService = mock(VfcService.class);
630         when(vfcService.createNetworkServiceInstance(anyObject())).thenReturn(successfulCall(result));
631         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
632
633         Assert.assertSame(result, service.createNetworkServiceInstance(request));
634     }
635
636     @Test(expected = VfcException.class)
637     public void createNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
638         HttpServletRequest request = mockRequest();
639         VfcService vfcService = mock(VfcService.class);
640         when(vfcService.createNetworkServiceInstance(anyObject())).thenReturn(failedCall("VFC is not available!"));
641         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
642         service.createNetworkServiceInstance(request);
643     }
644
645     @Test(expected = VfcException.class)
646     public void createNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
647         HttpServletRequest request = mockRequest();
648         VfcService vfcService = mock(VfcService.class);
649         when(vfcService.createNetworkServiceInstance(anyObject())).thenReturn(emptyBodyCall());
650         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
651         service.createNetworkServiceInstance(request);
652     }
653     
654     @Test
655     public void itCanGetNetworkServiceInfo() throws IOException {
656         ResponseBody result=null;
657         nsServiceRsp ns = new nsServiceRsp();
658         VfcService vfcService = mock(VfcService.class);
659         when(vfcService.getNetworkServiceInfo()).thenReturn(successfulCall(ns));
660         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
661
662         Assert.assertSame(result, service.getNetworkServiceInfo());
663     }
664
665     @Test(expected = VfcException.class)
666     public void getNetworkServiceInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
667         VfcService vfcService = mock(VfcService.class);
668         when(vfcService.getNetworkServiceInfo()).thenReturn(failedCall("VFC is not available!"));
669         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
670         service.getNetworkServiceInfo();
671     }
672
673     @Test(expected = VfcException.class)
674     public void getNetworkServiceInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
675         VfcService vfcService = mock(VfcService.class);
676         when(vfcService.getNetworkServiceInfo()).thenReturn(emptyBodyCall());
677         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
678         service.getNetworkServiceInfo();
679     }
680     
681
682     
683     @Test
684     public void itCanHealNetworkServiceInstance() throws IOException {
685         HttpServletRequest request = mockRequest();
686         String csarId = "1";
687         ResponseBody result=null;
688         VfcService vfcService = mock(VfcService.class);
689         //when(vfcService.healNetworkServiceInstance(csarId,anyObject())).thenReturn(successfulCall(result));
690         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
691
692         //Assert.assertSame(result, service.healNetworkServiceInstance(request,csarId));
693         service.healNetworkServiceInstance(request,csarId);
694     }
695
696     @Test(expected = VfcException.class)
697     public void healNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
698         HttpServletRequest request = mockRequest();
699         String csarId = "1";
700         VfcService vfcService = mock(VfcService.class);
701         when(vfcService.healNetworkServiceInstance(csarId,anyObject())).thenReturn(failedCall("VFC is not available!"));
702         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
703         service.healNetworkServiceInstance(request,csarId);
704     }
705
706     @Test(expected = VfcException.class)
707     public void healNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
708         HttpServletRequest request = mockRequest();
709         String csarId = "1";
710         VfcService vfcService = mock(VfcService.class);
711         when(vfcService.healNetworkServiceInstance(csarId,anyObject())).thenReturn(emptyBodyCall());
712         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
713         service.healNetworkServiceInstance(request,csarId);
714     }
715     
716     @Test
717     public void itCanScaleNetworkServiceInstance() throws IOException {
718         HttpServletRequest request = mockRequest();
719         String csarId = "1";
720         ResponseBody result=null;
721         VfcService vfcService = mock(VfcService.class);
722         //when(vfcService.scaleNetworkServiceInstance(csarId,anyObject())).thenReturn(successfulCall(result));
723         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
724
725         Assert.assertSame(result, service.scaleNetworkServiceInstance(request,csarId));
726     }
727
728     @Test(expected = VfcException.class)
729     public void scaleNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
730         HttpServletRequest request = mockRequest();
731         String csarId = "1";
732         VfcService vfcService = mock(VfcService.class);
733         when(vfcService.scaleNetworkServiceInstance(csarId,anyObject())).thenReturn(failedCall("VFC is not available!"));
734         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
735         service.scaleNetworkServiceInstance(request,csarId);
736     }
737
738     @Test(expected = VfcException.class)
739     public void scaleNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
740         HttpServletRequest request = mockRequest();
741         String csarId = "1";
742         VfcService vfcService = mock(VfcService.class);
743         when(vfcService.scaleNetworkServiceInstance(csarId,anyObject())).thenReturn(emptyBodyCall());
744         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
745         service.scaleNetworkServiceInstance(request,csarId);
746     }
747     
748     
749     @Test
750     public void itCaninstantiateNetworkServiceInstance() throws IOException {
751         HttpServletRequest request = mockRequest();
752         String serviceInstanceId="1";
753         ResponseBody result=null;
754         VfcService vfcService = mock(VfcService.class);
755         //when(vfcService.instantiateNetworkServiceInstance(anyObject(),serviceInstanceId)).thenReturn(successfulCall(result));
756         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
757
758         service.instantiateNetworkServiceInstance(request,serviceInstanceId);
759     }
760
761     @Test(expected = VfcException.class)
762     public void instantiateNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
763         HttpServletRequest request = mockRequest();
764         String serviceInstanceId="1";
765         VfcService vfcService = mock(VfcService.class);
766         when(vfcService.instantiateNetworkServiceInstance(anyObject(),serviceInstanceId)).thenReturn(failedCall("VFC is not available!"));
767         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
768         service.instantiateNetworkServiceInstance(request,serviceInstanceId);
769     }
770
771     @Test(expected = VfcException.class)
772     public void instantiateNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
773         HttpServletRequest request = mockRequest();
774         String serviceInstanceId="1";
775         VfcService vfcService = mock(VfcService.class);
776         when(vfcService.instantiateNetworkServiceInstance(anyObject(),serviceInstanceId)).thenReturn(emptyBodyCall());
777         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
778         service.instantiateNetworkServiceInstance(request,serviceInstanceId);
779     }
780     
781     
782     @Test
783     public void itCanTerminateNetworkServiceInstance() throws IOException {
784         HttpServletRequest request = mockRequest();
785         String csarId = "1";
786         ResponseBody result=null;
787         Job job = new Job();
788         VfcService vfcService = mock(VfcService.class);
789         when(vfcService.terminateNetworkServiceInstance(csarId,anyObject())).thenReturn(successfulCall(result));
790         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
791
792         service.terminateNetworkServiceInstance(request,csarId);
793     }
794
795     @Test(expected = VfcException.class)
796     public void terminateNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
797         HttpServletRequest request = mockRequest();
798         String csarId = "1";
799         VfcService vfcService = mock(VfcService.class);
800         //when(vfcService.terminateNetworkServiceInstance(csarId,anyObject())).thenReturn(failedCall("VFC is not available!"));
801         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
802         service.terminateNetworkServiceInstance(request,csarId);
803     }
804
805     @Test(expected = VfcException.class)
806     public void terminateNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
807         HttpServletRequest request = mockRequest();
808         String csarId = "1";
809         VfcService vfcService = mock(VfcService.class);
810         when(vfcService.terminateNetworkServiceInstance(csarId,anyObject())).thenReturn(emptyBodyCall());
811         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
812         service.terminateNetworkServiceInstance(request,csarId);
813     }
814     
815     @Test
816     public void itCreateNetworkServiceData() throws IOException {
817         HttpServletRequest request = mockRequest();
818         ResponseBody result=null;
819         VfcService vfcService = mock(VfcService.class);
820         when(vfcService.createNetworkServiceData(anyObject())).thenReturn(successfulCall(result));
821         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
822
823         Assert.assertSame(result, service.createNetworkServiceData(request));
824     }
825
826     @Test(expected = VfcException.class)
827     public void createNetworkServiceDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
828         HttpServletRequest request = mockRequest();
829         VfcService vfcService = mock(VfcService.class);
830         when(vfcService.createNetworkServiceData(anyObject())).thenReturn(failedCall("VFC is not available!"));
831         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
832         service.createNetworkServiceData(request);
833     }
834
835     @Test(expected = VfcException.class)
836     public void createNetworkServiceDataWillThrowExceptionWhenVFCResponseError() throws IOException {
837         HttpServletRequest request = mockRequest();
838         VfcService vfcService = mock(VfcService.class);
839         when(vfcService.createNetworkServiceData(anyObject())).thenReturn(emptyBodyCall());
840         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
841         service.createNetworkServiceData(request);
842     }
843     
844     @Test
845     public void itCreateVnfData() throws IOException {
846         HttpServletRequest request = mockRequest();
847         ResponseBody result=null;
848         VfcService vfcService = mock(VfcService.class);
849         when(vfcService.createVnfData(anyObject())).thenReturn(successfulCall(result));
850         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
851
852         Assert.assertSame(result, service.createVnfData(request));
853     }
854
855     @Test(expected = VfcException.class)
856     public void createVnfDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
857         HttpServletRequest request = mockRequest();
858         VfcService vfcService = mock(VfcService.class);
859         when(vfcService.createVnfData(anyObject())).thenReturn(failedCall("VFC is not available!"));
860         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
861         service.createVnfData(request);
862     }
863
864     @Test(expected = VfcException.class)
865     public void createVnfDataWillThrowExceptionWhenVFCResponseError() throws IOException {
866         HttpServletRequest request = mockRequest();
867         VfcService vfcService = mock(VfcService.class);
868         when(vfcService.createVnfData(anyObject())).thenReturn(emptyBodyCall());
869         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
870         service.createVnfData(request);
871     }
872     
873     @Test
874     public void itCreatePnfData() throws IOException {
875         HttpServletRequest request = mockRequest();
876         ResponseBody result=null;
877         VfcService vfcService = mock(VfcService.class);
878         when(vfcService.createPnfData(anyObject())).thenReturn(successfulCall(result));
879         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
880
881         Assert.assertSame(result, service.createPnfData(request));
882     }
883
884     @Test(expected = VfcException.class)
885     public void createPnfDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
886         HttpServletRequest request = mockRequest();
887         VfcService vfcService = mock(VfcService.class);
888         when(vfcService.createPnfData(anyObject())).thenReturn(failedCall("VFC is not available!"));
889         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
890         service.createPnfData(request);
891     }
892
893     @Test(expected = VfcException.class)
894     public void createPnfDataWillThrowExceptionWhenVFCResponseError() throws IOException {
895         HttpServletRequest request = mockRequest();
896         VfcService vfcService = mock(VfcService.class);
897         when(vfcService.createPnfData(anyObject())).thenReturn(emptyBodyCall());
898         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
899         service.createPnfData(request);
900     }
901     
902     @Test
903     public void itGetNsdInfo() throws IOException {
904         String nsdId="1";
905         ResponseBody result=null;
906         VfcService vfcService = mock(VfcService.class);
907         when(vfcService.getNsdInfo(nsdId)).thenReturn(successfulCall(result));
908         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
909
910         Assert.assertSame(result, service.getNsdInfo(nsdId));
911     }
912
913     @Test(expected = VfcException.class)
914     public void getNsdInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
915         String nsdId="1";
916         VfcService vfcService = mock(VfcService.class);
917         when(vfcService.getNsdInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
918         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
919         service.getNsdInfo(nsdId);
920     }
921
922     @Test(expected = VfcException.class)
923     public void getNsdInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
924         String nsdId="1";
925         VfcService vfcService = mock(VfcService.class);
926         when(vfcService.getNsdInfo(nsdId)).thenReturn(emptyBodyCall());
927         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
928         service.getNsdInfo(nsdId);
929     }
930     
931     @Test
932     public void itGetVnfInfo() throws IOException {
933         String nsdId="1";
934         ResponseBody result=null;
935         VfcService vfcService = mock(VfcService.class);
936         when(vfcService.getVnfInfo(nsdId)).thenReturn(successfulCall(result));
937         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
938
939         Assert.assertSame(result, service.getVnfInfo(nsdId));
940     }
941
942     @Test(expected = VfcException.class)
943     public void getVnfInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
944         String nsdId="1";
945         VfcService vfcService = mock(VfcService.class);
946         when(vfcService.getVnfInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
947         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
948         service.getVnfInfo(nsdId);
949     }
950
951     @Test(expected = VfcException.class)
952     public void getVnfInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
953         String nsdId="1";
954         VfcService vfcService = mock(VfcService.class);
955         when(vfcService.getVnfInfo(nsdId)).thenReturn(emptyBodyCall());
956         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
957         service.getVnfInfo(nsdId);
958     }
959     
960     @Test
961     public void itGetPnfInfo() throws IOException {
962         String nsdId="1";
963         ResponseBody result=null;
964         VfcService vfcService = mock(VfcService.class);
965         when(vfcService.getPnfInfo(nsdId)).thenReturn(successfulCall(result));
966         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
967
968         Assert.assertSame(result, service.getPnfInfo(nsdId));
969     }
970
971     @Test(expected = VfcException.class)
972     public void getPnfInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
973         String nsdId="1";
974         VfcService vfcService = mock(VfcService.class);
975         when(vfcService.getPnfInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
976         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
977         service.getPnfInfo(nsdId);
978     }
979
980     @Test(expected = VfcException.class)
981     public void getPnfInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
982         String nsdId="1";
983         VfcService vfcService = mock(VfcService.class);
984         when(vfcService.getPnfInfo(nsdId)).thenReturn(emptyBodyCall());
985         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
986         service.getPnfInfo(nsdId);
987     }
988     
989     @Test
990     public void itCanListNsTemplates() throws IOException {
991         ResponseBody result=null;
992         VfcService vfcService = mock(VfcService.class);
993         when(vfcService.listNsTemplates()).thenReturn(successfulCall(result));
994         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
995
996         Assert.assertSame(result, service.listNsTemplates());
997     }
998
999     @Test(expected = VfcException.class)
1000     public void listNsTemplatesWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
1001         VfcService vfcService = mock(VfcService.class);
1002         when(vfcService.listNsTemplates()).thenReturn(failedCall("VFC is not available!"));
1003         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1004         service.listNsTemplates();
1005     }
1006
1007     @Test(expected = VfcException.class)
1008     public void listNsTemplatesWillThrowExceptionWhenVFCResponseError() throws IOException {
1009         VfcService vfcService = mock(VfcService.class);
1010         when(vfcService.listNsTemplates()).thenReturn(emptyBodyCall());
1011         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1012         service.listNsTemplates();
1013     }
1014     
1015     @Test
1016     public void itCanGetVnfInfoById() throws IOException {
1017         String nsdId="1";
1018         ResponseBody result=null;
1019         VfcService vfcService = mock(VfcService.class);
1020         when(vfcService.getVnfInfoById(nsdId)).thenReturn(successfulCall(result));
1021         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1022
1023         Assert.assertSame(result, service.getVnfInfoById(nsdId));
1024     }
1025
1026     @Test(expected = VfcException.class)
1027     public void getVnfInfoByIdWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
1028         String nsdId="1";
1029         VfcService vfcService = mock(VfcService.class);
1030         when(vfcService.getVnfInfoById(nsdId)).thenReturn(failedCall("VFC is not available!"));
1031         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1032         service.getVnfInfoById(nsdId);
1033     }
1034
1035     @Test(expected = VfcException.class)
1036     public void getVnfInfoByIdWillThrowExceptionWhenVFCResponseError() throws IOException {
1037         String nsdId="1";
1038         VfcService vfcService = mock(VfcService.class);
1039         when(vfcService.getVnfInfoById(nsdId)).thenReturn(emptyBodyCall());
1040         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1041         service.getVnfInfoById(nsdId);
1042     }
1043     
1044     @Test
1045     public void itCanFetchNsTemplateData() throws IOException {
1046         HttpServletRequest request = mockRequest();
1047         ResponseBody result=null;
1048         VfcService vfcService = mock(VfcService.class);
1049         when(vfcService.fetchNsTemplateData(anyObject())).thenReturn(successfulCall(result));
1050         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1051
1052         Assert.assertSame(result, service.fetchNsTemplateData(request));
1053     }
1054
1055     @Test(expected = VfcException.class)
1056     public void fetchNsTemplateDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
1057         HttpServletRequest request = mockRequest();
1058         VfcService vfcService = mock(VfcService.class);
1059         when(vfcService.fetchNsTemplateData(anyObject())).thenReturn(failedCall("VFC is not available!"));
1060         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1061         service.fetchNsTemplateData(request);
1062     }
1063
1064     @Test(expected = VfcException.class)
1065     public void fetchNsTemplateDataWillThrowExceptionWhenVFCResponseError() throws IOException {
1066         HttpServletRequest request = mockRequest();
1067         VfcService vfcService = mock(VfcService.class);
1068         when(vfcService.fetchNsTemplateData(anyObject())).thenReturn(emptyBodyCall());
1069         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
1070         service.fetchNsTemplateData(request);
1071     }
1072
1073   }