2  * Copyright 2016-2017 ZTE Corporation.
 
   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
 
   8  *     http://www.apache.org/licenses/LICENSE-2.0
 
  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.
 
  16 package org.onap.usecaseui.server.service.lcm.impl;
 
  18 import org.apache.commons.lang3.StringUtils;
 
  19 import org.junit.Assert;
 
  20 import org.junit.Test;
 
  21 import org.mockito.Mockito;
 
  22 import org.onap.usecaseui.server.bean.ServiceBean;
 
  23 import org.onap.usecaseui.server.bean.lcm.VfNsPackageInfo;
 
  24 import org.onap.usecaseui.server.service.lcm.PackageDistributionService;
 
  25 import org.onap.usecaseui.server.service.lcm.ServiceLcmService;
 
  26 import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService;
 
  27 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.VimInfo;
 
  28 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.VimInfoRsp;
 
  29 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.nsServiceRsp;
 
  30 import org.onap.usecaseui.server.service.lcm.domain.sdc.SDCCatalogService;
 
  31 import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.SDCServiceTemplate;
 
  32 import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.Vnf;
 
  33 import org.onap.usecaseui.server.service.lcm.domain.sdc.exceptions.SDCCatalogException;
 
  34 import org.onap.usecaseui.server.service.lcm.domain.vfc.VfcService;
 
  35 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Csar;
 
  36 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.DistributionResult;
 
  37 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Job;
 
  38 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.JobStatus;
 
  39 import org.onap.usecaseui.server.service.lcm.domain.vfc.exceptions.VfcException;
 
  41 import okhttp3.ResponseBody;
 
  42 import retrofit2.Call;
 
  44 import java.io.IOException;
 
  45 import java.util.ArrayList;
 
  46 import java.util.Collections;
 
  47 import java.util.List;
 
  49 import jakarta.servlet.ReadListener;
 
  50 import jakarta.servlet.ServletInputStream;
 
  51 import jakarta.servlet.http.HttpServletRequest;
 
  53 import static org.hamcrest.CoreMatchers.equalTo;
 
  54 import static org.mockito.ArgumentMatchers.eq;
 
  55 import static org.mockito.Mockito.mock;
 
  56 import static org.mockito.Mockito.when;
 
  57 import static org.onap.usecaseui.server.service.lcm.domain.sdc.consts.SDCConsts.*;
 
  58 import static org.onap.usecaseui.server.util.CallStub.emptyBodyCall;
 
  59 import static org.onap.usecaseui.server.util.CallStub.failedCall;
 
  60 import static org.onap.usecaseui.server.util.CallStub.successfulCall;
 
  62 public class DefaultPackageDistributionServiceTest {
 
  65     private HttpServletRequest mockRequest() throws IOException {
 
  66         HttpServletRequest request = mock(HttpServletRequest.class);
 
  67         when(request.getContentLength()).thenReturn(0);
 
  68         ServletInputStream inStream = new ServletInputStream() {
 
  70             public boolean isFinished() {
 
  75             public boolean isReady() {
 
  80             public void setReadListener(ReadListener readListener) {
 
  85             public int read() throws IOException {
 
  89         when(request.getInputStream()).thenReturn(inStream);
 
  94     public void itCanRetrievePackageFromSDCAndAAI() {
 
  95         List<SDCServiceTemplate> serviceTemplate = Collections.singletonList(new SDCServiceTemplate("1", "1", "service", "V1","", ""));
 
  97         o.setInvariantUUID("2");
 
 100         List<Vnf> vnf = Collections.singletonList(o);
 
 101         SDCCatalogService sdcService = newSDCService(serviceTemplate, vnf);
 
 103         List<VimInfo> vim = Collections.singletonList(new VimInfo("owner", "regionId"));
 
 104         AAIService aaiService = newAAIService(vim);
 
 106         PackageDistributionService service = new DefaultPackageDistributionService(sdcService, null);
 
 108         Assert.assertThat(service.retrievePackageInfo(), equalTo(new VfNsPackageInfo(serviceTemplate, vnf)));
 
 111     private AAIService newAAIService(List<VimInfo> vim) {
 
 112         AAIService aaiService = mock(AAIService.class);
 
 113         VimInfoRsp rsp = new VimInfoRsp();
 
 114         rsp.setCloudRegion(vim);
 
 115         Call<VimInfoRsp> vimCall = successfulCall(rsp);
 
 116         when(aaiService.listVimInfo()).thenReturn(vimCall);
 
 120     private SDCCatalogService newSDCService(List<SDCServiceTemplate> serviceTemplate, List<Vnf> vnf) {
 
 121         SDCCatalogService sdcService = mock(SDCCatalogService.class);
 
 123         Call<List<SDCServiceTemplate>> serviceCall = successfulCall(serviceTemplate);
 
 124         when(sdcService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(serviceCall);
 
 126         Call<List<Vnf>> vnfCall = successfulCall(vnf);
 
 127         when(sdcService.listResources(RESOURCETYPE_VF)).thenReturn(vnfCall);
 
 132     public void retrievePackageWillThrowExceptionWhenSDCIsNotAvailable() {
 
 133         SDCCatalogService sdcService = mock(SDCCatalogService.class);
 
 134         Call<List<Vnf>> serviceCall = failedCall("SDC is not available!");
 
 135         Call<List<SDCServiceTemplate>> serviceCall1 = failedCall("SDC is not available!");
 
 136         when(sdcService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(serviceCall1);
 
 137         when(sdcService.listResources(RESOURCETYPE_VF)).thenReturn(serviceCall);
 
 139         List<VimInfo> vim = Collections.singletonList(new VimInfo("owner", "regionId"));
 
 140         AAIService aaiService = newAAIService(vim);
 
 142         PackageDistributionService service = new DefaultPackageDistributionService(sdcService, null);
 
 143         service.retrievePackageInfo();
 
 147     public void retrievePackageWillBeEmptyWhenNoNsServiceAndVfInSDC() {
 
 148         SDCCatalogService sdcService = mock(SDCCatalogService.class);
 
 149         Call<List<SDCServiceTemplate>> serviceCall = emptyBodyCall();
 
 150         when(sdcService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(serviceCall);
 
 152         Call<List<Vnf>> resourceCall = emptyBodyCall();
 
 153         when(sdcService.listResources(RESOURCETYPE_VF)).thenReturn(resourceCall);
 
 155         PackageDistributionService service = new DefaultPackageDistributionService(sdcService, null);
 
 156         VfNsPackageInfo vfNsPackageInfo = service.retrievePackageInfo();
 
 158         Assert.assertTrue("ns should be empty!", vfNsPackageInfo.getNsPackage().isEmpty());
 
 159         Assert.assertTrue("vf should be empty!", vfNsPackageInfo.getVnfPackages().isEmpty());
 
 163     public void itCanPostNsPackageToVFC() {
 
 164         VfcService vfcService = mock(VfcService.class);
 
 165         Csar csar = new Csar();
 
 166         DistributionResult result = new DistributionResult();
 
 167         result.setStatus("status");
 
 168         result.setStatusDescription("description");
 
 169         result.setErrorCode("errorcode");
 
 170         when(vfcService.distributeNsPackage(csar)).thenReturn(successfulCall(result));
 
 171         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 173         Assert.assertSame(result, service.postNsPackage(csar));
 
 176     @Test(expected = VfcException.class)
 
 177     public void postNsPackageWillThrowExceptionWhenVFCIsNotAvailable() {
 
 178         VfcService vfcService = mock(VfcService.class);
 
 179         Csar csar = new Csar();
 
 180         when(vfcService.distributeNsPackage(csar)).thenReturn(failedCall("VFC is not available!"));
 
 181         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 182         service.postNsPackage(csar);
 
 185     @Test(expected = VfcException.class)
 
 186     public void postNsPackageWillThrowExceptionWhenVFCResponseError() {
 
 187         VfcService vfcService = mock(VfcService.class);
 
 188         Csar csar = new Csar();
 
 189         when(vfcService.distributeNsPackage(csar)).thenReturn(emptyBodyCall());
 
 190         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 191         service.postNsPackage(csar);
 
 195     public void itCanPostVnfPackageToVFC() {
 
 196         VfcService vfcService = mock(VfcService.class);
 
 197         Csar csar = new Csar();
 
 199         when(vfcService.distributeVnfPackage(csar)).thenReturn(successfulCall(job));
 
 200         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 202         Assert.assertSame(job, service.postVfPackage(csar));
 
 205     @Test(expected = VfcException.class)
 
 206     public void postVnfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
 
 207         VfcService vfcService = mock(VfcService.class);
 
 208         Csar csar = new Csar();
 
 209         when(vfcService.distributeVnfPackage(csar)).thenReturn(failedCall("VFC is not available!"));
 
 210         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 211         service.postVfPackage(csar);
 
 214     @Test(expected = VfcException.class)
 
 215     public void postVnfPackageWillThrowExceptionWhenVFCResponseError() {
 
 216         VfcService vfcService = mock(VfcService.class);
 
 217         Csar csar = new Csar();
 
 218         when(vfcService.distributeVnfPackage(csar)).thenReturn(emptyBodyCall());
 
 219         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 220         service.postVfPackage(csar);
 
 224     public void itCanGetJobStatusFromVFC() {
 
 225         VfcService vfcService = mock(VfcService.class);
 
 227         String responseId = "1";
 
 228         JobStatus jobStatus = new JobStatus();
 
 229         when(vfcService.getJobStatus(jobId, responseId)).thenReturn(successfulCall(jobStatus));
 
 230         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 232         Assert.assertSame(jobStatus, service.getJobStatus(jobId, responseId));
 
 235     @Test(expected = VfcException.class)
 
 236     public void getJobStatusWillThrowExceptionWhenVFCIsNotAvailable() {
 
 237         VfcService vfcService = mock(VfcService.class);
 
 239         String responseId = "1";
 
 240         when(vfcService.getJobStatus(jobId, responseId)).thenReturn(failedCall("VFC is not available!"));
 
 241         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 242         service.getJobStatus(jobId, responseId);
 
 245     @Test(expected = VfcException.class)
 
 246     public void getJobStatusWillThrowExceptionWhenVFCResponseError() {
 
 247         VfcService vfcService = mock(VfcService.class);
 
 249         String responseId = "1";
 
 250         when(vfcService.getJobStatus(jobId, responseId)).thenReturn(emptyBodyCall());
 
 251         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 252         service.getJobStatus(jobId, responseId);
 
 256     public void itCanGetNsLcmJobStatusFromVFC() {
 
 257         VfcService vfcService = mock(VfcService.class);
 
 259         String responseId = "1";
 
 260         String serviceId= "1";
 
 261         String operationType= "1";
 
 262         JobStatus jobStatus = new JobStatus();
 
 263         when(vfcService.getNsLcmJobStatus(jobId, responseId)).thenReturn(successfulCall(jobStatus));
 
 264         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 266         Assert.assertSame(jobStatus, service.getNsLcmJobStatus(serviceId,jobId, responseId,operationType));
 
 269     @Test(expected = VfcException.class)
 
 270     public void getNsLcmJobStatusWillThrowExceptionWhenVFCIsNotAvailable() {
 
 271         VfcService vfcService = mock(VfcService.class);
 
 273         String responseId = "1";
 
 274         String serviceId= "1";
 
 275         String operationType= "1";
 
 276         when(vfcService.getNsLcmJobStatus(jobId, responseId)).thenReturn(failedCall("VFC is not available!"));
 
 277         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 278         service.getNsLcmJobStatus(serviceId,jobId, responseId,operationType);
 
 281     @Test(expected = VfcException.class)
 
 282     public void getNsLcmJobStatusWillThrowExceptionWhenVFCResponseError() {
 
 283         VfcService vfcService = mock(VfcService.class);
 
 285         String responseId = "1";
 
 286         String serviceId= "1";
 
 287         String operationType= "1";
 
 288         when(vfcService.getNsLcmJobStatus(jobId, responseId)).thenReturn(emptyBodyCall());
 
 289         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 290         service.getNsLcmJobStatus(serviceId,jobId, responseId,operationType);
 
 294     public void itCanDeleteNsPackage() {
 
 296         DistributionResult result = new DistributionResult();
 
 297         VfcService vfcService = mock(VfcService.class);
 
 298         when(vfcService.deleteNsPackage(csarId)).thenReturn(successfulCall(result));
 
 299         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 301         Assert.assertSame(result, service.deleteNsPackage(csarId));
 
 304     @Test(expected = VfcException.class)
 
 305     public void deleteNsPackageWillThrowExceptionWhenVFCIsNotAvailable() {
 
 307         VfcService vfcService = mock(VfcService.class);
 
 308         when(vfcService.deleteNsPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
 
 309         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 310         service.deleteNsPackage(csarId);
 
 313     @Test(expected = VfcException.class)
 
 314     public void deleteNsPackageWillThrowExceptionWhenVFCResponseError() {
 
 316         VfcService vfcService = mock(VfcService.class);
 
 317         when(vfcService.deleteNsPackage(csarId)).thenReturn(emptyBodyCall());
 
 318         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 319         service.deleteNsPackage(csarId);
 
 323     public void itCanGetVnfPackages(){
 
 324         ResponseBody result=null;
 
 325         VfcService vfcService = mock(VfcService.class);
 
 326         when(vfcService.getVnfPackages()).thenReturn(successfulCall(result));
 
 327         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 329         Assert.assertSame(result, service.getVnfPackages());
 
 333     public void getVnfPackagesThrowExceptionWhenVFCResponseError(){
 
 335         VfcService vfcService = mock(VfcService.class);
 
 336         when(vfcService.getVnfPackages ()).thenReturn(emptyBodyCall());
 
 337         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 338         service.getVnfPackages();
 
 342     public void getVnfPackagesThrowException(){
 
 343         VfcService vfcService = mock(VfcService.class);
 
 344         when(vfcService.getVnfPackages ()).thenReturn(failedCall("VFC is not available!"));
 
 345         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 346         service.getVnfPackages();
 
 350     public void itCanDeleteVFPackage() {
 
 353         VfcService vfcService = mock(VfcService.class);
 
 354         when(vfcService.deleteVnfPackage(csarId)).thenReturn(successfulCall(job));
 
 355         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 357         Assert.assertSame(job, service.deleteVfPackage(csarId));
 
 360     @Test(expected = VfcException.class)
 
 361     public void deleteVfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
 
 363         VfcService vfcService = mock(VfcService.class);
 
 364         when(vfcService.deleteVnfPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
 
 365         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 366         service.deleteVfPackage(csarId);
 
 369     @Test(expected = VfcException.class)
 
 370     public void deleteVnfPackageWillThrowExceptionWhenVFCResponseError() {
 
 372         VfcService vfcService = mock(VfcService.class);
 
 373         when(vfcService.deleteVnfPackage(csarId)).thenReturn(emptyBodyCall());
 
 374         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 375         service.deleteVnfPackage(csarId);
 
 379     public void itCanGetNetworkServicePackages() {
 
 380         ResponseBody responseBody = null;
 
 381         VfcService vfcService = mock(VfcService.class);
 
 382         JobStatus jobStatus = new JobStatus();
 
 383         when(vfcService.getNetworkServicePackages()).thenReturn(successfulCall(responseBody));
 
 384         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 386         Assert.assertSame(jobStatus, service.getNetworkServicePackages());
 
 390     public void getNetworkServicePackagesWillThrowExceptionWhenVFCIsNotAvailable() {
 
 391         VfcService vfcService = mock(VfcService.class);
 
 392         when(vfcService.getNetworkServicePackages()).thenReturn(failedCall("VFC is not available!"));
 
 393         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 394         service.getNetworkServicePackages();
 
 398     public void getNetworkServicePackagesWillThrowExceptionWhenVFCResponseError() {
 
 399         VfcService vfcService = mock(VfcService.class);
 
 400         when(vfcService.getNetworkServicePackages()).thenReturn(emptyBodyCall());
 
 401         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 402         service.getNetworkServicePackages();
 
 406     public void itCanGetPnfPackages(){
 
 407         ResponseBody result=null;
 
 408         VfcService vfcService = mock(VfcService.class);
 
 409         when(vfcService.getPnfPackages()).thenReturn(successfulCall(result));
 
 410         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 412         Assert.assertSame(result, service.getPnfPackages());
 
 416     public void getPnfPackagesThrowExceptionWhenVFCResponseError(){
 
 418         VfcService vfcService = mock(VfcService.class);
 
 419         when(vfcService.getPnfPackages ()).thenReturn(emptyBodyCall());
 
 420         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 421         service.getPnfPackages();
 
 425     public void getPnfPackagesThrowException(){
 
 426         VfcService vfcService = mock(VfcService.class);
 
 427         when(vfcService.getPnfPackages ()).thenReturn(failedCall("VFC is not available!"));
 
 428         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 429         service.getPnfPackages();
 
 433     public void itDownLoadNsPackage(){
 
 434         String nsdInfoId="1";
 
 435         ResponseBody result=null;
 
 436         VfcService vfcService = mock(VfcService.class);
 
 437         when(vfcService.downLoadNsPackage(nsdInfoId)).thenReturn(successfulCall(result));
 
 438         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 440         Assert.assertTrue(StringUtils.isNotEmpty(service.downLoadNsPackage(nsdInfoId)));
 
 444     public void downLoadNsPackagehrowExceptionWhenVFCResponseError(){
 
 445         String nsdInfoId="1";
 
 446         VfcService vfcService = mock(VfcService.class);
 
 447         when(vfcService.downLoadNsPackage (nsdInfoId)).thenReturn(emptyBodyCall());
 
 448         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 449         service.downLoadNsPackage(nsdInfoId);
 
 453     public void downLoadNsPackageThrowException(){
 
 454         String nsdInfoId="1";
 
 455         VfcService vfcService = mock(VfcService.class);
 
 456         when(vfcService.downLoadNsPackage (nsdInfoId)).thenReturn(failedCall("VFC is not available!"));
 
 457         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 458         service.downLoadNsPackage(nsdInfoId);
 
 462     public void itDownLoadPnfPackage(){
 
 463         String pnfInfoId="1";
 
 464         ResponseBody result=null;
 
 465         VfcService vfcService = mock(VfcService.class);
 
 466         when(vfcService.downLoadPnfPackage(pnfInfoId)).thenReturn(successfulCall(result));
 
 467         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 469         Assert.assertSame(result, service.downLoadPnfPackage(pnfInfoId));
 
 473     public void downLoadPnfPackagehrowExceptionWhenVFCResponseError(){
 
 474         String pnfInfoId="1";
 
 475         VfcService vfcService = mock(VfcService.class);
 
 476         when(vfcService.downLoadPnfPackage (pnfInfoId)).thenReturn(emptyBodyCall());
 
 477         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 478         service.downLoadPnfPackage(pnfInfoId);
 
 482     public void downLoadPnfPackageThrowException(){
 
 483         String pnfInfoId="1";
 
 484         VfcService vfcService = mock(VfcService.class);
 
 485         when(vfcService.downLoadPnfPackage (pnfInfoId)).thenReturn(failedCall("VFC is not available!"));
 
 486         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 487         service.downLoadPnfPackage(pnfInfoId);
 
 491     public void itDownLoadVnfPackage(){
 
 492         String vnfInfoId="1";
 
 493         ResponseBody result=null;
 
 494         VfcService vfcService = mock(VfcService.class);
 
 495         when(vfcService.downLoadVnfPackage(vnfInfoId)).thenReturn(successfulCall(result));
 
 496         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 498         Assert.assertSame("{\"status\":\"FAILED\"}", service.downLoadVnfPackage(vnfInfoId));
 
 502     public void downLoadVnfPackagehrowExceptionWhenVFCResponseError(){
 
 503         String vnfInfoId="1";
 
 504         VfcService vfcService = mock(VfcService.class);
 
 505         when(vfcService.downLoadVnfPackage (vnfInfoId)).thenReturn(failedCall("VFC is not available!"));
 
 506         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 507         service.downLoadVnfPackage(vnfInfoId);
 
 511     public void downLoadVnfPackageThrowException(){
 
 512         String vnfInfoId="1";
 
 513         VfcService vfcService = mock(VfcService.class);
 
 514         when(vfcService.downLoadVnfPackage (vnfInfoId)).thenReturn(failedCall("VFC is not available!"));
 
 515         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 516         service.downLoadVnfPackage(vnfInfoId);
 
 520     public void itCanDeleteNsdPackage() {
 
 522         ResponseBody result=null;
 
 523         VfcService vfcService = mock(VfcService.class);
 
 524         when(vfcService.deleteNsdPackage(csarId)).thenReturn(successfulCall(result));
 
 525         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 527         Assert.assertSame("{\"status\":\"SUCCESS\"}", service.deleteNsdPackage(csarId));
 
 531     public void deleteNsdPackageWillThrowExceptionWhenVFCIsNotAvailable() {
 
 533         VfcService vfcService = mock(VfcService.class);
 
 534         when(vfcService.deleteNsdPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
 
 535         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 536         service.deleteNsdPackage(csarId);
 
 540     public void deleteNsdPackageWillThrowExceptionWhenVFCResponseError() {
 
 542         VfcService vfcService = mock(VfcService.class);
 
 543         when(vfcService.deleteNsdPackage(csarId)).thenReturn(emptyBodyCall());
 
 544         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 545         service.deleteNsdPackage(csarId);
 
 549     public void itCanDeleteVnfPackage() {
 
 551         ResponseBody result=null;
 
 553         VfcService vfcService = mock(VfcService.class);
 
 554         when(vfcService.deleteVnfPackage(csarId)).thenReturn(successfulCall(job));
 
 555         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 557         Assert.assertSame(job, service.deleteVnfPackage(csarId));
 
 561     public void deleteVnfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
 
 563         VfcService vfcService = mock(VfcService.class);
 
 564         when(vfcService.deleteVnfPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
 
 565         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 566         service.deleteVnfPackage(csarId);
 
 569     @Test(expected = VfcException.class)
 
 570     public void deleteVnfNsdPackageWillThrowExceptionWhenVFCResponseError() {
 
 572         VfcService vfcService = mock(VfcService.class);
 
 573         when(vfcService.deleteVnfPackage(csarId)).thenReturn(emptyBodyCall());
 
 574         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 575         service.deleteVnfPackage(csarId);
 
 579     public void itCanDeletePnfdPackage() {
 
 581         ResponseBody result=null;
 
 583         VfcService vfcService = mock(VfcService.class);
 
 584         when(vfcService.deletePnfdPackage(csarId)).thenReturn(successfulCall(result));
 
 585         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 587         Assert.assertSame("{\"status\":\"SUCCESS\"}", service.deletePnfPackage(csarId));
 
 591     public void deletePnfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
 
 593         VfcService vfcService = mock(VfcService.class);
 
 594         when(vfcService.deletePnfdPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
 
 595         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 596         service.deletePnfPackage(csarId);
 
 600     public void deletePnfPackageWillThrowExceptionWhenVFCResponseError() {
 
 602         VfcService vfcService = mock(VfcService.class);
 
 603         when(vfcService.deletePnfdPackage(csarId)).thenReturn(emptyBodyCall());
 
 604         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 605         service.deletePnfPackage(csarId);
 
 609     public void itCanDeleteNetworkServiceInstance() {
 
 611         ResponseBody result=null;
 
 613         VfcService vfcService = mock(VfcService.class);
 
 614         when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(successfulCall(result));
 
 615         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 617         Assert.assertSame("{\"status\":\"SUCCESS\"}", service.deleteNetworkServiceInstance(csarId));
 
 621     public void deleteNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() {
 
 623         VfcService vfcService = mock(VfcService.class);
 
 624         when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(failedCall("VFC is not available!"));
 
 625         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 626         service.deleteNetworkServiceInstance(csarId);
 
 630     public void deleteNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() {
 
 632         VfcService vfcService = mock(VfcService.class);
 
 633         when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(emptyBodyCall());
 
 634         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 635         service.deleteNetworkServiceInstance(csarId);
 
 639     public void itCanCreateNetworkServiceInstance() throws IOException {
 
 640         HttpServletRequest request = mockRequest();
 
 641         ResponseBody result=null;
 
 642         VfcService vfcService = mock(VfcService.class);
 
 643         when(vfcService.createNetworkServiceInstance(Mockito.any())).thenReturn(successfulCall(result));
 
 644         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 646         Assert.assertSame("{\"status\":\"FAILED\"}", service.createNetworkServiceInstance(request));
 
 650     public void createNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
 
 651         HttpServletRequest request = mockRequest();
 
 652         VfcService vfcService = mock(VfcService.class);
 
 653         when(vfcService.createNetworkServiceInstance(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
 
 654         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 655         service.createNetworkServiceInstance(request);
 
 659     public void createNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
 
 660         HttpServletRequest request = mockRequest();
 
 661         VfcService vfcService = mock(VfcService.class);
 
 662         when(vfcService.createNetworkServiceInstance(Mockito.any())).thenReturn(emptyBodyCall());
 
 663         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 664         service.createNetworkServiceInstance(request);
 
 668     public void itCanGetNetworkServiceInfo() throws IOException {
 
 669         nsServiceRsp ns = new nsServiceRsp();
 
 670         List<String> list = new ArrayList<>();
 
 671         String s = "{\"nsInstanceId\":\"nsInstanceId\"}";
 
 673         ns.setNsServices(list);
 
 674         VfcService vfcService = mock(VfcService.class);
 
 675         when(vfcService.getNetworkServiceInfo()).thenReturn(successfulCall(ns));
 
 676         ServiceLcmService serviceLcmService = mock(ServiceLcmService.class);
 
 677         DefaultPackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 678         service.setServiceLcmService(serviceLcmService);
 
 679         when(serviceLcmService.getServiceBeanByServiceInStanceId("nsInstanceId")).thenReturn(new ServiceBean());
 
 680         Assert.assertNotNull( service.getNetworkServiceInfo());
 
 684     public void getNetworkServiceInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
 
 685         VfcService vfcService = mock(VfcService.class);
 
 686         when(vfcService.getNetworkServiceInfo()).thenReturn(failedCall("VFC is not available!"));
 
 687         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 688         service.getNetworkServiceInfo();
 
 692     public void getNetworkServiceInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
 
 693         VfcService vfcService = mock(VfcService.class);
 
 694         when(vfcService.getNetworkServiceInfo()).thenReturn(emptyBodyCall());
 
 695         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 696         service.getNetworkServiceInfo();
 
 702     public void itCanHealNetworkServiceInstance() throws IOException {
 
 703         HttpServletRequest request = mockRequest();
 
 705         ResponseBody result=null;
 
 706         VfcService vfcService = mock(VfcService.class);
 
 707         //when(vfcService.healNetworkServiceInstance(csarId,anyObject())).thenReturn(successfulCall(result));
 
 708         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 710         //Assert.assertSame(result, service.healNetworkServiceInstance(request,csarId));
 
 711         service.healNetworkServiceInstance(request,csarId);
 
 715     public void healNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
 
 716         HttpServletRequest request = mockRequest();
 
 718         VfcService vfcService = mock(VfcService.class);
 
 719         when(vfcService.healNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(failedCall("VFC is not available!"));
 
 720         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 721         service.healNetworkServiceInstance(request,csarId);
 
 725     public void healNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
 
 726         HttpServletRequest request = mockRequest();
 
 728         VfcService vfcService = mock(VfcService.class);
 
 729         when(vfcService.healNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(emptyBodyCall());
 
 730         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 731         service.healNetworkServiceInstance(request,csarId);
 
 735     public void itCanScaleNetworkServiceInstance() throws IOException {
 
 736         HttpServletRequest request = mockRequest();
 
 738         ResponseBody result=null;
 
 739         VfcService vfcService = mock(VfcService.class);
 
 740         //when(vfcService.scaleNetworkServiceInstance(csarId,anyObject())).thenReturn(successfulCall(result));
 
 741         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 743         Assert.assertTrue(StringUtils.isNotEmpty(service.scaleNetworkServiceInstance(request,csarId)));
 
 747     public void scaleNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
 
 748         HttpServletRequest request = mockRequest();
 
 750         VfcService vfcService = mock(VfcService.class);
 
 751         when(vfcService.scaleNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(failedCall("VFC is not available!"));
 
 752         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 753         service.scaleNetworkServiceInstance(request,csarId);
 
 757     public void scaleNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
 
 758         HttpServletRequest request = mockRequest();
 
 760         VfcService vfcService = mock(VfcService.class);
 
 761         when(vfcService.scaleNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(emptyBodyCall());
 
 762         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 763         service.scaleNetworkServiceInstance(request,csarId);
 
 768     public void itCaninstantiateNetworkServiceInstance() throws IOException {
 
 769         HttpServletRequest request = mockRequest();
 
 770         String serviceInstanceId="1";
 
 771         ResponseBody result=null;
 
 772         VfcService vfcService = mock(VfcService.class);
 
 773         //when(vfcService.instantiateNetworkServiceInstance(anyObject(),serviceInstanceId)).thenReturn(successfulCall(result));
 
 774         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 776         service.instantiateNetworkServiceInstance(request,serviceInstanceId);
 
 780     public void instantiateNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
 
 781         HttpServletRequest request = mockRequest();
 
 782         String serviceInstanceId="1";
 
 783         VfcService vfcService = mock(VfcService.class);
 
 784         when(vfcService.instantiateNetworkServiceInstance(Mockito.any(),eq(serviceInstanceId))).thenReturn(failedCall("VFC is not available!"));
 
 785         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 786         service.instantiateNetworkServiceInstance(request,serviceInstanceId);
 
 790     public void instantiateNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
 
 791         HttpServletRequest request = mockRequest();
 
 792         String serviceInstanceId="1";
 
 793         VfcService vfcService = mock(VfcService.class);
 
 794         when(vfcService.instantiateNetworkServiceInstance(Mockito.any(),eq(serviceInstanceId))).thenReturn(emptyBodyCall());
 
 795         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 796         service.instantiateNetworkServiceInstance(request,serviceInstanceId);
 
 801     public void itCanTerminateNetworkServiceInstance() throws IOException {
 
 802         HttpServletRequest request = mockRequest();
 
 804         ResponseBody result=null;
 
 806         VfcService vfcService = mock(VfcService.class);
 
 807         when(vfcService.terminateNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(successfulCall(result));
 
 808         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 810         service.terminateNetworkServiceInstance(request,csarId);
 
 814     public void terminateNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
 
 815         HttpServletRequest request = mockRequest();
 
 817         VfcService vfcService = mock(VfcService.class);
 
 818         //when(vfcService.terminateNetworkServiceInstance(csarId,anyObject())).thenReturn(failedCall("VFC is not available!"));
 
 819         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 820         service.terminateNetworkServiceInstance(request,csarId);
 
 824     public void terminateNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
 
 825         HttpServletRequest request = mockRequest();
 
 827         VfcService vfcService = mock(VfcService.class);
 
 828         when(vfcService.terminateNetworkServiceInstance(eq(csarId),Mockito.any())).thenReturn(emptyBodyCall());
 
 829         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 830         service.terminateNetworkServiceInstance(request,csarId);
 
 834     public void itCreateNetworkServiceData() throws IOException {
 
 835         HttpServletRequest request = mockRequest();
 
 836         ResponseBody result=null;
 
 837         VfcService vfcService = mock(VfcService.class);
 
 838         when(vfcService.createNetworkServiceData(Mockito.any())).thenReturn(successfulCall(result));
 
 839         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 841         Assert.assertTrue(StringUtils.isNotEmpty(service.createNetworkServiceData(request)));
 
 845     public void createNetworkServiceDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
 
 846         HttpServletRequest request = mockRequest();
 
 847         VfcService vfcService = mock(VfcService.class);
 
 848         when(vfcService.createNetworkServiceData(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
 
 849         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 850         service.createNetworkServiceData(request);
 
 854     public void createNetworkServiceDataWillThrowExceptionWhenVFCResponseError() throws IOException {
 
 855         HttpServletRequest request = mockRequest();
 
 856         VfcService vfcService = mock(VfcService.class);
 
 857         when(vfcService.createNetworkServiceData(Mockito.any())).thenReturn(emptyBodyCall());
 
 858         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 859         service.createNetworkServiceData(request);
 
 863     public void itCreateVnfData() throws IOException {
 
 864         HttpServletRequest request = mockRequest();
 
 865         ResponseBody result=null;
 
 866         VfcService vfcService = mock(VfcService.class);
 
 867         when(vfcService.createVnfData(Mockito.any())).thenReturn(successfulCall(result));
 
 868         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 870         Assert.assertSame("{\"status\":\"FAILED\"}", service.createVnfData(request));
 
 874     public void createVnfDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
 
 875         HttpServletRequest request = mockRequest();
 
 876         VfcService vfcService = mock(VfcService.class);
 
 877         when(vfcService.createVnfData(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
 
 878         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 879         service.createVnfData(request);
 
 883     public void createVnfDataWillThrowExceptionWhenVFCResponseError() throws IOException {
 
 884         HttpServletRequest request = mockRequest();
 
 885         VfcService vfcService = mock(VfcService.class);
 
 886         when(vfcService.createVnfData(Mockito.any())).thenReturn(emptyBodyCall());
 
 887         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 888         service.createVnfData(request);
 
 892     public void itCreatePnfData() throws IOException {
 
 893         HttpServletRequest request = mockRequest();
 
 894         ResponseBody result=null;
 
 895         VfcService vfcService = mock(VfcService.class);
 
 896         when(vfcService.createPnfData(Mockito.any())).thenReturn(successfulCall(result));
 
 897         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 899         Assert.assertSame("{\"status\":\"FAILED\"}", service.createPnfData(request));
 
 903     public void createPnfDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
 
 904         HttpServletRequest request = mockRequest();
 
 905         VfcService vfcService = mock(VfcService.class);
 
 906         when(vfcService.createPnfData(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
 
 907         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 908         service.createPnfData(request);
 
 912     public void createPnfDataWillThrowExceptionWhenVFCResponseError() throws IOException {
 
 913         HttpServletRequest request = mockRequest();
 
 914         VfcService vfcService = mock(VfcService.class);
 
 915         when(vfcService.createPnfData(Mockito.any())).thenReturn(emptyBodyCall());
 
 916         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 917         service.createPnfData(request);
 
 921     public void itGetNsdInfo() throws IOException {
 
 923         ResponseBody result=null;
 
 924         VfcService vfcService = mock(VfcService.class);
 
 925         when(vfcService.getNsdInfo(nsdId)).thenReturn(successfulCall(result));
 
 926         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 928         Assert.assertSame("{\"status\":\"SUCCESS\"}", service.getNsdInfo(nsdId));
 
 932     public void getNsdInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
 
 934         VfcService vfcService = mock(VfcService.class);
 
 935         when(vfcService.getNsdInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
 
 936         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 937         service.getNsdInfo(nsdId);
 
 941     public void getNsdInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
 
 943         VfcService vfcService = mock(VfcService.class);
 
 944         when(vfcService.getNsdInfo(nsdId)).thenReturn(emptyBodyCall());
 
 945         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 946         service.getNsdInfo(nsdId);
 
 950     public void itGetVnfInfo() throws IOException {
 
 952         ResponseBody result=null;
 
 953         VfcService vfcService = mock(VfcService.class);
 
 954         when(vfcService.getVnfInfo(nsdId)).thenReturn(successfulCall(result));
 
 955         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 957         Assert.assertSame("{\"status\":\"SUCCESS\"}", service.getVnfInfo(nsdId));
 
 961     public void getVnfInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
 
 963         VfcService vfcService = mock(VfcService.class);
 
 964         when(vfcService.getVnfInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
 
 965         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 966         service.getVnfInfo(nsdId);
 
 970     public void getVnfInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
 
 972         VfcService vfcService = mock(VfcService.class);
 
 973         when(vfcService.getVnfInfo(nsdId)).thenReturn(emptyBodyCall());
 
 974         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 975         service.getVnfInfo(nsdId);
 
 979     public void itGetPnfInfo() throws IOException {
 
 981         ResponseBody result=null;
 
 982         VfcService vfcService = mock(VfcService.class);
 
 983         when(vfcService.getPnfInfo(nsdId)).thenReturn(successfulCall(result));
 
 984         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 986         Assert.assertSame("{\"status\":\"SUCCESS\"}", service.getPnfInfo(nsdId));
 
 990     public void getPnfInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
 
 992         VfcService vfcService = mock(VfcService.class);
 
 993         when(vfcService.getPnfInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
 
 994         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
 995         service.getPnfInfo(nsdId);
 
 999     public void getPnfInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
 
1001         VfcService vfcService = mock(VfcService.class);
 
1002         when(vfcService.getPnfInfo(nsdId)).thenReturn(emptyBodyCall());
 
1003         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
1004         service.getPnfInfo(nsdId);
 
1008     public void itCanListNsTemplates() throws IOException {
 
1009         ResponseBody result=null;
 
1010         VfcService vfcService = mock(VfcService.class);
 
1011         when(vfcService.listNsTemplates()).thenReturn(successfulCall(result));
 
1012         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
1014         Assert.assertSame(result, service.listNsTemplates());
 
1018     public void listNsTemplatesWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
 
1019         VfcService vfcService = mock(VfcService.class);
 
1020         when(vfcService.listNsTemplates()).thenReturn(failedCall("VFC is not available!"));
 
1021         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
1022         service.listNsTemplates();
 
1026     public void listNsTemplatesWillThrowExceptionWhenVFCResponseError() throws IOException {
 
1027         VfcService vfcService = mock(VfcService.class);
 
1028         when(vfcService.listNsTemplates()).thenReturn(emptyBodyCall());
 
1029         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
1030         service.listNsTemplates();
 
1034     public void itCanGetVnfInfoById() throws IOException {
 
1036         ResponseBody result=null;
 
1037         VfcService vfcService = mock(VfcService.class);
 
1038         when(vfcService.getVnfInfoById(nsdId)).thenReturn(successfulCall(result));
 
1039         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
1041         Assert.assertSame(result, service.getVnfInfoById(nsdId));
 
1045     public void getVnfInfoByIdWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
 
1047         VfcService vfcService = mock(VfcService.class);
 
1048         when(vfcService.getVnfInfoById(nsdId)).thenReturn(failedCall("VFC is not available!"));
 
1049         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
1050         service.getVnfInfoById(nsdId);
 
1054     public void getVnfInfoByIdWillThrowExceptionWhenVFCResponseError() throws IOException {
 
1056         VfcService vfcService = mock(VfcService.class);
 
1057         when(vfcService.getVnfInfoById(nsdId)).thenReturn(emptyBodyCall());
 
1058         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
1059         service.getVnfInfoById(nsdId);
 
1063     public void itCanFetchNsTemplateData() throws IOException {
 
1064         HttpServletRequest request = mockRequest();
 
1065         ResponseBody result=null;
 
1066         VfcService vfcService = mock(VfcService.class);
 
1067         when(vfcService.fetchNsTemplateData(Mockito.any())).thenReturn(successfulCall(result));
 
1068         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
1070         Assert.assertSame("{\"status\":\"FAILED\"}", service.fetchNsTemplateData(request));
 
1074     public void fetchNsTemplateDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
 
1075         HttpServletRequest request = mockRequest();
 
1076         VfcService vfcService = mock(VfcService.class);
 
1077         when(vfcService.fetchNsTemplateData(Mockito.any())).thenReturn(failedCall("VFC is not available!"));
 
1078         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
1079         service.fetchNsTemplateData(request);
 
1083     public void fetchNsTemplateDataWillThrowExceptionWhenVFCResponseError() throws IOException {
 
1084         HttpServletRequest request = mockRequest();
 
1085         VfcService vfcService = mock(VfcService.class);
 
1086         when(vfcService.fetchNsTemplateData(Mockito.any())).thenReturn(emptyBodyCall());
 
1087         PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
 
1088         service.fetchNsTemplateData(request);