Provide user to specify the ouput name while declaring the atrributes
[sdc.git] / integration-tests / src / test / java / org / onap / sdc / frontend / ci / tests / pages / DeploymentArtifactPage.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * SDC\r
4  * ================================================================================\r
5  * Copyright (C) 2017, 2021 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  *\r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 \r
21 package org.onap.sdc.frontend.ci.tests.pages;\r
22 \r
23 import com.aventstack.extentreports.Status;\r
24 import org.apache.commons.text.WordUtils;\r
25 import org.onap.sdc.backend.ci.tests.datatypes.enums.ArtifactTypeEnum;\r
26 import org.onap.sdc.frontend.ci.tests.datatypes.ArtifactInfo;\r
27 import org.onap.sdc.frontend.ci.tests.datatypes.DataTestIdEnum;\r
28 import org.onap.sdc.frontend.ci.tests.execute.setup.ExtentTestActions;\r
29 import org.onap.sdc.frontend.ci.tests.execute.setup.SetupCDTest;\r
30 import org.onap.sdc.frontend.ci.tests.utilities.FileHandling;\r
31 import org.onap.sdc.frontend.ci.tests.utilities.GeneralUIUtils;\r
32 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;\r
33 import org.openqa.selenium.By;\r
34 import org.openqa.selenium.WebElement;\r
35 import org.testng.collections.Lists;\r
36 import java.util.List;\r
37 import java.util.stream.Collectors;\r
38 \r
39 public class DeploymentArtifactPage extends GeneralPageElements {\r
40 \r
41     protected DeploymentArtifactPage() {\r
42         super();\r
43     }\r
44 \r
45     public static ResourceLeftMenu getLeftPanel() {\r
46         return new ResourceLeftMenu();\r
47     }\r
48 \r
49     public static UploadArtifactPopup artifactPopup() {\r
50         return new UploadArtifactPopup();\r
51     }\r
52 \r
53     protected static void addNewArtifact(ArtifactGroupTypeEnum artifactGroupType) {\r
54         switch (artifactGroupType) {\r
55             case DEPLOYMENT:\r
56                 GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.ADD_DEPLOYMENT_ARTIFACT.getValue()).click();\r
57                 break;\r
58             case INFORMATIONAL:\r
59                 GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.ADD_INFORMATIONAL_ARTIFACT.getValue()).click();\r
60                 break;\r
61             default:\r
62                 break;\r
63         }\r
64     }\r
65 \r
66     public static void clickAddNewArtifact() {\r
67         addNewArtifact(ArtifactGroupTypeEnum.DEPLOYMENT);\r
68     }\r
69 \r
70     public static void clickEditArtifact(String artifactLabel) {\r
71         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.EDIT_ARTIFACT.getValue() + artifactLabel).click();\r
72     }\r
73 \r
74     public static void clickEditEnvArtifact(String artifactLabel) {\r
75         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.EDIT_PARAMETERS_OF_ARTIFACT.getValue() + artifactLabel).click();\r
76     }\r
77 \r
78     public static void hoverArtifact(String artifactLabel) {\r
79         GeneralUIUtils.hoverOnAreaByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_NAME.getValue() + artifactLabel);\r
80     }\r
81 \r
82     public static void clickDeleteArtifact(String artifactLabel) {\r
83         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Deleting %s Artefact ", artifactLabel));\r
84         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.DELETE_ARTIFACT.getValue() + artifactLabel).click();\r
85     }\r
86 \r
87     public static void clickDownloadEnvArtifact(String envFileNameToDownload) {\r
88         ExtentTestActions.log(Status.INFO, String.format("Downloading the updated  %s artifact for validate parameters with the response after the update...", envFileNameToDownload));\r
89         GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ArtifactPageEnum.DOWNLOAD_ARTIFACT_ENV.getValue() + envFileNameToDownload);\r
90         ExtentTestActions.log(Status.INFO, String.format("%s Envartifact was downloaded successfully!", envFileNameToDownload));\r
91     }\r
92 \r
93     public static void clickSaveEnvParameters() {\r
94         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPopup.SAVE.getValue()).click();\r
95         GeneralUIUtils.ultimateWait();\r
96     }\r
97 \r
98     public static void clickCloseEnvParameters() {\r
99         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPopup.CANCEL_BUTTON.getValue()).click();\r
100         GeneralUIUtils.ultimateWait();\r
101     }\r
102 \r
103     public static void clickOK() {\r
104         SetupCDTest.getExtendTest().log(Status.INFO, "Artifact Page, Clicking OK");\r
105         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.OK.getValue()).click();\r
106         GeneralUIUtils.getWebElementBy(By.className("flex-container"));\r
107         GeneralUIUtils.waitForAngular();\r
108     }\r
109 \r
110     public static String getArtifactDescription(String artifactLabel) throws Exception {\r
111         clickOnArtifactDescription(artifactLabel); // open artifact\r
112         WebElement artifactDescriptionElement = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.GET_DEPLOYMENT_ARTIFACT_DESCRIPTION.getValue());\r
113         String artifactDesc = artifactDescriptionElement.getAttribute("value");\r
114         closeArtifactDescription(artifactLabel); // close artifact\r
115         return artifactDesc;\r
116     }\r
117 \r
118     public static void closeArtifactDescription(String artifactLabel) {\r
119         GeneralUIUtils.clickOnElementByTestId("popover-x-button");\r
120     }\r
121 \r
122     public static WebElement clickOnArtifactDescription(String artifactLabel) throws Exception {\r
123         try {\r
124             WebElement artifact = GeneralUIUtils.getWebElementByTestID("descriptionIcon_" + artifactLabel);\r
125             artifact.click();\r
126             GeneralUIUtils.waitForLoader();\r
127             return artifact;\r
128         } catch (Exception e) {\r
129             throw new Exception("Artifact " + artifactLabel + "is not found");\r
130         }\r
131     }\r
132 \r
133     public static boolean checkElementsCountInTable(int expectedElementsCount) {\r
134         return GeneralPageElements.checkElementsCountInTable(expectedElementsCount + 1);\r
135     }\r
136 \r
137     public static String[] verifyArtifactsExistInTable(String filepath, String vnfFile) throws Exception {\r
138         String[] artifactNamesFromZipFile = FileHandling.getArtifactsFromZip(filepath, vnfFile);\r
139         return verifyArtifactsExistInTable(artifactNamesFromZipFile);\r
140     }\r
141 \r
142     public static String[] verifyArtifactsExistInTable(String[] artifactNamesFromZipFile) throws Exception {\r
143         if (artifactNamesFromZipFile != null) {\r
144             checkArtifactsDisplayed(artifactNamesFromZipFile);\r
145             checkEnvArtifactsDisplayed();\r
146         }\r
147 \r
148         return artifactNamesFromZipFile;\r
149     }\r
150 \r
151     public static void checkArtifactsDisplayed(String[] artifactsFromZipFile) throws Exception {\r
152         SetupCDTest.getExtendTest().log(Status.INFO, "Verifying the artifacts in the table");\r
153         List<String> artifactList = Lists.newArrayList(artifactsFromZipFile).stream().filter(p -> !p.contains(".env")).map(p -> getVisualArtifactName(p)).collect(Collectors.toList());\r
154         try {\r
155             List<WebElement> rows = GeneralUIUtils.getWebElementsListByContainsClassName("datatable-body-row");\r
156             for (WebElement r : rows) {\r
157                 String artifactDisplayed = r.getAttribute("textContent").trim();\r
158                 if (artifactList.contains(artifactDisplayed)) {\r
159                     artifactList.remove(artifactDisplayed);\r
160                 } else if (artifactDisplayed.toLowerCase().contains("license")) {\r
161                     artifactList.add(artifactDisplayed);\r
162                 }\r
163             }\r
164             checkLicenseArtifactsDisplayed(artifactList);\r
165         } catch (Exception e) {\r
166             throw new Exception("Table problem");\r
167         }\r
168 \r
169 \r
170         if (!artifactList.isEmpty()) {\r
171             throw new Exception(String.format("missing the following artifact(s) : %s", artifactList.toString()));\r
172         }\r
173     }\r
174 \r
175     public static void checkEnvArtifactsDisplayed() throws Exception {\r
176         List<WebElement> envRows;\r
177         List<WebElement> heatRows;\r
178         List<WebElement> heatNetRows;\r
179         List<WebElement> heatVolRows;\r
180         int envArtifactsSize = 0;\r
181 \r
182         SetupCDTest.getExtendTest().log(Status.INFO, "Verifying the HEAT_ENV artifacts in the table");\r
183 \r
184         try {\r
185             envRows = GeneralUIUtils.getElementsByCSS("div div[data-tests-id='HEAT_ENV']");\r
186 \r
187             heatRows = GeneralUIUtils.getElementsByCSS("div div[tooltip-content='HEAT']");\r
188             heatNetRows = GeneralUIUtils.getElementsByCSS("div div[tooltip-content='HEAT_NET']");\r
189             heatVolRows = GeneralUIUtils.getElementsByCSS("div div[tooltip-content='HEAT_VOL']");\r
190 \r
191             envArtifactsSize = heatRows.size() + heatNetRows.size() + heatVolRows.size();\r
192         } catch (Exception e) {\r
193             throw new Exception("Table problem");\r
194         }\r
195 \r
196         if (envArtifactsSize != envRows.size()) {\r
197             throw new Exception(String.format("some env artifacts are missing... there is %s instead of %s", envRows.size(), envArtifactsSize));\r
198         }\r
199 \r
200     }\r
201 \r
202     public static void checkLicenseArtifactsDisplayed(List<String> rowsFromTable) throws Exception {\r
203         SetupCDTest.getExtendTest().log(Status.INFO, "Verifying the license artifacts in the table");\r
204         String vfLicense = getPreparedLicense(ArtifactTypeEnum.VF_LICENSE.getType());\r
205         String[] split = vfLicense.split(" ");\r
206         vfLicense = vfLicense.replaceAll(split[0], split[0].toUpperCase());\r
207         if (rowsFromTable.contains(vfLicense)) {\r
208             rowsFromTable.remove(vfLicense);\r
209         }\r
210 \r
211         String vendorLicense = getPreparedLicense(ArtifactTypeEnum.VENDOR_LICENSE.getType());\r
212         if (rowsFromTable.contains(vendorLicense)) {\r
213             rowsFromTable.remove(vendorLicense);\r
214         }\r
215 \r
216     }\r
217 \r
218     public static String getPreparedLicense(String license) {\r
219         return WordUtils.capitalizeFully(license.replaceAll("_", " "));\r
220     }\r
221 \r
222 \r
223     private static String getVisualArtifactName(String artifactName) {\r
224         if (artifactName.contains(".")) {\r
225             return artifactName.substring(0, artifactName.lastIndexOf("."));\r
226         }\r
227         return artifactName;\r
228     }\r
229 \r
230     public static void updateDescription(String newDescription, ArtifactInfo artefact) throws Exception {\r
231         UploadArtifactPopup artifactPopup = new UploadArtifactPopup(true);\r
232         DeploymentArtifactPage.clickEditArtifact(artefact.getArtifactLabel());\r
233         artifactPopup.insertDescription(newDescription);\r
234         artifactPopup.clickDoneButton();\r
235     }\r
236 \r
237     public static List<String> getDeploymentArtifactsNamesWorkSpace() {\r
238         return GeneralUIUtils.getWebElementListText(GeneralUIUtils.getWebElementsListByContainTestID(DataTestIdEnum.ArtifactPageEnum.ARTIFACT_NAME.getValue()));\r
239     }\r
240 \r
241     //Get Artifact Type by Artifact Name.\r
242     public static String getArtifactType(String artifactName) {\r
243         return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.TYPE.getValue() + artifactName).getText();\r
244     }\r
245 \r
246     public static void searchBoxEnv(String parameterName) {\r
247         GeneralUIUtils.getWebElementByContainsClassName("w-sdc-env-search-input").sendKeys(parameterName);\r
248     }\r
249 \r
250     public static void clearSearchBoxEnv() {\r
251         GeneralUIUtils.getWebElementByContainsClassName("w-sdc-env-search-input").clear();\r
252     }\r
253 \r
254     public static void editHeatParamValue(String paramName, String value) throws Exception {\r
255         SetupCDTest.getExtendTest().log(Status.INFO, "Searching for " + paramName + " parameter on Heat Params modal screen");\r
256         WebElement valueTextbox = GeneralUIUtils.getWebElementByTestID(paramName);\r
257 \r
258         clickOnHeatParam(paramName);\r
259         valueTextbox.clear();\r
260         SetupCDTest.getExtendTest().log(Status.INFO, "Editing " + paramName + " value on Heat Params modal screen");\r
261         valueTextbox.sendKeys(value);\r
262         GeneralUIUtils.ultimateWait();\r
263 \r
264     }\r
265 \r
266     public static void clickOnDeleteHeatParamValue(String paramName) throws Exception {\r
267         SetupCDTest.getExtendTest().log(Status.INFO, "Searching for " + paramName + " parameter on Properties screen");\r
268         String value = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.EnvParameterView.ENV_CURRENT_VALUE.getValue() + paramName).getAttribute("value");\r
269         if (value != null) {\r
270             GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ArtifactPageEnum.DELETE_PARAMETER_OF_ARTIFACT.getValue() + paramName);\r
271             GeneralUIUtils.ultimateWait();\r
272             SetupCDTest.getExtendTest().log(Status.INFO, "Value of " + paramName + " is deleted");\r
273         }\r
274         SetupCDTest.getExtendTest().log(Status.INFO, "Value of " + paramName + " is empty and cannot be deleted");\r
275     }\r
276 \r
277     public static void clickOnHeatParam(String paramName) throws Exception {\r
278 \r
279         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on the %s component in Properties", paramName));\r
280         GeneralUIUtils.clickOnElementByTestId(paramName);\r
281         GeneralUIUtils.ultimateWait();\r
282         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.LIFECYCLE_STATE.getValue());\r
283     }\r
284 \r
285 }\r