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 public class VSPFullTest {
27 public static final Version VERSION01 = new Version(0, 1);
28 private static final VendorSoftwareProductDao vendorSoftwareProductDao =
29 VendorSoftwareProductDaoFactory
30 .getInstance().createInterface();
31 private static final String USER1 = "vspTestUser1";
32 private static VendorSoftwareProductManager vendorSoftwareProductManager = null;
33 //new VendorSoftwareProductManagerImpl();
34 private static VendorLicenseFacade vendorLicenseFacade =
35 VendorLicenseFacadeFactory.getInstance().createInterface();
36 private OrchestrationTemplateCandidateManager candidateManager;
37 private MonitoringUploadsManager mibManager;
38 private NicManager nicManager;
41 public void testEnrichModelInSubmit() {
43 .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
46 String vlm1Id = vendorLicenseFacade.createVendorLicenseModel(VSPCommon
47 .createVendorLicenseModel("vlmName " + CommonMethods.nextUuId(), "vlm1Id desc", "icon1"),
49 String entitlementPoolId = vendorLicenseFacade
50 .createEntitlementPool(new EntitlementPoolEntity(vlm1Id, null, null), USER1).getId();
52 FeatureGroupEntity featureGroup = new FeatureGroupEntity(vlm1Id, null, null);
53 featureGroup.getEntitlementPoolIds().add(entitlementPoolId);
54 String featureGroupId = vendorLicenseFacade.createFeatureGroup(featureGroup, USER1).getId();
56 LicenseAgreementEntity licenseAgreement = new LicenseAgreementEntity(vlm1Id, null, null);
57 licenseAgreement.getFeatureGroupIds().add(featureGroupId);
58 String licenseAgreementId =
59 vendorLicenseFacade.createLicenseAgreement(licenseAgreement, USER1).getId();
61 vendorLicenseFacade.checkin(vlm1Id, USER1);
62 vendorLicenseFacade.submit(vlm1Id, USER1);
64 String vspId = createVsp(vlm1Id, licenseAgreementId, licenseAgreement.getFeatureGroupIds());
66 Collection<ComponentEntity> components = uploadFullCompositionFile(vspId);
68 InputStream zis1 = getFileInputStream("/validation/zips/various/MIB.zip");
70 .upload(zis1, "MMSC.zip", vspId, VERSION01,
71 components.iterator().next().getId(),
72 MonitoringUploadType.SNMP_TRAP,
76 vendorSoftwareProductManager.checkin(vspId, USER1);
79 ValidationResponse result = vendorSoftwareProductManager.submit(vspId, USER1);
80 //Assert.assertTrue(result.isValid());
81 //PackageInfo createPackageResult = vendorSoftwareProductManager.createPackage(vspId, USER1);
83 } catch (IOException exception) {
86 VersionedVendorSoftwareProductInfo details =
87 vendorSoftwareProductManager.getVsp(vspId, null, USER1);
90 //File csar = vendorSoftwareProductManager.getTranslatedFile(vspId,details.getVersionInfo().getActiveVersion(),USER1);
94 ToscaServiceModel model =
95 (ToscaServiceModel) EnrichedServiceModelDaoFactory.getInstance().createInterface()
96 .getServiceModel(vspId, details.getVersionInfo().getActiveVersion());
98 Map<String, CapabilityDefinition> capabilities = new HashMap<>();
99 for (ComponentEntity component : components) {
100 model.getServiceTemplates().
103 filter(entryValue -> entryValue.getValue() != null &&
104 entryValue.getValue().getNode_types() != null &&
105 entryValue.getValue().
107 containsKey(component.getComponentCompositionData().getName())).
108 forEach(entryValue -> entryValue.getValue().getNode_types().
111 filter(type -> MapUtils.isNotEmpty(type.getCapabilities())).
112 forEach(type -> type.getCapabilities().
114 forEach(entry -> addCapability(entryValue.getKey(), capabilities, entry.getKey(),
115 entry.getValue()))));
119 Assert.assertNotNull(capabilities);
122 private Collection<ComponentEntity> uploadFullCompositionFile(String vspId) {
123 candidateManager.upload(vspId, VERSION01,
124 getFileInputStream("/vspmanager/zips/fullComposition.zip"), USER1);
125 candidateManager.process(vspId, VERSION01, USER1);
127 Collection<ComponentEntity> components = null;
128 //vendorSoftwareProductManager.listComponents(vspId, null, USER1);
129 Assert.assertFalse(components.isEmpty());
131 for (ComponentEntity component : components) {
133 /* Assert.assertNotNull(vendorSoftwareProductManager
134 .getQuestionnaire(vspId, null, component.getId(), USER1).getData());*//*
137 Collection<NicEntity> nics =
138 nicManager.listNics(vspId, null, component.getId(), USER1);
139 Assert.assertFalse(nics.isEmpty());
140 for (NicEntity nic : nics) {
141 Assert.assertNotNull(nicManager
142 .getNicQuestionnaire(vspId, null, component.getId(), nic.getId(), USER1).getData());
149 private String createVsp(String vlm1Id, String licenseAgreementId, Set<String> featureGroupIds) {
150 VspDetails expectedVsp = VSPCommon
151 .createVspDetails(null, null, "VSP_FullTest", "Test-vsp_fullTest", "vendorName", vlm1Id,
152 "icon", "category", "subCategory", licenseAgreementId,
153 featureGroupIds.stream().collect(Collectors.toList()));
154 String vspId = vendorSoftwareProductManager.createVsp(expectedVsp, USER1).getId();
156 VspDetails actualVsp =
157 vendorSoftwareProductDao.getVendorSoftwareProductInfo(new VspDetails(vspId, VERSION01));
158 expectedVsp.setId(vspId);
159 expectedVsp.setVersion(VERSION01);
161 //VendorSoftwareProductManagerImplTest.assertVspsEquals(actualVsp, expectedVsp);
162 Assert.assertNotNull(
163 vendorSoftwareProductManager.getVspQuestionnaire(vspId, null, USER1).getData());
167 private void writeFile(File csar) {
169 FileInputStream in = new FileInputStream(csar);
170 File output = new File("CSAR_vDNS.zip");
172 FileOutputStream out = new FileOutputStream(output);
174 IOUtils.copy(in, out);
177 } catch (IOException exception) {
178 throw new RuntimeException(exception);
182 private void addCapability(String entryValueKey, Map<String, CapabilityDefinition> capabilities,
183 String key, CapabilityDefinition value) {
185 capabilities.put(entryValueKey + "_" + key, value);
188 private InputStream getFileInputStream(String fileName) {
189 URL url = this.getClass().getResource(fileName);
191 return url.openStream();
192 } catch (IOException exception) {
193 exception.printStackTrace();