1 package org.openecomp.sdc.vendorsoftwareproduct;
3 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
4 import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition;
5 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
6 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
7 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory;
8 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
9 import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl;
10 import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse;
11 import org.openecomp.sdc.vendorsoftwareproduct.types.VersionedVendorSoftwareProductInfo;
12 import org.openecomp.sdc.versioning.dao.types.Version;
13 import org.openecomp.core.model.dao.EnrichedServiceModelDaoFactory;
14 import org.openecomp.core.util.UniqueValueUtil;
15 import org.openecomp.core.utilities.CommonMethods;
16 import org.apache.commons.collections4.MapUtils;
17 import org.apache.commons.io.IOUtils;
18 import org.testng.Assert;
19 import org.testng.annotations.Test;
23 import java.util.Collection;
24 import java.util.HashMap;
27 import java.util.stream.Collectors;
29 public class VSPFullTest {
32 public static final Version VERSION01 = new Version(0, 1);
33 private static final org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao
34 vendorSoftwareProductDao =
35 VendorSoftwareProductDaoFactory.getInstance().createInterface();
36 private static final String USER1 = "vspTestUser1";
37 private static VendorSoftwareProductManager vendorSoftwareProductManager =
38 new VendorSoftwareProductManagerImpl();
39 private static VendorLicenseFacade vendorLicenseFacade =
40 org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacadeFactory.getInstance().createInterface();
43 public void testEnrichModelInSubmit() {
45 .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
48 String vlm1Id = vendorLicenseFacade.createVendorLicenseModel(VSPCommon
49 .createVendorLicenseModel("vlmName " + CommonMethods.nextUuId(), "vlm1Id desc", "icon1"),
51 String entitlementPoolId = vendorLicenseFacade
52 .createEntitlementPool(new EntitlementPoolEntity(vlm1Id, null, null), USER1).getId();
54 org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity
55 featureGroup = new org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity(vlm1Id, null, null);
56 featureGroup.getEntitlementPoolIds().add(entitlementPoolId);
57 String featureGroupId = vendorLicenseFacade.createFeatureGroup(featureGroup, USER1).getId();
59 org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity
60 licenseAgreement = new org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity(vlm1Id, null, null);
61 licenseAgreement.getFeatureGroupIds().add(featureGroupId);
62 String licenseAgreementId =
63 vendorLicenseFacade.createLicenseAgreement(licenseAgreement, USER1).getId();
65 vendorLicenseFacade.checkin(vlm1Id, USER1);
66 vendorLicenseFacade.submit(vlm1Id, USER1);
68 String vspId = createVsp(vlm1Id, licenseAgreementId, licenseAgreement.getFeatureGroupIds());
70 Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity> components = uploadFullCompositionFile(vspId);
74 vendorSoftwareProductManager.checkin(vspId, USER1);
77 ValidationResponse result = vendorSoftwareProductManager.submit(vspId, USER1);
78 //Assert.assertTrue(result.isValid());
79 //PackageInfo createPackageResult = vendorSoftwareProductManager.createPackage(vspId, USER1);
81 } catch (IOException e) {
84 VersionedVendorSoftwareProductInfo details =
85 vendorSoftwareProductManager.getVspDetails(vspId, null, USER1);
88 //File csar = vendorSoftwareProductManager.getTranslatedFile(vspId,details.getVersionInfo().getActiveVersion(),USER1);
92 ToscaServiceModel model =
93 (ToscaServiceModel) EnrichedServiceModelDaoFactory.getInstance().createInterface()
94 .getServiceModel(vspId, details.getVersionInfo().getActiveVersion());
96 Map<String, CapabilityDefinition> capabilities = new HashMap<>();
97 for (org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity component : components) {
98 model.getServiceTemplates().
101 filter(entryValue -> entryValue.getValue() != null &&
102 entryValue.getValue().getNode_types() != null &&
103 entryValue.getValue().
105 containsKey(component.getComponentCompositionData().getName())).
106 forEach(entryValue -> entryValue.getValue().getNode_types().
109 filter(type -> MapUtils.isNotEmpty(type.getCapabilities())).
110 forEach(type -> type.getCapabilities().
112 forEach(entry -> addCapability(entryValue.getKey(), capabilities, entry.getKey(),
113 entry.getValue()))));
117 Assert.assertNotNull(capabilities);
120 private Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity> uploadFullCompositionFile(String vspId) {
121 vendorSoftwareProductManager
122 .uploadFile(vspId, getFileInputStream("/vspmanager/zips/fullComposition.zip"), USER1);
124 Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity> components =
125 vendorSoftwareProductManager.listComponents(vspId, null, USER1);
126 Assert.assertFalse(components.isEmpty());
128 for (org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity component : components) {
129 Assert.assertNotNull(vendorSoftwareProductManager
130 .getComponentQuestionnaire(vspId, null, component.getId(), USER1).getData());
132 Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity> nics =
133 vendorSoftwareProductManager.listNics(vspId, null, component.getId(), USER1);
134 Assert.assertFalse(nics.isEmpty());
135 for (org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity nic : nics) {
136 Assert.assertNotNull(vendorSoftwareProductManager
137 .getNicQuestionnaire(vspId, null, component.getId(), nic.getId(), USER1).getData());
144 private String createVsp(String vlm1Id, String licenseAgreementId, Set<String> featureGroupIds) {
145 VspDetails expectedVsp = VSPCommon
146 .createVspDetails(null, null, "VSP_FullTest", "Test-vsp_fullTest", "vendorName", vlm1Id,
147 "icon", "category", "subCategory", licenseAgreementId,
148 featureGroupIds.stream().collect(Collectors.toList()));
149 String vspId = vendorSoftwareProductManager.createNewVsp(expectedVsp, USER1).getId();
151 VspDetails actualVsp =
152 vendorSoftwareProductDao.getVendorSoftwareProductInfo(new VspDetails(vspId, VERSION01));
153 expectedVsp.setId(vspId);
154 expectedVsp.setVersion(VERSION01);
156 VendorSoftwareProductManagerTest.assertVspsEquals(actualVsp, expectedVsp);
157 Assert.assertNotNull(
158 vendorSoftwareProductManager.getVspQuestionnaire(vspId, null, USER1).getData());
162 private void writeFile(File csar) {
164 FileInputStream in = new FileInputStream(csar);
165 File output = new File("CSAR_vDNS.zip");
167 FileOutputStream out = new FileOutputStream(output);
169 IOUtils.copy(in, out);
172 } catch (IOException e) {
173 throw new RuntimeException(e);
177 private void addCapability(String entryValueKey, Map<String, CapabilityDefinition> capabilities,
178 String key, CapabilityDefinition value) {
180 capabilities.put(entryValueKey + "_" + key, value);
183 private InputStream getFileInputStream(String fileName) {
184 URL url = this.getClass().getResource(fileName);
186 return url.openStream();
187 } catch (IOException e) {