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.ci.tests.verificator;
23 import static org.testng.Assert.assertFalse;
24 import static org.testng.Assert.assertTrue;
27 import java.io.IOException;
28 import java.util.ArrayList;
29 import java.util.Arrays;
30 import java.util.HashMap;
31 import java.util.LinkedList;
32 import java.util.List;
34 import java.util.UUID;
35 import java.util.stream.Collectors;
36 import java.util.stream.Stream;
38 import org.apache.commons.io.FileUtils;
39 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
40 import org.openecomp.sdc.ci.tests.datatypes.HeatMetaFirstLevelDefinition;
41 import org.openecomp.sdc.ci.tests.datatypes.enums.GroupPropertyEnum;
42 import org.openecomp.sdc.ci.tests.execute.devCI.ArtifactFromCsar;
43 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
44 import org.openecomp.sdc.ci.tests.pages.DeploymentPage;
45 import org.openecomp.sdc.ci.tests.pages.ResourceGeneralPage;
46 import org.openecomp.sdc.ci.tests.tosca.datatypes.ToscaDefinition;
47 import org.openecomp.sdc.ci.tests.tosca.datatypes.ToscaGroupsTopologyTemplateDefinition;
48 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
49 import org.openecomp.sdc.ci.tests.utils.ToscaParserUtils;
50 import org.openqa.selenium.WebElement;
52 import com.aventstack.extentreports.Status;
54 public class DeploymentViewVerificator {
56 //GroupPropertyEnum.getGroupPropertyNames();
57 private static List<String> currentPropertiesForUI = Arrays.asList("isBase",
59 "vf_module_description",
60 "min_vf_module_instances",
61 "max_vf_module_instances",
63 "vf_module_type", //works as isBase property, value can be Base/Expantion
66 "availability_zone_count");
68 //GroupPropertyEnum.getGroupPropertyNamesWithoutIsbase();
69 private static List<String> currentPropertiesWithoutIsBaseForFile = Arrays.asList("vf_module_label",
70 "vf_module_description",
71 "min_vf_module_instances",
72 "max_vf_module_instances",
74 "vf_module_type", //works as isBase property, value can be Base/Expantion
77 "availability_zone_count");
79 public static List<String> getCurrentProperties() {
80 return currentPropertiesForUI;
83 public static List<String> getCurrentPropertiesWithoutIsBase() {
84 return currentPropertiesWithoutIsBaseForFile;
88 public static final String partToReplace = "_group";
90 private static Map<String, HashMap<String, List<String>>> deploymentViewData = new HashMap<String, HashMap<String, List<String>>>(){
92 HashMap<String, List<String>> segw_heat_c3_base , segw_heat_c3_VMs1 ;
94 segw_heat_c3_base = new HashMap<String, List<String>>();
95 segw_heat_c3_base.put("members", Arrays.asList("segw_internet_security_group", "segw_security_group", "int_layer2vlan_net"));
96 segw_heat_c3_base.put("artifacts", Arrays.asList("segw_heat_c3_base.yml", "segw_heat_c3_base.env"));
97 segw_heat_c3_base.put("properties", currentPropertiesForUI);
98 put("segw_heat_c3_base", segw_heat_c3_base);
99 segw_heat_c3_VMs1 = new HashMap<String, List<String>>();
100 segw_heat_c3_VMs1.put("members", Arrays.asList("segw_oam_protected_0_port",
101 "fw_oam_int_layer2vlan_1_port",
102 "segw_0", "segw_internet_1_port",
103 "segw_layer2vlan_2_port",
104 "fw_gn_0", "fw_gn_hsl_direct_3_port",
105 "fw_oam_oam_mgmt_0_port",
106 "fw_oam_hsl_direct_3_port",
107 "fw_gn_oam_mgmt_0_port",
108 "fw_oam_oam_direct_2_port",
109 "fw_gn_gn_direct_2_port",
111 "fw_gn_int_layer2vlan_1_port"));
112 segw_heat_c3_VMs1.put("artifacts", Arrays.asList("segw_heat_c3_VMs1.yml", "segw_heat_c3_VMs1.env"));
113 segw_heat_c3_VMs1.put("properties", currentPropertiesForUI);
114 put("segw_heat_c3_VMs1", segw_heat_c3_VMs1);
118 private static Map<String, HashMap<String, List<String>>> deploymentViewDataMixedArtifacts = new HashMap<String, HashMap<String, List<String>>>(){
120 HashMap<String, List<String>> module_1_ldsa, module_2_ldsa, base_ldsa;
122 module_1_ldsa = new HashMap<String, List<String>>();
123 module_1_ldsa.put("members", Stream.of("ltm_oam_protected_0_port", "ltm_dmz_direct_0_port", "ltm_server_0").collect(Collectors.toList()));
124 module_1_ldsa.put("artifacts", Stream.of("module_1_ldsa.yaml", "module_1_ldsa.env", "base_ldsa.33.yaml", "module_1_ldsa.11.yaml").collect(Collectors.toList()));
125 module_1_ldsa.put("properties", currentPropertiesForUI);
126 put("module_1_ldsa", module_1_ldsa);
127 module_2_ldsa = new HashMap<String, List<String>>();
128 module_2_ldsa.put("members", Stream.of("ltm_server_0").collect(Collectors.toList()));
129 module_2_ldsa.put("artifacts", Stream.of("module_2_ldsa.yaml", "module_2_ldsa.env", "base_ldsa.3.yaml", "module_2_ldsa.22.yaml").collect(Collectors.toList()));
130 module_2_ldsa.put("properties", currentPropertiesForUI);
131 put("module_2_ldsa", module_2_ldsa);
132 base_ldsa = new HashMap<String, List<String>>();
133 base_ldsa.put("members", Stream.of("ldsa_sec_grp_1").collect(Collectors.toList()));
134 base_ldsa.put("artifacts", Stream.of("base_ldsa.yaml", "module_2_ldsa.2.yaml", "module_1_ldsa.1.yaml").collect(Collectors.toList()));
135 base_ldsa.put("properties", currentPropertiesForUI);
136 put("base_ldsa", base_ldsa);
141 private Map<String, HashMap<String, List<String>>> deploymentViewDataFromFile;
143 public DeploymentViewVerificator(String pathToCsar) throws Exception {
144 deploymentViewDataFromFile = buildDeploymentViewDataFromCSAR(pathToCsar);
147 public DeploymentViewVerificator() throws Exception {
148 deploymentViewDataFromFile = deploymentViewDataMixedArtifacts;
152 public void verifyDeploymentPageSubElements(String moduleName) throws Exception{
153 HashMap<String, List<String>> moduleProperties = getDeploymentViewData().get(moduleName);
155 // add env placeholder to deployment view data
156 if (!moduleProperties.get("artifacts").contains(moduleName + ".env")){
157 moduleProperties.get("artifacts").add(moduleName + ".env");
160 List<WebElement> members, artifacts, properties;
161 members = DeploymentPage.getGroupMembersList(moduleName);
162 artifacts = DeploymentPage.getArtifactNames();
163 properties = DeploymentPage.getPropertyNames();
165 File imageFilePath = GeneralUIUtils.takeScreenshot(moduleName + UUID.randomUUID(), SetupCDTest.getScreenshotFolder(), null);
166 final String absolutePath = new File(SetupCDTest.getReportFolder()).toURI().relativize(imageFilePath.toURI()).getPath();
167 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Validating group %s, should be %s members, %s artifacts " + SetupCDTest.getExtendTest().addScreenCaptureFromPath(absolutePath),
168 moduleName, moduleProperties.get("members").size(), moduleProperties.get("artifacts").size()));
170 assertTrue(moduleProperties.get("artifacts").size() == artifacts.size(), "Artifacts amount not as expected, expected " + moduleProperties.get("artifacts").size());
171 assertTrue(moduleProperties.get("artifacts").containsAll(artifacts.stream().
172 map(e -> e.getAttribute("textContent")).
173 collect(Collectors.toList())));
174 assertTrue(moduleProperties.get("members").size() == members.size(), "Members amount not as expected, expected " + moduleProperties.get("members").size());
175 assertTrue(moduleProperties.get("members").containsAll(members.stream().
176 map(e -> e.getAttribute("textContent")).
177 collect(Collectors.toList())));
178 assertTrue(moduleProperties.get("properties").size() == properties.size(), "Properties amount not as expected, expected " + moduleProperties.get("properties").size());
179 assertTrue(moduleProperties.get("properties").containsAll(properties.stream().
180 map(e -> e.getAttribute("textContent")).
181 collect(Collectors.toList())));
182 DeploymentPage.clickOnProperties();
183 DeploymentPage.clickOnArtifacts();
186 public void verifyDeploymentPageModules(List<WebElement> modules){
187 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Validating VF groups , should be %s groups ", getDeploymentViewData().size()));
188 assertFalse(modules.isEmpty(), "No modules found");
189 assertTrue(modules.size() == getDeploymentViewData().size(), "Modules amount not as expected, expected " + getDeploymentViewData().size());
190 for (WebElement module: modules){
191 assertTrue(getDeploymentViewData().containsKey(module.getText().split("\\.\\.")[1]));
195 public static void verifyComponentNameChanged(String oldName, String newName){
197 GeneralUIUtils.clickOnElementByText(oldName, 10);
198 assertTrue(false, "Element name don't changed");
199 } catch(Exception e){
200 GeneralUIUtils.clickOnElementByText(newName);
204 public Map<String, HashMap<String, List<String>>> getDeploymentViewData() {
205 // return deploymentViewData;
206 return getDeploymentViewDataFromFile();
209 public static Map<String, HashMap<String, List<String>>> buildDeploymentViewDataFromCSAR(String pathToCSAR) throws Exception{
210 ToscaDefinition toscaDefinition = ToscaParserUtils.parseToscaMainYamlToJavaObjectByCsarLocation(new File(pathToCSAR));
211 Map<String, HashMap<String, List<String>>> deploymentViewDataFromFile = new HashMap<String, HashMap<String, List<String>>>();
212 Map<String, ToscaGroupsTopologyTemplateDefinition> groups = toscaDefinition.getTopology_template().getGroups();
213 List<String> keyList = groups.keySet().stream().collect(Collectors.toList());
214 HashMap<String, List<String>> groupsToArtifacts = getDeploymentArtifactsMappedToGroupsFromCSAR(pathToCSAR);
215 for(String groupKey: keyList){
216 HashMap<String, List<String>> tempGroupMap = new HashMap<String, List<String>>();
217 tempGroupMap.put("artifacts", groupsToArtifacts.get(convertAmdocsCsarGroupNameToSdcCsarGroupName(groupKey)));
218 if (groups.get(groupKey).getMembers() == null){
219 tempGroupMap.put("members", Arrays.asList());
221 tempGroupMap.put("members", groups.get(groupKey).getMembers());
223 tempGroupMap.put("properties", currentPropertiesForUI);
224 deploymentViewDataFromFile.put(convertAmdocsCsarGroupNameToSdcCsarGroupName(groupKey), tempGroupMap);
226 return deploymentViewDataFromFile;
229 public static HashMap<String, List<String>> getDeploymentArtifactsMappedToGroupsFromCSAR(String pathToFile) throws Exception {
230 Map<String, Object> combinedMap = ArtifactFromCsar.combineHeatArtifacstWithFolderArtifacsToMap(pathToFile);
231 LinkedList<HeatMetaFirstLevelDefinition> deploymentArtifacts = ((LinkedList<HeatMetaFirstLevelDefinition>) combinedMap.get("Deployment"));
233 HashMap<String, List<String>> tempGroupMap = new HashMap<String, List<String>>();
234 for(HeatMetaFirstLevelDefinition deploymentArtifact: deploymentArtifacts) {
235 String groupName = deploymentArtifact.getFileName().trim().substring(0, deploymentArtifact.getFileName().indexOf("."));
236 if(deploymentArtifact.getType().equals("HEAT") || deploymentArtifact.getType().equals("HEAT_NET") || deploymentArtifact.getType().equals("HEAT_VOL")) {
237 List<String> list = new ArrayList<>();
238 list.add(deploymentArtifact.getFileName().trim());
239 tempGroupMap.put(groupName, list);
241 // update current key
242 List<String> list = tempGroupMap.get(groupName);
243 list.add(deploymentArtifact.getFileName().trim());
244 tempGroupMap.put(groupName, list);
251 public static void cleanFolders(String outputFolder) throws IOException {
253 FileUtils.cleanDirectory(new File(outputFolder));
254 FileUtils.deleteDirectory(new File(outputFolder));
257 public static String unzipCsarFile(String pathToCsar) {
258 File csarFile = new File(pathToCsar);
261 File dir = new File(csarFile.getParent() + File.separator + "output"+ UUID.randomUUID() + File.separator + UUID.randomUUID());
266 String outputFolder = dir.getPath();
267 ArtifactFromCsar.unZip(pathToCsar, outputFolder);
271 public static void validateEditPopoverFields(String expectedVNFName, String expectedHeatName, String expectedModuleName){
272 String VNFname = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.DeploymentScreen.RESOURCE_NAME_ON_POPOVER.getValue()).getText();
273 String heatName = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.DeploymentScreen.NAME_INPUT.getValue()).getAttribute("value");
274 String moduleName = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.DeploymentScreen.MODULE_NAME_ON_POPOVER.getValue()).getText();
275 assertTrue(expectedVNFName.equals(VNFname), String.format("VNF name Expected: %s, Actual: %s ", expectedVNFName, VNFname));
276 assertTrue(expectedHeatName.equals(heatName), String.format("HEAT name Expected: %s, Actual: %s ", expectedHeatName, heatName ));
277 assertTrue(expectedModuleName.equals(moduleName), String.format("Module name Expected: %s, Actual: %s ", expectedModuleName, moduleName));
280 public static void validateEditPopoverButtons(String newName, String invalidModuleName, String validModueName ){
281 DeploymentPage.updateAndCancel(newName, DataTestIdEnum.DeploymentScreen.X_BUTTON);
282 verifyComponentNameChanged(invalidModuleName, validModueName);
283 DeploymentPage.clickOnEditIcon();
284 DeploymentPage.updateAndCancel(newName, DataTestIdEnum.DeploymentScreen.CANCEL);
285 verifyComponentNameChanged(invalidModuleName, validModueName);
288 public static void validateEditPopover() throws Exception{
289 String moduleRowText = GeneralUIUtils.getElementsByCSS(DataTestIdEnum.DeploymentScreen.MODULES.getValue()).get(0).getText();
290 DeploymentPage.clickOnModuleName(moduleRowText);
291 DeploymentPage.clickOnEditIcon();
292 String[] splitedModuleName = moduleRowText.split("\\.\\.");
294 validateEditPopoverFields(splitedModuleName[0], splitedModuleName[1], splitedModuleName[2]);
296 String newName = "kuku";
297 String newModuleName = DeploymentPage.reconstructModuleName(splitedModuleName, newName);
298 validateEditPopoverButtons(newName, newModuleName, moduleRowText);
301 private Map<String, HashMap<String, List<String>>> getDeploymentViewDataFromFile() {
302 return deploymentViewDataFromFile;
305 public static void validateModuleNameUpadate() throws Exception{
306 List<WebElement> moduleRowsFromTable = GeneralUIUtils.getElementsByCSS(DataTestIdEnum.DeploymentScreen.MODULES.getValue());
308 for(WebElement moduleRow :moduleRowsFromTable){
309 String moduleRowText = moduleRow.getText();
310 String updatedName = "updatedName" + i;
311 DeploymentPage.updateModuleName(moduleRowText, updatedName);
312 String updatedModuleName = DeploymentPage.reconstructModuleName(moduleRowText.split("\\.\\."), updatedName);
313 verifyComponentNameChanged(moduleRowText, updatedModuleName);
315 GeneralUIUtils.clickOnElementByText(updatedModuleName);
320 public static void regularDepoymentScreenVerificator(Map<String, HashMap<String, String>> metaDataFromUI, DeploymentViewVerificator verificator) throws Exception, InterruptedException {
321 ResourceGeneralPage.getLeftMenu().moveToDeploymentViewScreen();
322 List<WebElement> moduleRowsFromTable = GeneralUIUtils.getElementsByCSS(DataTestIdEnum.DeploymentScreen.MODULES.getValue());
323 verificator.verifyDeploymentPageModules(moduleRowsFromTable);
324 for(WebElement moduleRow :moduleRowsFromTable){
325 String moduleRowText = moduleRow.getText();
326 String middleName = moduleRowText.split("\\.\\.")[1];
327 verificator.verifyDeploymentPageSubElements(middleName);
328 if (metaDataFromUI != null){
329 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Validating %s group version, should be %s ", moduleRowText, metaDataFromUI.get(moduleRowText.split("\\.\\.")[1])));
330 String groupVersion = DeploymentPage.getGroupVersion().split(":")[1].trim();
331 String increasedVersion = String.valueOf(Integer.parseInt(metaDataFromUI.get(middleName).get("version")) + 1);
332 assertTrue(groupVersion.equals(increasedVersion));
333 if ( metaDataFromUI.get(middleName).get("moduleID") != "primary"){
334 String moduleID = DeploymentPage.getModuleID();
335 assertFalse(moduleID.equals(metaDataFromUI.get(middleName).get("moduleID")));
339 GeneralUIUtils.clickOnElementByText(moduleRowText);
343 public static String convertAmdocsCsarGroupNameToSdcCsarGroupName(String originalString){
344 return originalString.replace(partToReplace, "");