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 com.aventstack.extentreports.Status;
24 import org.apache.commons.io.FileUtils;
25 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
26 import org.openecomp.sdc.ci.tests.datatypes.HeatMetaFirstLevelDefinition;
27 import org.openecomp.sdc.ci.tests.execute.devCI.ArtifactFromCsar;
28 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
29 import org.openecomp.sdc.ci.tests.pages.DeploymentPage;
30 import org.openecomp.sdc.ci.tests.pages.ResourceGeneralPage;
31 import org.openecomp.sdc.ci.tests.tosca.datatypes.ToscaDefinition;
32 import org.openecomp.sdc.ci.tests.tosca.datatypes.ToscaGroupsTopologyTemplateDefinition;
33 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
34 import org.openecomp.sdc.ci.tests.utils.ToscaParserUtils;
35 import org.openqa.selenium.WebElement;
38 import java.io.IOException;
40 import java.util.stream.Collectors;
41 import java.util.stream.Stream;
43 import static org.testng.Assert.assertFalse;
44 import static org.testng.Assert.assertTrue;
46 public class DeploymentViewVerificator {
48 //GroupPropertyEnum.getGroupPropertyNames();
49 private static List<String> currentPropertiesForUI = Arrays.asList("isBase",
51 "vf_module_description",
52 "min_vf_module_instances",
53 "max_vf_module_instances",
55 "vf_module_type", //works as isBase property, value can be Base/Expantion
58 "availability_zone_count");
60 //GroupPropertyEnum.getGroupPropertyNamesWithoutIsbase();
61 private static List<String> currentPropertiesWithoutIsBaseForFile = Arrays.asList("vf_module_label",
62 "vf_module_description",
63 "min_vf_module_instances",
64 "max_vf_module_instances",
66 "vf_module_type", //works as isBase property, value can be Base/Expantion
69 "availability_zone_count");
71 public static List<String> getCurrentProperties() {
72 return currentPropertiesForUI;
75 public static List<String> getCurrentPropertiesWithoutIsBase() {
76 return currentPropertiesWithoutIsBaseForFile;
80 public static final String partToReplace = "_group";
82 private static Map<String, HashMap<String, List<String>>> deploymentViewData = new HashMap<String, HashMap<String, List<String>>>(){
84 HashMap<String, List<String>> segw_heat_c3_base , segw_heat_c3_VMs1 ;
86 segw_heat_c3_base = new HashMap<String, List<String>>();
87 segw_heat_c3_base.put("members", Arrays.asList("segw_internet_security_group", "segw_security_group", "int_layer2vlan_net"));
88 segw_heat_c3_base.put("artifacts", Arrays.asList("segw_heat_c3_base.yml", "segw_heat_c3_base.env"));
89 segw_heat_c3_base.put("properties", currentPropertiesForUI);
90 put("segw_heat_c3_base", segw_heat_c3_base);
91 segw_heat_c3_VMs1 = new HashMap<String, List<String>>();
92 segw_heat_c3_VMs1.put("members", Arrays.asList("segw_oam_protected_0_port",
93 "fw_oam_int_layer2vlan_1_port",
94 "segw_0", "segw_internet_1_port",
95 "segw_layer2vlan_2_port",
96 "fw_gn_0", "fw_gn_hsl_direct_3_port",
97 "fw_oam_oam_mgmt_0_port",
98 "fw_oam_hsl_direct_3_port",
99 "fw_gn_oam_mgmt_0_port",
100 "fw_oam_oam_direct_2_port",
101 "fw_gn_gn_direct_2_port",
103 "fw_gn_int_layer2vlan_1_port"));
104 segw_heat_c3_VMs1.put("artifacts", Arrays.asList("segw_heat_c3_VMs1.yml", "segw_heat_c3_VMs1.env"));
105 segw_heat_c3_VMs1.put("properties", currentPropertiesForUI);
106 put("segw_heat_c3_VMs1", segw_heat_c3_VMs1);
110 private static Map<String, HashMap<String, List<String>>> deploymentViewDataMixedArtifacts = new HashMap<String, HashMap<String, List<String>>>(){
112 HashMap<String, List<String>> module_1_ldsa, module_2_ldsa, base_ldsa;
114 module_1_ldsa = new HashMap<String, List<String>>();
115 module_1_ldsa.put("members", Stream.of("ltm_oam_protected_0_port", "ltm_dmz_direct_0_port", "ltm_server_0").collect(Collectors.toList()));
116 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()));
117 module_1_ldsa.put("properties", currentPropertiesForUI);
118 put("module_1_ldsa", module_1_ldsa);
119 module_2_ldsa = new HashMap<String, List<String>>();
120 module_2_ldsa.put("members", Stream.of("ltm_server_0").collect(Collectors.toList()));
121 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()));
122 module_2_ldsa.put("properties", currentPropertiesForUI);
123 put("module_2_ldsa", module_2_ldsa);
124 base_ldsa = new HashMap<String, List<String>>();
125 base_ldsa.put("members", Stream.of("ldsa_sec_grp_1").collect(Collectors.toList()));
126 base_ldsa.put("artifacts", Stream.of("base_ldsa.yaml", "module_2_ldsa.2.yaml", "module_1_ldsa.1.yaml").collect(Collectors.toList()));
127 base_ldsa.put("properties", currentPropertiesForUI);
128 put("base_ldsa", base_ldsa);
133 private Map<String, HashMap<String, List<String>>> deploymentViewDataFromFile;
135 public DeploymentViewVerificator(String pathToCsar) throws Exception {
136 deploymentViewDataFromFile = buildDeploymentViewDataFromCSAR(pathToCsar);
139 public DeploymentViewVerificator() throws Exception {
140 deploymentViewDataFromFile = deploymentViewDataMixedArtifacts;
144 public void verifyDeploymentPageSubElements(String moduleName) throws Exception{
145 HashMap<String, List<String>> moduleProperties = getDeploymentViewData().get(moduleName);
147 // add env placeholder to deployment view data
148 if (!moduleProperties.get("artifacts").contains(moduleName + ".env")){
149 moduleProperties.get("artifacts").add(moduleName + ".env");
152 List<WebElement> members, artifacts, properties;
153 members = DeploymentPage.getGroupMembersList(moduleName);
154 artifacts = DeploymentPage.getArtifactNames();
155 properties = DeploymentPage.getPropertyNames();
157 File imageFilePath = GeneralUIUtils.takeScreenshot(moduleName + UUID.randomUUID(), SetupCDTest.getScreenshotFolder(), null);
158 final String absolutePath = new File(SetupCDTest.getReportFolder()).toURI().relativize(imageFilePath.toURI()).getPath();
159 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Validating group %s, should be %s members, %s artifacts " + SetupCDTest.getExtendTest().addScreenCaptureFromPath(absolutePath),
160 moduleName, moduleProperties.get("members").size(), moduleProperties.get("artifacts").size()));
162 assertTrue(moduleProperties.get("artifacts").size() == artifacts.size(), "Artifacts amount not as expected, expected " + moduleProperties.get("artifacts").size());
163 assertTrue(moduleProperties.get("artifacts").containsAll(artifacts.stream().
164 map(e -> e.getAttribute("textContent")).
165 collect(Collectors.toList())));
166 assertTrue(moduleProperties.get("members").size() == members.size(), "Members amount not as expected, expected " + moduleProperties.get("members").size());
167 assertTrue(moduleProperties.get("members").containsAll(members.stream().
168 map(e -> e.getAttribute("textContent")).
169 collect(Collectors.toList())));
170 assertTrue(moduleProperties.get("properties").size() == properties.size(), "Properties amount not as expected, expected " + moduleProperties.get("properties").size());
171 assertTrue(moduleProperties.get("properties").containsAll(properties.stream().
172 map(e -> e.getAttribute("textContent")).
173 collect(Collectors.toList())));
174 DeploymentPage.clickOnProperties();
175 DeploymentPage.clickOnArtifacts();
178 public void verifyDeploymentPageModules(List<WebElement> modules){
179 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Validating VF groups , should be %s groups ", getDeploymentViewData().size()));
180 assertFalse(modules.isEmpty(), "No modules found");
181 assertTrue(modules.size() == getDeploymentViewData().size(), "Modules amount not as expected, expected " + getDeploymentViewData().size());
182 for (WebElement module: modules){
183 assertTrue(getDeploymentViewData().containsKey(module.getText().split("\\.\\.")[1]));
187 public static void verifyComponentNameChanged(String oldName, String newName){
189 GeneralUIUtils.clickOnElementByText(oldName, 10);
190 assertTrue(false, "Element name don't changed");
191 } catch(Exception e){
192 GeneralUIUtils.clickOnElementByText(newName);
196 public Map<String, HashMap<String, List<String>>> getDeploymentViewData() {
197 // return deploymentViewData;
198 return getDeploymentViewDataFromFile();
201 public static Map<String, HashMap<String, List<String>>> buildDeploymentViewDataFromCSAR(String pathToCSAR) throws Exception{
202 ToscaDefinition toscaDefinition = ToscaParserUtils.parseToscaMainYamlToJavaObjectByCsarLocation(new File(pathToCSAR));
203 Map<String, HashMap<String, List<String>>> deploymentViewDataFromFile = new HashMap<String, HashMap<String, List<String>>>();
204 Map<String, ToscaGroupsTopologyTemplateDefinition> groups = toscaDefinition.getTopology_template().getGroups();
205 List<String> keyList = groups.keySet().stream().collect(Collectors.toList());
206 HashMap<String, List<String>> groupsToArtifacts = getDeploymentArtifactsMappedToGroupsFromCSAR(pathToCSAR);
207 for(String groupKey: keyList){
208 HashMap<String, List<String>> tempGroupMap = new HashMap<String, List<String>>();
209 tempGroupMap.put("artifacts", groupsToArtifacts.get(convertAmdocsCsarGroupNameToSdcCsarGroupName(groupKey)));
210 if (groups.get(groupKey).getMembers() == null){
211 tempGroupMap.put("members", Arrays.asList());
213 tempGroupMap.put("members", groups.get(groupKey).getMembers());
215 tempGroupMap.put("properties", currentPropertiesForUI);
216 deploymentViewDataFromFile.put(convertAmdocsCsarGroupNameToSdcCsarGroupName(groupKey), tempGroupMap);
218 return deploymentViewDataFromFile;
221 public static HashMap<String, List<String>> getDeploymentArtifactsMappedToGroupsFromCSAR(String pathToFile) throws Exception {
222 Map<String, Object> combinedMap = ArtifactFromCsar.combineHeatArtifacstWithFolderArtifacsToMap(pathToFile);
223 LinkedList<HeatMetaFirstLevelDefinition> deploymentArtifacts = ((LinkedList<HeatMetaFirstLevelDefinition>) combinedMap.get("Deployment"));
225 HashMap<String, List<String>> tempGroupMap = new HashMap<String, List<String>>();
226 for(HeatMetaFirstLevelDefinition deploymentArtifact: deploymentArtifacts) {
227 String groupName = deploymentArtifact.getFileName().trim().substring(0, deploymentArtifact.getFileName().indexOf("."));
228 if(deploymentArtifact.getType().equals("HEAT") || deploymentArtifact.getType().equals("HEAT_NET") || deploymentArtifact.getType().equals("HEAT_VOL")) {
229 List<String> list = new ArrayList<>();
230 list.add(deploymentArtifact.getFileName().trim());
231 tempGroupMap.put(groupName, list);
233 // update current key
234 List<String> list = tempGroupMap.get(groupName);
235 list.add(deploymentArtifact.getFileName().trim());
236 tempGroupMap.put(groupName, list);
243 public static void cleanFolders(String outputFolder) throws IOException {
245 FileUtils.cleanDirectory(new File(outputFolder));
246 FileUtils.deleteDirectory(new File(outputFolder));
249 public static String unzipCsarFile(String pathToCsar) {
250 File csarFile = new File(pathToCsar);
253 File dir = new File(csarFile.getParent() + File.separator + "output"+ UUID.randomUUID() + File.separator + UUID.randomUUID());
258 String outputFolder = dir.getPath();
259 ArtifactFromCsar.unZip(pathToCsar, outputFolder);
263 public static void validateEditPopoverFields(String expectedVNFName, String expectedHeatName, String expectedModuleName){
264 String VNFname = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.DeploymentScreen.RESOURCE_NAME_ON_POPOVER.getValue()).getText();
265 String heatName = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.DeploymentScreen.NAME_INPUT.getValue()).getAttribute("value");
266 String moduleName = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.DeploymentScreen.MODULE_NAME_ON_POPOVER.getValue()).getText();
267 assertTrue(expectedVNFName.equals(VNFname), String.format("VNF name Expected: %s, Actual: %s ", expectedVNFName, VNFname));
268 assertTrue(expectedHeatName.equals(heatName), String.format("HEAT name Expected: %s, Actual: %s ", expectedHeatName, heatName ));
269 assertTrue(expectedModuleName.equals(moduleName), String.format("Module name Expected: %s, Actual: %s ", expectedModuleName, moduleName));
272 public static void validateEditPopoverButtons(String newName, String invalidModuleName, String validModueName ){
273 DeploymentPage.updateAndCancel(newName, DataTestIdEnum.DeploymentScreen.X_BUTTON);
274 verifyComponentNameChanged(invalidModuleName, validModueName);
275 DeploymentPage.clickOnEditIcon();
276 DeploymentPage.updateAndCancel(newName, DataTestIdEnum.DeploymentScreen.CANCEL);
277 verifyComponentNameChanged(invalidModuleName, validModueName);
280 public static void validateEditPopover() throws Exception{
281 String moduleRowText = GeneralUIUtils.getElementsByCSS(DataTestIdEnum.DeploymentScreen.MODULES.getValue()).get(0).getText();
282 DeploymentPage.clickOnModuleName(moduleRowText);
283 DeploymentPage.clickOnEditIcon();
284 String[] splitedModuleName = moduleRowText.split("\\.\\.");
286 validateEditPopoverFields(splitedModuleName[0], splitedModuleName[1], splitedModuleName[2]);
288 String newName = "kuku";
289 String newModuleName = DeploymentPage.reconstructModuleName(splitedModuleName, newName);
290 validateEditPopoverButtons(newName, newModuleName, moduleRowText);
293 private Map<String, HashMap<String, List<String>>> getDeploymentViewDataFromFile() {
294 return deploymentViewDataFromFile;
297 public static void validateModuleNameUpadate() throws Exception{
298 List<WebElement> moduleRowsFromTable = GeneralUIUtils.getElementsByCSS(DataTestIdEnum.DeploymentScreen.MODULES.getValue());
300 for(WebElement moduleRow :moduleRowsFromTable){
301 String moduleRowText = moduleRow.getText();
302 String updatedName = "updatedName" + i;
303 DeploymentPage.updateModuleName(moduleRowText, updatedName);
304 String updatedModuleName = DeploymentPage.reconstructModuleName(moduleRowText.split("\\.\\."), updatedName);
305 verifyComponentNameChanged(moduleRowText, updatedModuleName);
307 GeneralUIUtils.clickOnElementByText(updatedModuleName);
312 public static void regularDepoymentScreenVerificator(Map<String, HashMap<String, String>> metaDataFromUI, DeploymentViewVerificator verificator) throws Exception, InterruptedException {
313 ResourceGeneralPage.getLeftMenu().moveToDeploymentViewScreen();
314 List<WebElement> moduleRowsFromTable = GeneralUIUtils.getElementsByCSS(DataTestIdEnum.DeploymentScreen.MODULES.getValue());
315 verificator.verifyDeploymentPageModules(moduleRowsFromTable);
316 for(WebElement moduleRow :moduleRowsFromTable){
317 String moduleRowText = moduleRow.getText();
318 String middleName = moduleRowText.split("\\.\\.")[1];
319 verificator.verifyDeploymentPageSubElements(middleName);
320 if (metaDataFromUI != null){
321 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Validating %s group version, should be %s ", moduleRowText, metaDataFromUI.get(moduleRowText.split("\\.\\.")[1])));
322 String groupVersion = DeploymentPage.getGroupVersion().split(":")[1].trim();
323 String increasedVersion = String.valueOf(Integer.parseInt(metaDataFromUI.get(middleName).get("version")) + 1);
324 assertTrue(groupVersion.equals(increasedVersion));
325 if ( metaDataFromUI.get(middleName).get("moduleID") != "primary"){
326 String moduleID = DeploymentPage.getModuleID();
327 assertFalse(moduleID.equals(metaDataFromUI.get(middleName).get("moduleID")));
331 GeneralUIUtils.clickOnElementByText(moduleRowText);
335 public static String convertAmdocsCsarGroupNameToSdcCsarGroupName(String originalString){
336 return originalString.replace(partToReplace, "");