[SDC] Onboarding 1710 rebase.
[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 public class VSPFullTest {
24 /*
25
26
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;
39
40   @Test
41   public void testEnrichModelInSubmit() {
42     UniqueValueUtil
43         .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
44             "VSP_FullTest");
45
46     String vlm1Id = vendorLicenseFacade.createVendorLicenseModel(VSPCommon
47             .createVendorLicenseModel("vlmName " + CommonMethods.nextUuId(), "vlm1Id desc", "icon1"),
48         USER1).getId();
49     String entitlementPoolId = vendorLicenseFacade
50         .createEntitlementPool(new EntitlementPoolEntity(vlm1Id, null, null), USER1).getId();
51
52     FeatureGroupEntity featureGroup = new FeatureGroupEntity(vlm1Id, null, null);
53     featureGroup.getEntitlementPoolIds().add(entitlementPoolId);
54     String featureGroupId = vendorLicenseFacade.createFeatureGroup(featureGroup, USER1).getId();
55
56     LicenseAgreementEntity licenseAgreement = new LicenseAgreementEntity(vlm1Id, null, null);
57     licenseAgreement.getFeatureGroupIds().add(featureGroupId);
58     String licenseAgreementId =
59         vendorLicenseFacade.createLicenseAgreement(licenseAgreement, USER1).getId();
60
61     vendorLicenseFacade.checkin(vlm1Id, USER1);
62     vendorLicenseFacade.submit(vlm1Id, USER1);
63
64     String vspId = createVsp(vlm1Id, licenseAgreementId, licenseAgreement.getFeatureGroupIds());
65
66     Collection<ComponentEntity> components = uploadFullCompositionFile(vspId);
67
68     InputStream zis1 = getFileInputStream("/validation/zips/various/MIB.zip");
69     mibManager
70         .upload(zis1, "MMSC.zip", vspId, VERSION01,
71             components.iterator().next().getId(),
72             MonitoringUploadType.SNMP_TRAP,
73             USER1);
74
75     //check in
76     vendorSoftwareProductManager.checkin(vspId, USER1);
77     //submit
78     try {
79       ValidationResponse result = vendorSoftwareProductManager.submit(vspId, USER1);
80       //Assert.assertTrue(result.isValid());
81       //PackageInfo createPackageResult = vendorSoftwareProductManager.createPackage(vspId, USER1);
82
83     } catch (IOException exception) {
84       Assert.fail();
85     }
86     VersionedVendorSoftwareProductInfo details =
87         vendorSoftwareProductManager.getVsp(vspId, null, USER1);
88
89
90     //File csar = vendorSoftwareProductManager.getTranslatedFile(vspId,details.getVersionInfo().getActiveVersion(),USER1);
91     // writeFile(csar);
92
93
94     ToscaServiceModel model =
95         (ToscaServiceModel) EnrichedServiceModelDaoFactory.getInstance().createInterface()
96             .getServiceModel(vspId, details.getVersionInfo().getActiveVersion());
97
98     Map<String, CapabilityDefinition> capabilities = new HashMap<>();
99     for (ComponentEntity component : components) {
100       model.getServiceTemplates().
101           entrySet().
102           stream().
103           filter(entryValue -> entryValue.getValue() != null &&
104               entryValue.getValue().getNode_types() != null &&
105               entryValue.getValue().
106                   getNode_types().
107                   containsKey(component.getComponentCompositionData().getName())).
108           forEach(entryValue -> entryValue.getValue().getNode_types().
109               values().
110               stream().
111               filter(type -> MapUtils.isNotEmpty(type.getCapabilities())).
112               forEach(type -> type.getCapabilities().
113                   entrySet().
114                   forEach(entry -> addCapability(entryValue.getKey(), capabilities, entry.getKey(),
115                       entry.getValue()))));
116
117     }
118
119     Assert.assertNotNull(capabilities);
120   }
121
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);
126
127     Collection<ComponentEntity> components = null;
128     //vendorSoftwareProductManager.listComponents(vspId, null, USER1);
129     Assert.assertFalse(components.isEmpty());
130
131     for (ComponentEntity component : components) {
132 */
133 /*      Assert.assertNotNull(vendorSoftwareProductManager
134           .getQuestionnaire(vspId, null, component.getId(), USER1).getData());*//*
135
136
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());
143       }
144     }
145
146     return components;
147   }
148
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();
155
156     VspDetails actualVsp =
157         vendorSoftwareProductDao.getVendorSoftwareProductInfo(new VspDetails(vspId, VERSION01));
158     expectedVsp.setId(vspId);
159     expectedVsp.setVersion(VERSION01);
160
161     //VendorSoftwareProductManagerImplTest.assertVspsEquals(actualVsp, expectedVsp);
162     Assert.assertNotNull(
163         vendorSoftwareProductManager.getVspQuestionnaire(vspId, null, USER1).getData());
164     return vspId;
165   }
166
167   private void writeFile(File csar) {
168     try {
169       FileInputStream in = new FileInputStream(csar);
170       File output = new File("CSAR_vDNS.zip");
171
172       FileOutputStream out = new FileOutputStream(output);
173
174       IOUtils.copy(in, out);
175       in.close();
176       out.close();
177     } catch (IOException exception) {
178       throw new RuntimeException(exception);
179     }
180   }
181
182   private void addCapability(String entryValueKey, Map<String, CapabilityDefinition> capabilities,
183                              String key, CapabilityDefinition value) {
184
185     capabilities.put(entryValueKey + "_" + key, value);
186   }
187
188   private InputStream getFileInputStream(String fileName) {
189     URL url = this.getClass().getResource(fileName);
190     try {
191       return url.openStream();
192     } catch (IOException exception) {
193       exception.printStackTrace();
194       return null;
195     }
196   }
197
198
199 */
200 }