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.junit.Assert;
19 import org.junit.Test;
20 import org.mockito.Mockito;
21 import org.onap.usecaseui.server.bean.lcm.VfNsPackageInfo;
22 import org.onap.usecaseui.server.service.lcm.PackageDistributionService;
23 import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService;
24 import org.onap.usecaseui.server.service.lcm.domain.aai.bean.VimInfo;
25 import org.onap.usecaseui.server.service.lcm.domain.sdc.SDCCatalogService;
26 import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.SDCServiceTemplate;
27 import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.Vnf;
28 import org.onap.usecaseui.server.service.lcm.domain.sdc.exceptions.SDCCatalogException;
29 import org.onap.usecaseui.server.service.lcm.domain.vfc.VfcService;
30 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Csar;
31 import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.DistributionResult;
32 import org.onap.usecaseui.server.service.lcm.domain.vfc.exceptions.VfcException;
33 import org.onap.usecaseui.server.util.CallStub;
34 import retrofit2.Call;
36 import java.util.Collections;
37 import java.util.List;
39 import static org.hamcrest.CoreMatchers.equalTo;
40 import static org.onap.usecaseui.server.service.lcm.domain.sdc.consts.SDCConsts.*;
42 public class DefaultPackageDistributionServiceTest {
45 public void itCanRetrievePackageFromSDCAndAAI() {
46 List<SDCServiceTemplate> serviceTemplate = Collections.singletonList(new SDCServiceTemplate("1", "1", "service", "", ""));
47 List<Vnf> vnf = Collections.singletonList(new Vnf("2","2","vnf"));
48 SDCCatalogService sdcService = newSDCService(serviceTemplate, vnf);
50 List<VimInfo> vim = Collections.singletonList(new VimInfo("owner", "regionId"));
51 AAIService aaiService = newAAIService(vim);
53 PackageDistributionService service = new DefaultPackageDistributionService(sdcService,aaiService, null);
55 Assert.assertThat(service.retrievePackageInfo(), equalTo(new VfNsPackageInfo(serviceTemplate, vnf, vim)));
58 private AAIService newAAIService(List<VimInfo> vim) {
59 AAIService aaiService = Mockito.mock(AAIService.class);
61 Call<List<VimInfo>> vimCall = CallStub.successfulCall(vim);
62 Mockito.when(aaiService.listVimInfo()).thenReturn(vimCall);
66 private SDCCatalogService newSDCService(List<SDCServiceTemplate> serviceTemplate, List<Vnf> vnf) {
67 SDCCatalogService sdcService = Mockito.mock(SDCCatalogService.class);
69 Call<List<SDCServiceTemplate>> serviceCall = CallStub.successfulCall(serviceTemplate);
70 Mockito.when(sdcService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(serviceCall);
72 Call<List<Vnf>> vnfCall = CallStub.successfulCall(vnf);
73 Mockito.when(sdcService.listResources(RESOURCETYPE_VF, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(vnfCall);
77 @Test(expected = SDCCatalogException.class)
78 public void retrievePackageWillThrowExceptionWhenSDCIsNotAvailable() {
79 SDCCatalogService sdcService = Mockito.mock(SDCCatalogService.class);
80 Call<List<SDCServiceTemplate>> serviceCall = CallStub.failedCall("SDC is not available!");
81 Mockito.when(sdcService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(serviceCall);
83 List<VimInfo> vim = Collections.singletonList(new VimInfo("owner", "regionId"));
84 AAIService aaiService = newAAIService(vim);
86 PackageDistributionService service = new DefaultPackageDistributionService(sdcService,aaiService, null);
87 service.retrievePackageInfo();
91 public void itCanPostNsPackageToVFC() {
92 VfcService vfcService = Mockito.mock(VfcService.class);
93 Csar csar = new Csar();
94 DistributionResult result = new DistributionResult("status", "description", "errorcode");
95 Mockito.when(vfcService.distributeNsPackage(csar)).thenReturn(CallStub.successfulCall(result));
96 PackageDistributionService service = new DefaultPackageDistributionService(null, null, vfcService);
98 Assert.assertSame(result, service.postNsPackage(csar));
101 @Test(expected = VfcException.class)
102 public void postNsPackageWillThrowExceptionWhenVFCIsNotAvailable() {
103 VfcService vfcService = Mockito.mock(VfcService.class);
104 Csar csar = new Csar();
105 Mockito.when(vfcService.distributeNsPackage(csar)).thenReturn(CallStub.failedCall("VFC is not available!"));
106 PackageDistributionService service = new DefaultPackageDistributionService(null, null, vfcService);
107 service.postNsPackage(csar);