d4dea70f2f36edbd0d4297e6f12d91c4d1ae6745
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-software-product-manager / src / test / java / org / openecomp / sdc / vendorsoftwareproduct / VSPFullTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.vendorsoftwareproduct;
22
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;
47
48 import java.io.File;
49 import java.io.FileInputStream;
50 import java.io.FileOutputStream;
51 import java.io.IOException;
52 import java.io.InputStream;
53 import java.net.URL;
54 import java.util.Collection;
55 import java.util.HashMap;
56 import java.util.Map;
57 import java.util.Set;
58 import java.util.stream.Collectors;
59
60 public class VSPFullTest {
61 /*
62
63
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;
76
77   @Test
78   public void testEnrichModelInSubmit() {
79     UniqueValueUtil
80         .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
81             "VSP_FullTest");
82
83     String vlm1Id = vendorLicenseFacade.createVendorLicenseModel(VSPCommon
84             .createVendorLicenseModel("vlmName " + CommonMethods.nextUuId(), "vlm1Id desc", "icon1"),
85         USER1).getId();
86     String entitlementPoolId = vendorLicenseFacade
87         .createEntitlementPool(new EntitlementPoolEntity(vlm1Id, null, null), USER1).getId();
88
89     FeatureGroupEntity featureGroup = new FeatureGroupEntity(vlm1Id, null, null);
90     featureGroup.getEntitlementPoolIds().add(entitlementPoolId);
91     String featureGroupId = vendorLicenseFacade.createFeatureGroup(featureGroup, USER1).getId();
92
93     LicenseAgreementEntity licenseAgreement = new LicenseAgreementEntity(vlm1Id, null, null);
94     licenseAgreement.getFeatureGroupIds().add(featureGroupId);
95     String licenseAgreementId =
96         vendorLicenseFacade.createLicenseAgreement(licenseAgreement, USER1).getId();
97
98     vendorLicenseFacade.checkin(vlm1Id, USER1);
99     vendorLicenseFacade.submit(vlm1Id, USER1);
100
101     String vspId = createVsp(vlm1Id, licenseAgreementId, licenseAgreement.getFeatureGroupIds());
102
103     Collection<ComponentEntity> components = uploadFullCompositionFile(vspId);
104
105     InputStream zis1 = getFileInputStream("/validation/zips/various/MIB.zip");
106     mibManager
107         .upload(zis1, "MMSC.zip", vspId, VERSION01,
108             components.iterator().next().getId(),
109             ArtifactType.SNMP_TRAP,
110             USER1);
111
112     //check in
113     vendorSoftwareProductManager.checkin(vspId, USER1);
114     //submit
115     try {
116       ValidationResponse result = vendorSoftwareProductManager.submit(vspId, USER1);
117       //Assert.assertTrue(result.isValid());
118       //PackageInfo createPackageResult = vendorSoftwareProductManager.createPackage(vspId, USER1);
119
120     } catch (IOException exception) {
121       Assert.fail();
122     }
123     VersionedVendorSoftwareProductInfo details =
124         vendorSoftwareProductManager.getVsp(vspId, null, USER1);
125
126
127     //File csar = vendorSoftwareProductManager.getTranslatedFile(vspId,details.getVersionInfo().getActiveVersion(),USER1);
128     // writeFile(csar);
129
130
131     ToscaServiceModel model =
132         (ToscaServiceModel) EnrichedServiceModelDaoFactory.getInstance().createInterface()
133             .getServiceModel(vspId, details.getVersionInfo().getActiveVersion());
134
135     Map<String, CapabilityDefinition> capabilities = new HashMap<>();
136     for (ComponentEntity component : components) {
137       model.getServiceTemplates().
138           entrySet().
139           stream().
140           filter(entryValue -> entryValue.getValue() != null &&
141               entryValue.getValue().getNode_types() != null &&
142               entryValue.getValue().
143                   getNode_types().
144                   containsKey(component.getComponentCompositionData().getName())).
145           forEach(entryValue -> entryValue.getValue().getNode_types().
146               values().
147               stream().
148               filter(type -> MapUtils.isNotEmpty(type.getCapabilities())).
149               forEach(type -> type.getCapabilities().
150                   entrySet().
151                   forEach(entry -> addCapability(entryValue.getKey(), capabilities, entry.getKey(),
152                       entry.getValue()))));
153
154     }
155
156     Assert.assertNotNull(capabilities);
157   }
158
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);
163
164     Collection<ComponentEntity> components = null;
165     //vendorSoftwareProductManager.listComponents(vspId, null, USER1);
166     Assert.assertFalse(components.isEmpty());
167
168     for (ComponentEntity component : components) {
169 */
170 /*      Assert.assertNotNull(vendorSoftwareProductManager
171           .getQuestionnaire(vspId, null, component.getId(), USER1).getData());*//*
172
173
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());
180       }
181     }
182
183     return components;
184   }
185
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();
192
193     VspDetails actualVsp =
194         vendorSoftwareProductDao.getVendorSoftwareProductInfo(new VspDetails(vspId, VERSION01));
195     expectedVsp.setId(vspId);
196     expectedVsp.setVersion(VERSION01);
197
198     //VendorSoftwareProductManagerImplTest.assertVspsEquals(actualVsp, expectedVsp);
199     Assert.assertNotNull(
200         vendorSoftwareProductManager.getVspQuestionnaire(vspId, null, USER1).getData());
201     return vspId;
202   }
203
204   private void writeFile(File csar) {
205     try {
206       FileInputStream in = new FileInputStream(csar);
207       File output = new File("CSAR_vDNS.zip");
208
209       FileOutputStream out = new FileOutputStream(output);
210
211       IOUtils.copy(in, out);
212       in.close();
213       out.close();
214     } catch (IOException exception) {
215       throw new RuntimeException(exception);
216     }
217   }
218
219   private void addCapability(String entryValueKey, Map<String, CapabilityDefinition> capabilities,
220                              String key, CapabilityDefinition value) {
221
222     capabilities.put(entryValueKey + "_" + key, value);
223   }
224
225   private InputStream getFileInputStream(String fileName) {
226     URL url = this.getClass().getResource(fileName);
227     try {
228       return url.openStream();
229     } catch (IOException exception) {
230       exception.printStackTrace();
231       return null;
232     }
233   }
234
235
236 */
237 }