2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.vendorsoftwareproduct;
23 import org.apache.commons.collections4.MapUtils;
24 import org.apache.commons.io.IOUtils;
25 import org.openecomp.core.enrichment.types.ArtifactType;
26 import org.openecomp.core.model.dao.EnrichedServiceModelDaoFactory;
27 import org.openecomp.core.util.UniqueValueUtil;
28 import org.openecomp.core.utilities.CommonMethods;
29 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
30 import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition;
31 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
32 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity;
33 import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity;
34 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
35 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacadeFactory;
36 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao;
37 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory;
38 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
39 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity;
40 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
41 import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse;
42 import org.openecomp.sdc.vendorsoftwareproduct.types.VersionedVendorSoftwareProductInfo;
43 import org.openecomp.sdc.vendorsoftwareproduct.utils.VSPCommon;
44 import org.openecomp.sdc.versioning.dao.types.Version;
45 import org.testng.Assert;
46 import org.testng.annotations.Test;
49 import java.io.FileInputStream;
50 import java.io.FileOutputStream;
51 import java.io.IOException;
52 import java.io.InputStream;
54 import java.util.Collection;
55 import java.util.HashMap;
58 import java.util.stream.Collectors;
60 public class VSPFullTest {
64 public static final Version VERSION01 = new Version(0, 1);
65 private static final VendorSoftwareProductDao vendorSoftwareProductDao =
66 VendorSoftwareProductDaoFactory
67 .getInstance().createInterface();
68 private static final String USER1 = "vspTestUser1";
69 private static VendorSoftwareProductManager vendorSoftwareProductManager = null;
70 //new VendorSoftwareProductManagerImpl();
71 private static VendorLicenseFacade vendorLicenseFacade =
72 VendorLicenseFacadeFactory.getInstance().createInterface();
73 private OrchestrationTemplateCandidateManager candidateManager;
74 private MibManager mibManager;
75 private NicManager nicManager;
78 public void testEnrichModelInSubmit() {
80 .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
83 String vlm1Id = vendorLicenseFacade.createVendorLicenseModel(VSPCommon
84 .createVendorLicenseModel("vlmName " + CommonMethods.nextUuId(), "vlm1Id desc", "icon1"),
86 String entitlementPoolId = vendorLicenseFacade
87 .createEntitlementPool(new EntitlementPoolEntity(vlm1Id, null, null), USER1).getId();
89 FeatureGroupEntity featureGroup = new FeatureGroupEntity(vlm1Id, null, null);
90 featureGroup.getEntitlementPoolIds().add(entitlementPoolId);
91 String featureGroupId = vendorLicenseFacade.createFeatureGroup(featureGroup, USER1).getId();
93 LicenseAgreementEntity licenseAgreement = new LicenseAgreementEntity(vlm1Id, null, null);
94 licenseAgreement.getFeatureGroupIds().add(featureGroupId);
95 String licenseAgreementId =
96 vendorLicenseFacade.createLicenseAgreement(licenseAgreement, USER1).getId();
98 vendorLicenseFacade.checkin(vlm1Id, USER1);
99 vendorLicenseFacade.submit(vlm1Id, USER1);
101 String vspId = createVsp(vlm1Id, licenseAgreementId, licenseAgreement.getFeatureGroupIds());
103 Collection<ComponentEntity> components = uploadFullCompositionFile(vspId);
105 InputStream zis1 = getFileInputStream("/validation/zips/various/MIB.zip");
107 .upload(zis1, "MMSC.zip", vspId, VERSION01,
108 components.iterator().next().getId(),
109 ArtifactType.SNMP_TRAP,
113 vendorSoftwareProductManager.checkin(vspId, USER1);
116 ValidationResponse result = vendorSoftwareProductManager.submit(vspId, USER1);
117 //Assert.assertTrue(result.isValid());
118 //PackageInfo createPackageResult = vendorSoftwareProductManager.createPackage(vspId, USER1);
120 } catch (IOException exception) {
123 VersionedVendorSoftwareProductInfo details =
124 vendorSoftwareProductManager.getVsp(vspId, null, USER1);
127 //File csar = vendorSoftwareProductManager.getTranslatedFile(vspId,details.getVersionInfo().getActiveVersion(),USER1);
131 ToscaServiceModel model =
132 (ToscaServiceModel) EnrichedServiceModelDaoFactory.getInstance().createInterface()
133 .getServiceModel(vspId, details.getVersionInfo().getActiveVersion());
135 Map<String, CapabilityDefinition> capabilities = new HashMap<>();
136 for (ComponentEntity component : components) {
137 model.getServiceTemplates().
140 filter(entryValue -> entryValue.getValue() != null &&
141 entryValue.getValue().getNode_types() != null &&
142 entryValue.getValue().
144 containsKey(component.getComponentCompositionData().getName())).
145 forEach(entryValue -> entryValue.getValue().getNode_types().
148 filter(type -> MapUtils.isNotEmpty(type.getCapabilities())).
149 forEach(type -> type.getCapabilities().
151 forEach(entry -> addCapability(entryValue.getKey(), capabilities, entry.getKey(),
152 entry.getValue()))));
156 Assert.assertNotNull(capabilities);
159 private Collection<ComponentEntity> uploadFullCompositionFile(String vspId) {
160 candidateManager.upload(vspId, VERSION01,
161 getFileInputStream("/vspmanager/zips/fullComposition.zip"), USER1);
162 candidateManager.process(vspId, VERSION01, USER1);
164 Collection<ComponentEntity> components = null;
165 //vendorSoftwareProductManager.listComponents(vspId, null, USER1);
166 Assert.assertFalse(components.isEmpty());
168 for (ComponentEntity component : components) {
170 /* Assert.assertNotNull(vendorSoftwareProductManager
171 .getQuestionnaire(vspId, null, component.getId(), USER1).getData());*//*
174 Collection<NicEntity> nics =
175 nicManager.listNics(vspId, null, component.getId(), USER1);
176 Assert.assertFalse(nics.isEmpty());
177 for (NicEntity nic : nics) {
178 Assert.assertNotNull(nicManager
179 .getNicQuestionnaire(vspId, null, component.getId(), nic.getId(), USER1).getData());
186 private String createVsp(String vlm1Id, String licenseAgreementId, Set<String> featureGroupIds) {
187 VspDetails expectedVsp = VSPCommon
188 .createVspDetails(null, null, "VSP_FullTest", "Test-vsp_fullTest", "vendorName", vlm1Id,
189 "icon", "category", "subCategory", licenseAgreementId,
190 featureGroupIds.stream().collect(Collectors.toList()));
191 String vspId = vendorSoftwareProductManager.createVsp(expectedVsp, USER1).getId();
193 VspDetails actualVsp =
194 vendorSoftwareProductDao.getVendorSoftwareProductInfo(new VspDetails(vspId, VERSION01));
195 expectedVsp.setId(vspId);
196 expectedVsp.setVersion(VERSION01);
198 //VendorSoftwareProductManagerImplTest.assertVspsEquals(actualVsp, expectedVsp);
199 Assert.assertNotNull(
200 vendorSoftwareProductManager.getVspQuestionnaire(vspId, null, USER1).getData());
204 private void writeFile(File csar) {
206 FileInputStream in = new FileInputStream(csar);
207 File output = new File("CSAR_vDNS.zip");
209 FileOutputStream out = new FileOutputStream(output);
211 IOUtils.copy(in, out);
214 } catch (IOException exception) {
215 throw new RuntimeException(exception);
219 private void addCapability(String entryValueKey, Map<String, CapabilityDefinition> capabilities,
220 String key, CapabilityDefinition value) {
222 capabilities.put(entryValueKey + "_" + key, value);
225 private InputStream getFileInputStream(String fileName) {
226 URL url = this.getClass().getResource(fileName);
228 return url.openStream();
229 } catch (IOException exception) {
230 exception.printStackTrace();