[SDC-29] rebase continue work to align source
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / pages / DeploymentArtifactPage.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.pages;
22
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.stream.Collectors;
26
27 import org.apache.commons.lang.WordUtils;
28 import org.openecomp.sdc.ci.tests.datatypes.ArtifactInfo;
29 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
30 import org.openecomp.sdc.ci.tests.datatypes.enums.ArtifactTypeEnum;
31 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
32 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
33 import org.openecomp.sdc.ci.tests.utilities.FileHandling;
34 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
35 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
36 import org.openqa.selenium.By;
37 import org.openqa.selenium.WebElement;
38 import org.testng.collections.Lists;
39
40 import com.aventstack.extentreports.Status;
41
42 public class DeploymentArtifactPage extends GeneralPageElements {
43
44         public DeploymentArtifactPage() {
45                 super();
46         }
47
48         public static ResourceLeftMenu getLeftPanel() {
49                 return new ResourceLeftMenu();
50         }
51
52         public static UploadArtifactPopup artifactPopup() {
53                 return new UploadArtifactPopup();
54         }
55
56         protected static void addNewArtifact(ArtifactGroupTypeEnum artifactGroupType) {
57                 switch (artifactGroupType) {
58                         case DEPLOYMENT:
59                         GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.ADD_DEPLOYMENT_ARTIFACT.getValue()).click();
60                                 break;
61                         case INFORMATIONAL:
62                         GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.ADD_INFORMATIONAL_ARTIFACT.getValue()).click();
63                                 break;
64                         default:
65                                 break;
66                         }
67         }
68
69         public static void clickAddNewArtifact() {
70                 addNewArtifact(ArtifactGroupTypeEnum.DEPLOYMENT);
71         }
72
73         public static void clickAddAnotherArtifact() {
74                 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.ADD_ANOTHER_ARTIFACT.getValue()).click();
75         }
76
77         public static void clickEditArtifact(String artifactLabel) {
78                 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.EDIT_ARTIFACT.getValue() + artifactLabel).click();
79         }
80         
81         public static void clickEditEnvArtifact(String artifactLabel) {
82                 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.EDIT_PARAMETERS_OF_ARTIFACT.getValue() + artifactLabel).click();
83         }
84
85         public static void clickDeleteArtifact(String artifactLabel) {
86                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Deleting %s Artefact ",artifactLabel));
87                 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.DELETE_ARTIFACT.getValue() + artifactLabel).click();
88         }
89
90         public static WebElement clickDownloadArtifact(String artifactLabel) {
91                 WebElement downloadButton = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.DOWNLOAD_ARTIFACT.getValue() + artifactLabel);
92
93                 return downloadButton;
94         }
95         
96         public static void clickDownloadEnvArtifact(String envFileNameToDownload) {
97                 ExtentTestActions.log(Status.INFO, String.format("Downloading the updated  %s artifact for validate parameters with the response after the update...", envFileNameToDownload));
98                 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ArtifactPageEnum.DOWNLOAD_ARTIFACT_ENV.getValue() + envFileNameToDownload);
99                 ExtentTestActions.log(Status.INFO, String.format("%s Envartifact was downloaded successfully!", envFileNameToDownload));
100         }
101         
102         public static  void clickSaveEnvParameters() {
103                  GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPopup.SAVE.getValue()).click();
104                  GeneralUIUtils.ultimateWait();
105         }
106         
107         public static WebElement getAddOtherArtifactButton(){
108                 return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.ADD_ANOTHER_ARTIFACT.getValue());
109         }
110         
111         public static void clickOK(){
112                 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.OK.getValue()).click();
113                 GeneralUIUtils.getWebElementBy(By.className("flex-container"));
114                 GeneralUIUtils.waitForAngular();
115         }
116
117         public static String getArtifactDescription(String artifactLabel) throws Exception {
118                 clickOnArtifactDescription(artifactLabel); // open artifact
119                 WebElement artifactDescriptionElement = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.GET_DEPLOYMENT_ARTIFACT_DESCRIPTION.getValue());
120                 String artifactDesc = artifactDescriptionElement.getAttribute("value");
121                 closeArtifactDescription(artifactLabel); // close artifact
122                 return artifactDesc;
123         }
124
125         public static void closeArtifactDescription(String artifactLabel) {
126                 GeneralUIUtils.clickOnElementByTestId("popover-x-button");
127         }
128
129         public static WebElement clickOnArtifactDescription(String artifactLabel) throws Exception {
130                 try{
131                         WebElement artifact = GeneralUIUtils.getWebElementByTestID("descriptionIcon_" + artifactLabel);
132                         artifact.click();
133                         GeneralUIUtils.waitForLoader();
134                         return artifact;
135                 }
136                 catch(Exception e){
137                         throw new Exception("Artifact " + artifactLabel + "is not found");
138                 }
139         }
140         
141         public static boolean checkElementsCountInTable(int expectedElementsCount) {
142                 return GeneralPageElements.checkElementsCountInTable(expectedElementsCount + 1);
143         }
144         
145         public static String[] verifyArtifactsExistInTable(String filepath, String vnfFile) throws Exception{
146                 String[] artifactNamesFromZipFile = FileHandling.getArtifactsFromZip(filepath, vnfFile);
147                 return verifyArtifactsExistInTable(artifactNamesFromZipFile);
148         }
149         
150         public static String[] verifyArtifactsExistInTable(String[] artifactNamesFromZipFile) throws Exception{
151                 if (artifactNamesFromZipFile != null){
152                         checkArtifactsDisplayed(artifactNamesFromZipFile);
153                         checkEnvArtifactsDisplayed();
154                 }
155                 
156                 return artifactNamesFromZipFile;
157         }
158
159         public static void checkArtifactsDisplayed(String[] artifactsFromZipFile) throws Exception {
160                 SetupCDTest.getExtendTest().log(Status.INFO, "Verifying the artifacts in the table");
161                 List<String> artifactList = Lists.newArrayList(artifactsFromZipFile).stream().filter(p -> !p.contains(".env")).map(p -> getVisualArtifactName(p)).collect(Collectors.toList());
162                 try{
163 //                      List<WebElement> rows = GeneralUIUtils.getElementsByCSS("div div[data-tests-id^='artifact-item'] span.ng-binding:nth-of-type(2)");
164                         List<WebElement> rows = GeneralUIUtils.getElementsByCSS("div div[data-tests-id^='artifact-item'] span[data-tests-id^='artifactDisplayName']");
165                         for (WebElement r : rows){
166                                 String artifactDisplayed = r.getAttribute("textContent").trim();
167                                 if (artifactList.contains(artifactDisplayed)){
168                                         artifactList.remove(artifactDisplayed);
169                                 }
170                                 else if (artifactDisplayed.toLowerCase().contains("license")){
171                                         artifactList.add(artifactDisplayed);
172                                 }
173                         }
174                         checkLicenseArtifactsDisplayed(artifactList);
175                 }
176                 catch(Exception e){
177                         throw new Exception("Table problem");
178                 }
179                 
180                 
181                 if (!artifactList.isEmpty()){
182                         throw new Exception(String.format("missing the following artifact(s) : %s", artifactList.toString()));
183                 }
184         }
185
186         public static void checkEnvArtifactsDisplayed() throws Exception {
187                 List<WebElement> envRows;
188                 List<WebElement> heatRows;
189                 List<WebElement> heatNetRows;
190                 List<WebElement> heatVolRows;
191                 int envArtifactsSize = 0;
192                 
193                 SetupCDTest.getExtendTest().log(Status.INFO, "Verifying the HEAT_ENV artifacts in the table");
194                 
195                 try{
196                         envRows = GeneralUIUtils.getElementsByCSS("div div[data-tests-id='HEAT_ENV']");
197                         
198                         heatRows = GeneralUIUtils.getElementsByCSS("div div[tooltip-content='HEAT']");
199                         heatNetRows = GeneralUIUtils.getElementsByCSS("div div[tooltip-content='HEAT_NET']");
200                         heatVolRows = GeneralUIUtils.getElementsByCSS("div div[tooltip-content='HEAT_VOL']");
201                         
202                         envArtifactsSize = heatRows.size() + heatNetRows.size() + heatVolRows.size();
203                 }
204                 catch(Exception e){
205                         throw new Exception("Table problem");
206                 }
207                 
208                 if (envArtifactsSize !=envRows.size()){
209                         throw new Exception(String.format("some env artifacts are missing... there is %s instead of %s", envRows.size(), envArtifactsSize));    
210                 }
211                 
212         }
213
214         public static void checkLicenseArtifactsDisplayed(List<String> rowsFromTable) throws Exception {
215                 SetupCDTest.getExtendTest().log(Status.INFO, "Verifying the license artifacts in the table");
216                 String vfLicense =   getPreparedLicense(ArtifactTypeEnum.VF_LICENSE.getType());
217                 String[] split = vfLicense.split(" ");
218                 vfLicense = vfLicense.replaceAll(split[0], split[0].toUpperCase());
219                 if (rowsFromTable.contains(vfLicense)){
220                         rowsFromTable.remove(vfLicense);
221                 }
222                 
223                 String vendorLicense = getPreparedLicense(ArtifactTypeEnum.VENDOR_LICENSE.getType());
224                 if (rowsFromTable.contains(vendorLicense)){ 
225                         rowsFromTable.remove(vendorLicense);
226                 }
227
228         }
229
230         public static String getPreparedLicense(String license) {
231                 return WordUtils.capitalizeFully(license.replaceAll("_", " "));
232         }
233         
234
235         private static String getVisualArtifactName(String artifactName) {
236                 if (artifactName.contains(".")){
237                         return artifactName.substring(0, artifactName.lastIndexOf("."));
238                 }
239                 return artifactName;
240         }
241         
242         public static void updateDescription(String newDescription, ArtifactInfo artefact) throws Exception{
243                 UploadArtifactPopup artifactPopup = new UploadArtifactPopup(true);
244                 DeploymentArtifactPage.clickEditArtifact(artefact.getArtifactLabel());
245                 artifactPopup.insertDescription(newDescription);
246                 artifactPopup.clickDoneButton();
247         }
248         
249         public static List<String> getDeploymentArtifactsNamesWorkSpace() {
250                 return GeneralUIUtils.getWebElementListText(GeneralUIUtils.getWebElementsListByContainTestID(DataTestIdEnum.ArtifactPageEnum.ARTIFACT_NAME.getValue()));
251         }
252         
253         //Get Artifact Type by Artifact Name.
254         public static String getArtifactType(String artifactName){
255                 return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.TYPE.getValue()+artifactName).getText();
256         }
257         
258         public static List<String> getHeatParametersInUI(String dataTestId){
259                 List<WebElement>elements;
260                 List<String>Names=new ArrayList<>();
261                 elements=GeneralUIUtils.getWebElementsListByContainTestID(dataTestId);
262                                 for (WebElement webElement : elements) {
263                                         String attributevalue=webElement.getAttribute("data-tests-id");
264                                         Names.add(attributevalue.replace("heatParameterName_", ""));
265                                 }
266                 return Names;
267         }
268         
269         public static void searchBoxEnv(String parameterName) {
270                 GeneralUIUtils.getWebElementByContainsClassName("w-sdc-env-search-input").sendKeys(parameterName);
271         }
272         
273         public static void clearSearchBoxEnv() {
274                 GeneralUIUtils.getWebElementByContainsClassName("w-sdc-env-search-input").clear();
275         }
276
277 }