Catalog alignment
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / execute / sanity / VFCArtifacts.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.ci.tests.execute.sanity;
22
23 import com.aventstack.extentreports.Status;
24 import org.apache.http.HttpStatus;
25 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
26 import org.openecomp.sdc.ci.tests.datatypes.HeatMetaFirstLevelDefinition;
27 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
28 import org.openecomp.sdc.ci.tests.datatypes.VendorLicenseModel;
29 import org.openecomp.sdc.ci.tests.datatypes.VendorSoftwareProductObject;
30 import org.openecomp.sdc.ci.tests.datatypes.enums.NormativeTypesEnum;
31 import org.openecomp.sdc.ci.tests.datatypes.enums.ResourceCategoryEnum;
32 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
33 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
34 import org.openecomp.sdc.ci.tests.execute.devCI.ArtifactFromCsar;
35 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
36 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
37 import org.openecomp.sdc.ci.tests.pages.DeploymentArtifactPage;
38 import org.openecomp.sdc.ci.tests.pages.HomePage;
39 import org.openecomp.sdc.ci.tests.pages.ResourceGeneralPage;
40 import org.openecomp.sdc.ci.tests.utilities.DownloadManager;
41 import org.openecomp.sdc.ci.tests.utilities.FileHandling;
42 import org.openecomp.sdc.ci.tests.utilities.OnboardingUiUtils;
43 import org.openecomp.sdc.ci.tests.utilities.ResourceUIUtils;
44 import org.openecomp.sdc.ci.tests.utilities.RestCDUtils;
45 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
46 import org.openecomp.sdc.ci.tests.utils.general.VendorLicenseModelRestUtils;
47 import org.openecomp.sdc.ci.tests.utils.general.VendorSoftwareProductRestUtils;
48 import org.openecomp.sdc.ci.tests.verificator.VFCArtifactVerificator;
49 import org.testng.annotations.BeforeClass;
50 import org.testng.annotations.Test;
51
52 import java.util.HashMap;
53 import java.util.LinkedList;
54 import java.util.List;
55 import java.util.Map;
56 import java.util.stream.Collectors;
57
58 import static org.testng.Assert.assertTrue;
59
60 public class VFCArtifacts extends SetupCDTest {
61
62     private static final String DEPLOYMENT = "Deployment";
63     private static final String INFORMATIONAL = "Informational";
64     private static final String ARTIFACTS = "artifacts";
65     private static final String DEPLOYMENT_ARTIFACTS = "deploymentArtifacts";
66     private String filePath;
67
68     @BeforeClass
69     public void beforeClass() {
70         filePath = FileHandling.getFilePath("VFCArtifacts");
71     }
72
73     @Test
74     public void ImportMultiVFCTest_TC1407998() throws Exception {
75
76         String csarFile = "Import_Multi_VFC.csar";
77
78         ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType("ciRes", NormativeTypesEnum.ROOT, ResourceCategoryEnum.APPLICATION_L4_DATABASE, getUser().getUserId(), ResourceTypeEnum.VF.toString());
79         resourceMetaData.setVersion("0.1");
80         ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, csarFile, getUser());
81
82         RestResponse getResponse = RestCDUtils.getResource(resourceMetaData, getUser());
83         assertTrue(getResponse.getErrorCode().intValue() == HttpStatus.SC_OK);
84
85         Map<String, LinkedList<HeatMetaFirstLevelDefinition>> expectedArtifactMap = verifyVfcArtifacts(filePath, csarFile, resourceMetaData, getResponse);
86
87         VFCArtifactVerificator.verifyVFCArtifactsNotInVFArtifactList(resourceMetaData, getUser(), getResponse, expectedArtifactMap);
88
89
90     }
91
92     @Test
93     public void updateCsarWithVFCArtifacts_ModifyArtifacts_TC1449482() throws Exception {
94
95         String csarFile = "LDSA-ORIG.csar";
96         ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType("ciRes", NormativeTypesEnum.ROOT, ResourceCategoryEnum.APPLICATION_L4_DATABASE, getUser().getUserId(), ResourceTypeEnum.VF.toString());
97         resourceMetaData.setVersion("0.1");
98         ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, csarFile, getUser());
99
100         Map<String, Object> artifactsFromCsar = ArtifactFromCsar.getVFCArtifacts(filePath + csarFile);
101         List<String> vfcKeys = artifactsFromCsar.keySet().stream().filter(p -> p.contains("vfc")).collect(Collectors.toList());
102         for (String key : vfcKeys) {
103             VFCArtifactVerificator.setActualVfcArtifactList(key, resourceMetaData, getUser());
104         }
105
106         String updatedCsarFile = "LDSA-MODIFY.csar";
107         ResourceUIUtils.updateVfWithCsar(filePath, updatedCsarFile);
108
109         Map<String, Object> updatedArtifactsFromCsar = ArtifactFromCsar.getVFCArtifacts(filePath + updatedCsarFile);
110         List<String> updatedVfcKeys = updatedArtifactsFromCsar.keySet().stream().filter(p -> p.contains("vfc")).collect(Collectors.toList());
111         for (String key : updatedVfcKeys) {
112             verifyVfcInstanceArtifacts(resourceMetaData, null, updatedArtifactsFromCsar, key);
113             VFCArtifactVerificator.verifyVfcArtifactUpdated(key, resourceMetaData, getUser());
114         }
115     }
116
117     @Test
118     public void updateCsarWithVFCArtifacts_DeleteAndAddArtifacts_TC1449473() throws Exception {
119
120         String csarFile = "LDSA-ORIG.csar";
121         ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType("ciRes", NormativeTypesEnum.ROOT, ResourceCategoryEnum.APPLICATION_L4_DATABASE, getUser().getUserId(), ResourceTypeEnum.VF.toString());
122         resourceMetaData.setVersion("0.1");
123         ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, csarFile, getUser());
124
125         String updatedCsarFile = "LDSA-DELETE-ADD.csar";
126         ResourceUIUtils.updateVfWithCsar(filePath, updatedCsarFile);
127
128         verifyVfcArtifacts(filePath, updatedCsarFile, resourceMetaData, null);
129     }
130
131     @Test
132     public void updateCsarWithVFCArtifacts_AddFirstVFCIdentifier_TC1425896() throws Exception {
133
134         String csarFile = "LDSA-ORIG-OLD_STRUCTURE.csar";
135         ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType("ciRes", NormativeTypesEnum.ROOT, ResourceCategoryEnum.APPLICATION_L4_DATABASE, getUser().getUserId(), ResourceTypeEnum.VF.toString());
136         resourceMetaData.setVersion("0.1");
137         ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, csarFile, getUser());
138
139         VFCArtifactVerificator.verifyNoVfcArtifacts(resourceMetaData, getUser(), null);
140
141         ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
142         String[] artifactNamesFromFile = ArtifactFromCsar.getArtifactNamesFromCsar(filePath, csarFile);
143         String[] artifactsFromFileBeforeUpdate = DeploymentArtifactPage.verifyArtifactsExistInTable(artifactNamesFromFile);
144         DeploymentArtifactPage.getLeftMenu().moveToGeneralScreen();
145
146         String updatedCsarFile = "LDSA-ADD.csar";
147         ResourceUIUtils.updateVfWithCsar(filePath, updatedCsarFile);
148
149         verifyVfcArtifacts(filePath, updatedCsarFile, resourceMetaData, null);
150
151         ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
152         DeploymentArtifactPage.verifyArtifactsExistInTable(artifactsFromFileBeforeUpdate);
153     }
154
155
156     @Test
157     public void updateCsarWithVFCArtifacts_AddAdditionalVFCIdentifier_TC1425898() throws Exception {
158
159         String csarFile = "LDSA-SINGLE.csar";
160         ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType("ciRes", NormativeTypesEnum.ROOT, ResourceCategoryEnum.APPLICATION_L4_DATABASE, getUser().getUserId(), ResourceTypeEnum.VF.toString());
161         resourceMetaData.setVersion("0.1");
162         ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, csarFile, getUser());
163
164         Map<String, Object> artifactsFromCsar = ArtifactFromCsar.getVFCArtifacts(filePath + csarFile);
165         List<String> vfcKeys = artifactsFromCsar.keySet().stream().filter(p -> p.contains("vfc")).collect(Collectors.toList());
166         for (String key : vfcKeys) {
167             VFCArtifactVerificator.setActualVfcArtifactList(key, resourceMetaData, getUser());
168         }
169
170         ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
171         String[] artifactNamesFromFile = ArtifactFromCsar.getArtifactNamesFromCsar(filePath, csarFile);
172         String[] artifactsFromFileBeforeUpdate = DeploymentArtifactPage.verifyArtifactsExistInTable(artifactNamesFromFile);
173         DeploymentArtifactPage.getLeftMenu().moveToGeneralScreen();
174
175         String updatedCsarFile = "LDSA-MULTI.csar";
176         ResourceUIUtils.updateVfWithCsar(filePath, updatedCsarFile);
177
178         Map<String, Object> updatedArtifactsFromCsar = ArtifactFromCsar.getVFCArtifacts(filePath + updatedCsarFile);
179         List<String> updatedVfcKeys = updatedArtifactsFromCsar.keySet().stream().filter(p -> p.contains("vfc")).collect(Collectors.toList());
180         for (String key : updatedVfcKeys) {
181             verifyVfcInstanceArtifacts(resourceMetaData, null, updatedArtifactsFromCsar, key);
182             if (vfcKeys.contains(key)) {
183                 VFCArtifactVerificator.verifyVFCArtifactNotChanged(key, resourceMetaData, getUser());
184             }
185         }
186
187         ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
188         DeploymentArtifactPage.verifyArtifactsExistInTable(artifactsFromFileBeforeUpdate);
189     }
190
191     @Test
192     public void updateCsarWithVFCArtifacts_DeleteAll_TC1425581() throws Exception {
193
194         String csarFile = "LDSA-ORIG.csar";
195         ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType("ciRes", NormativeTypesEnum.ROOT, ResourceCategoryEnum.APPLICATION_L4_DATABASE, getUser().getUserId(), ResourceTypeEnum.VF.toString());
196         resourceMetaData.setVersion("0.1");
197         ResourceUIUtils.importVfFromCsar(resourceMetaData, filePath, csarFile, getUser());
198
199         ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
200         String[] artifactNamesFromFile = ArtifactFromCsar.getArtifactNamesFromCsar(filePath, csarFile);
201         String[] artifactsFromFileBeforeUpdate = DeploymentArtifactPage.verifyArtifactsExistInTable(artifactNamesFromFile);
202         DeploymentArtifactPage.getLeftMenu().moveToGeneralScreen();
203
204         String updatedCsarFile = "LDSA-DELETE-ALL.csar";
205         ResourceUIUtils.updateVfWithCsar(filePath, updatedCsarFile);
206
207         VFCArtifactVerificator.verifyNoVfcArtifacts(resourceMetaData, getUser(), null);
208
209         ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
210         DeploymentArtifactPage.verifyArtifactsExistInTable(artifactsFromFileBeforeUpdate);
211     }
212
213     @Test
214     public void importComplexVFCArtifacts_Onboarding_TC1484153() throws Exception {
215
216         ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
217
218         String vnfFile = "2016-043_vsaegw_fdnt_30_1607_e2e.zip";
219         String snmpFile = "Fault-alarms-ASDC-vprobes-vLB.zip";
220
221         VendorLicenseModel vendorLicenseModel = VendorLicenseModelRestUtils.createVendorLicense(getUser());
222         VendorSoftwareProductObject createVSP = VendorSoftwareProductRestUtils.createVSP(resourceMetaData, vnfFile, filePath, getUser(),
223             vendorLicenseModel);
224         String vspName = createVSP.getName();
225         resourceMetaData.setName(vspName);
226 //              VendorSoftwareProductObject resourceMeta = createVSP.right;
227         String vspid = createVSP.getVspId();
228         VendorSoftwareProductRestUtils.addVFCArtifacts(filePath, snmpFile, null, createVSP, getUser());
229         VendorSoftwareProductRestUtils.prepareVspForUse(getUser(), createVSP, true);
230
231         String downloadDirectory = getWindowTest().getDownloadDirectory();
232         String csarFile = vspid + ".csar";
233
234         DownloadManager.downloadCsarByNameFromVSPRepository(vspName, vspid);
235         HomePage.showVspRepository();
236         OnboardingUiUtils.importVSP(createVSP);
237         resourceMetaData.setVersion("0.1");
238
239         verifyVfcArtifacts(downloadDirectory, csarFile, resourceMetaData, null);
240
241         ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
242         DeploymentArtifactPage.verifyArtifactsExistInTable(filePath, vnfFile);
243
244     }
245
246     @Test
247     public void updateComplexVFCArtifacts_AddRemove_Onboarding_TC1484185() throws Exception {
248
249         //check of version is 1
250         ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
251
252         String vnfFile = "2016-043_vsaegw_fdnt_30_1607_e2e.zip";
253         String snmpPollFile = "vprobes-vLB.zip";
254         String updatedSnmpPollFile = "vprobes-vLBAgent.zip";
255
256         VendorLicenseModel vendorLicenseModel = VendorLicenseModelRestUtils.createVendorLicense(getUser());
257         VendorSoftwareProductObject createVSP = VendorSoftwareProductRestUtils.createVSP(resourceMetaData, vnfFile, filePath, getUser(),
258             vendorLicenseModel);
259         String vspName = createVSP.getName();
260         resourceMetaData.setName(vspName);
261         String vspid = createVSP.getVspId();
262         String monitoringComponentId = VendorSoftwareProductRestUtils.addVFCArtifacts(filePath, snmpPollFile, null, createVSP, getUser());
263         VendorSoftwareProductRestUtils.prepareVspForUse(getUser(), createVSP, true);
264
265         String downloadDirectory = getWindowTest().getDownloadDirectory();
266         String csarFile = vspid + ".csar";
267
268         DownloadManager.downloadCsarByNameFromVSPRepository(vspName, vspid);
269         HomePage.showVspRepository();
270         OnboardingUiUtils.importVSP(createVSP);
271         ResourceGeneralPage.clickCertifyButton(vspName);
272
273         VendorSoftwareProductRestUtils.updateVspWithVfcArtifacts(filePath, updatedSnmpPollFile, null, monitoringComponentId, getUser(), createVSP);
274         DownloadManager.downloadCsarByNameFromVSPRepository(vspName, vspid);
275         HomePage.showVspRepository();
276         OnboardingUiUtils.updateVSP(createVSP);
277         resourceMetaData.setVersion("1.1");
278
279         ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
280         DeploymentArtifactPage.verifyArtifactsExistInTable(filePath, vnfFile);
281
282         verifyVfcArtifacts(downloadDirectory, csarFile, resourceMetaData, null);
283
284     }
285
286     @Test
287     public void updateComplexVFCArtifacts_Modify_Onboarding_TC1484195() throws Exception {
288
289         //check of version is 2
290         ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
291
292         String vnfFile = "2016-043_vsaegw_fdnt_30_1607_e2e.zip";
293         String snmpFile = "vprobes-vLB.zip";
294         String updatedSnmpFile = "vprobes-vLB-Modified.zip";
295
296         VendorLicenseModel vendorLicenseModel = VendorLicenseModelRestUtils.createVendorLicense(getUser());
297         VendorSoftwareProductObject createVSP = VendorSoftwareProductRestUtils.createVSP(resourceMetaData, vnfFile, filePath, getUser(),
298             vendorLicenseModel);
299         String vspName = createVSP.getName();
300         resourceMetaData.setName(vspName);
301         String vspid = createVSP.getVspId();
302         String monitoringId = VendorSoftwareProductRestUtils.addVFCArtifacts(filePath, snmpFile, null, createVSP, getUser());
303         VendorSoftwareProductRestUtils.prepareVspForUse(getUser(), createVSP, true);
304
305         String downloadDirectory = getWindowTest().getDownloadDirectory();
306         String csarFile = vspid + ".csar";
307
308         DownloadManager.downloadCsarByNameFromVSPRepository(vspName, vspid);
309         HomePage.showVspRepository();
310         OnboardingUiUtils.importVSP(createVSP);
311
312         Map<String, Object> artifactsFromCsar = ArtifactFromCsar.getVFCArtifacts(downloadDirectory + csarFile);
313         List<String> vfcKeys = artifactsFromCsar.keySet().stream().filter(p -> p.contains("vfc")).collect(Collectors.toList());
314         for (String key : vfcKeys) {
315             resourceMetaData.setVersion("0.1");
316             VFCArtifactVerificator.setActualVfcArtifactList(key, resourceMetaData, getUser());
317         }
318
319         ResourceGeneralPage.clickCertifyButton(vspName);
320         VendorSoftwareProductRestUtils.updateVspWithVfcArtifacts(filePath, updatedSnmpFile, null, monitoringId, getUser(), createVSP);
321         DownloadManager.downloadCsarByNameFromVSPRepository(vspName, vspid);
322         HomePage.showVspRepository();
323         OnboardingUiUtils.updateVSP(createVSP);
324         resourceMetaData.setVersion("1.1");
325
326         ResourceGeneralPage.getLeftMenu().moveToDeploymentArtifactScreen();
327         DeploymentArtifactPage.verifyArtifactsExistInTable(filePath, vnfFile);
328
329         Map<String, Object> artifactsFromCsarAfterUpdate = ArtifactFromCsar.getVFCArtifacts(downloadDirectory + csarFile);
330         List<String> vfcKeysAfterUpdate = artifactsFromCsarAfterUpdate.keySet().stream().filter(p -> p.contains("vfc")).collect(Collectors.toList());
331         for (String key : vfcKeysAfterUpdate) {
332             verifyVfcInstanceArtifacts(resourceMetaData, null, artifactsFromCsarAfterUpdate, key);
333             VFCArtifactVerificator.verifyVfcArtifactUpdated(key, resourceMetaData, getUser());
334         }
335
336     }
337
338
339     @Override
340     protected UserRoleEnum getRole() {
341         return UserRoleEnum.DESIGNER;
342     }
343
344     private Map<String, LinkedList<HeatMetaFirstLevelDefinition>> verifyVfcArtifacts(String filepath, String csarFile,
345                                                                                      ResourceReqDetails resourceMetaData, RestResponse getResponse) throws Exception {
346
347         ExtentTestActions.log(Status.INFO, "Verifying VFC artifacts");
348         Map<String, LinkedList<HeatMetaFirstLevelDefinition>> expectedArtifactMap = null;
349         ExtentTestActions.log(Status.INFO, "Reading artifacts in CSAR file");
350         Map<String, Object> artifactsFromCsar = ArtifactFromCsar.getVFCArtifacts(filepath + csarFile);
351         List<String> vfcKeys = artifactsFromCsar.keySet().stream().filter(p -> p.contains("vfc")).collect(Collectors.toList());
352         for (String key : vfcKeys) {
353             expectedArtifactMap = verifyVfcInstanceArtifacts(resourceMetaData, getResponse, artifactsFromCsar, key);
354         }
355         return expectedArtifactMap;
356     }
357
358     private Map<String, LinkedList<HeatMetaFirstLevelDefinition>> verifyVfcInstanceArtifacts(
359             ResourceReqDetails resourceMetaData, RestResponse getResponse, Map<String, Object> artifactsFromCsar, String key) {
360
361         Map<String, LinkedList<HeatMetaFirstLevelDefinition>> expectedArtifactMap;
362         Map<String, LinkedList<HeatMetaFirstLevelDefinition>> vfcDeploymentArtifacts = (Map<String, LinkedList<HeatMetaFirstLevelDefinition>>) artifactsFromCsar.get(key);
363         LinkedList<HeatMetaFirstLevelDefinition> deploymentList = vfcDeploymentArtifacts.get(DEPLOYMENT);
364         LinkedList<HeatMetaFirstLevelDefinition> informationalList = (LinkedList<HeatMetaFirstLevelDefinition>) vfcDeploymentArtifacts.get(INFORMATIONAL);
365
366         expectedArtifactMap = new HashMap<String, LinkedList<HeatMetaFirstLevelDefinition>>();
367         if (deploymentList == null) {
368             expectedArtifactMap.put(DEPLOYMENT_ARTIFACTS, new LinkedList<HeatMetaFirstLevelDefinition>());
369         } else {
370             expectedArtifactMap.put(DEPLOYMENT_ARTIFACTS, deploymentList);
371         }
372         if (informationalList == null) {
373             expectedArtifactMap.put(ARTIFACTS, new LinkedList<HeatMetaFirstLevelDefinition>());
374         } else {
375             expectedArtifactMap.put(ARTIFACTS, informationalList);
376         }
377
378         VFCArtifactVerificator.verifyVfcArtifacts(resourceMetaData, getUser(), key, expectedArtifactMap, getResponse);
379         return expectedArtifactMap;
380     }
381 }