[SDC-29] rebase continue work to align source
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / utilities / ArtifactUIUtils.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.utilities;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertTrue;
25
26 import java.awt.AWTException;
27 import java.awt.Robot;
28 import java.awt.Toolkit;
29 import java.awt.datatransfer.StringSelection;
30 import java.awt.event.KeyEvent;
31 import java.io.File;
32 import java.io.IOException;
33 import java.util.HashMap;
34 import java.util.List;
35 import java.util.Map;
36
37 import org.json.simple.JSONObject;
38 import org.json.simple.JSONValue;
39 import org.openecomp.sdc.be.datatypes.elements.HeatParameterDataDefinition;
40 import org.openecomp.sdc.be.model.User;
41 import org.openecomp.sdc.ci.tests.datatypes.ArtifactInfo;
42 import org.openecomp.sdc.ci.tests.datatypes.ArtifactReqDetails;
43 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
44 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.InformationalArtifactsPlaceholders;
45 import org.openecomp.sdc.ci.tests.datatypes.HeatWithParametersDefinition;
46 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
47 import org.openecomp.sdc.ci.tests.datatypes.enums.ArtifactTypeEnum;
48 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
49 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
50 import org.openecomp.sdc.ci.tests.pages.CompositionPage;
51 import org.openecomp.sdc.ci.tests.pages.InformationalArtifactPage;
52 import org.openecomp.sdc.ci.tests.pages.UploadArtifactPopup;
53 import org.openqa.selenium.By;
54 import org.openqa.selenium.WebElement;
55 import org.testng.Assert;
56
57 import com.aventstack.extentreports.Status;
58
59 public final class ArtifactUIUtils {
60
61         private static final String PARAMETERS = "parameters";
62
63         private ArtifactUIUtils() {
64         }
65
66         public static void fillAndAddNewArtifactParameters(ArtifactInfo artifactInfo) throws Exception {
67                 UploadArtifactPopup artifactPopup = new UploadArtifactPopup();
68                 fillAndAddNewArtifactParameters(artifactInfo, artifactPopup);
69 //              artifactPopup.defineArtifactLabel(artifactInfo.getArtifactLabel());
70 //              artifactPopup.selectArtifactType(artifactInfo.getArtifactType());
71 //              artifactPopup.insertDescription(artifactInfo.getDescription());
72 //              artifactPopup.loadFile(artifactInfo.getFilepath(), artifactInfo.getFilename());
73 //              artifactPopup.clickAddButton();
74         }
75         
76         public static void fillAndAddNewArtifactParameters(ArtifactInfo artifactInfo, UploadArtifactPopup artifactPopup) throws Exception {
77                 artifactPopup.defineArtifactLabel(artifactInfo.getArtifactLabel());
78                 artifactPopup.selectArtifactType(artifactInfo.getArtifactType());
79                 artifactPopup.insertDescription(artifactInfo.getDescription());
80                 artifactPopup.loadFile(artifactInfo.getFilepath(), artifactInfo.getFilename());
81                 artifactPopup.clickDoneButton();
82                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("A new artifact of type %s was added", artifactInfo.getArtifactType()));  
83         }
84
85         public static void fillAndAddNewEnvArtifactParameters(ArtifactInfo artifactInfo, UploadArtifactPopup artifactPopup) throws Exception {
86                 artifactPopup.insertDescription(artifactInfo.getDescription());
87                 artifactPopup.loadFile(artifactInfo.getFilepath(), artifactInfo.getFilename());
88                 artifactPopup.clickDoneButton();
89                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("ENV parameters %s artifact updated ", artifactInfo.getArtifactType()));  
90         }
91         
92         public static void fillPlaceHolderInformationalArtifact(DataTestIdEnum.InformationalArtifactsPlaceholders artifactLabel,String filepath, String filename, String description) throws Exception {
93                 GeneralUIUtils.clickOnElementByTestId(artifactLabel.getValue());
94                 InformationalArtifactPage.artifactPopup().loadFile(filepath, filename);
95                 InformationalArtifactPage.artifactPopup().insertDescription(description);
96                 InformationalArtifactPage.artifactPopup().clickDoneButton();
97         }
98         
99         public static void fillPlaceHolderInformationalArtifact(DataTestIdEnum.InformationalArtifactsService artifactLabel,
100                         String filepath, String filename, String description) throws Exception {
101                 GeneralUIUtils.clickOnElementByTestId(artifactLabel.getValue());
102                 UploadArtifactPopup artifactPopup = new UploadArtifactPopup(true);
103                 artifactPopup.loadFile(filepath, filename);
104                 artifactPopup.insertDescription(description);
105                 artifactPopup.clickDoneButton();
106         }
107         
108         public static void fillPlaceHolderAPIArtifact(DataTestIdEnum.APIArtifactsService artifactLabel,
109                         String filepath, String filename, String description, String url) throws Exception {
110                 GeneralUIUtils.clickOnElementByTestId(artifactLabel.getValue());
111                 UploadArtifactPopup artifactPopup = new UploadArtifactPopup(true);
112                 artifactPopup.loadFile(filepath, filename);
113                 artifactPopup.insertURL(url);
114                 artifactPopup.insertDescription(description);
115                 artifactPopup.clickDoneButton();
116         }
117
118         public static RestResponse deploymentArtifactResourceInUI(ResourceReqDetails resource, User user,
119                         ArtifactReqDetails artifact, String file) throws Exception {
120                 Thread.sleep(1000);
121
122                 List<WebElement> listFormInput = GeneralUIUtils.getDriver()
123                                 .findElements(By.className("i-sdc-designer-sidebar-tab"));
124                 WebElement addArtifactElement = listFormInput.get(2);
125                 addArtifactElement.click();
126
127                 WebElement addArtifact = GeneralUIUtils.getDriver()
128                                 .findElement(By.className("i-sdc-designer-sidebar-section-content-item-artifact-details-name"));
129                 addArtifact.click();
130
131                 Thread.sleep(1000);
132                 WebElement descriptionProperty = GeneralUIUtils.getDriver().findElement(By.className("i-sdc-form-textarea"));
133                 descriptionProperty.clear();
134                 descriptionProperty.sendKeys(artifact.getDescription());
135
136                 WebElement uploadFile = GeneralUIUtils.getDriver().findElement(By.className("i-sdc-form-label-upload"));
137                 uploadFile.click();
138
139                 StringSelection sel = new StringSelection(file);
140                 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(sel, null);
141                 // System.out.println("selection" + sel);
142                 Thread.sleep(1000);
143
144                 Robot robot = new Robot();
145                 Thread.sleep(1000);
146
147                 Thread.sleep(2000);
148
149                 robot.keyPress(KeyEvent.VK_ENTER);
150
151                 // Release Enter
152                 robot.keyRelease(KeyEvent.VK_ENTER);
153
154                 // Press CTRL+V
155                 robot.keyPress(KeyEvent.VK_CONTROL);
156                 robot.keyPress(KeyEvent.VK_V);
157
158                 // Release CTRL+V
159                 robot.keyRelease(KeyEvent.VK_CONTROL);
160                 robot.keyRelease(KeyEvent.VK_V);
161                 Thread.sleep(1000);
162
163                 // Press Enter
164                 robot.keyPress(KeyEvent.VK_ENTER);
165                 robot.keyRelease(KeyEvent.VK_ENTER);
166                 Thread.sleep(3000);
167
168                 WebElement clickDone = GeneralUIUtils.getDriver().findElement(By.className("w-sdc-form-action"));
169                 clickDone.click();
170
171                 Thread.sleep(3500);
172
173                 GeneralUIUtils.getDriver().findElement(By.cssSelector("button[data-ng-click^=save]")).click();
174
175                 RestResponse getResource = RestCDUtils.getResource(resource, user);
176                 assertEquals("Did not succeed to get resource after create", 200, getResource.getErrorCode().intValue());
177                 return getResource;
178         }
179
180         public static void addInformationArtifact(ArtifactReqDetails artifact, String filePath,
181                         final InformationalArtifactsPlaceholders dataTestEnum) throws Exception {
182                 GeneralUIUtils.waitForLoader();
183                 GeneralUIUtils.sleep(2000);
184                 GeneralUIUtils.getWebElementByTestID(dataTestEnum.getValue()).click();
185
186 //              final WebElement browseWebElement = GeneralUIUtils.retryMethodOnException(
187 //                              () -> GeneralUIUtils.getWebElementByDataTestId(DataTestIdEnum.ModalItems.BROWSE_BUTTON.getValue()));
188                 
189                 WebElement browseWebElement = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ModalItems.BROWSE_BUTTON.getValue());
190                 browseWebElement.sendKeys(filePath);
191
192                 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ModalItems.DESCRIPTION.getValue())
193                                 .sendKeys(artifact.getDescription());
194                 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ModalItems.ADD.getValue()).click();
195
196         }
197
198         private static void addFileToWindowBrowse(String file) throws InterruptedException, AWTException {
199                 StringSelection sel = new StringSelection(file);
200                 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(sel, null);
201                 // System.out.println("selection" + sel);
202                 Thread.sleep(1000);
203
204                 Robot robot = new Robot();
205
206                 robot.keyPress(KeyEvent.VK_ENTER);
207
208                 // Release Enter
209                 robot.keyRelease(KeyEvent.VK_ENTER);
210
211                 // Press CTRL+V
212                 robot.keyPress(KeyEvent.VK_CONTROL);
213                 robot.keyPress(KeyEvent.VK_V);
214
215                 // Release CTRL+V
216                 robot.keyRelease(KeyEvent.VK_CONTROL);
217                 robot.keyRelease(KeyEvent.VK_V);
218                 Thread.sleep(1000);
219
220                 // Press Enter
221                 robot.keyPress(KeyEvent.VK_ENTER);
222                 robot.keyRelease(KeyEvent.VK_ENTER);
223                 Thread.sleep(3000);
224         }
225
226         static WebElement ArtifactLabel;
227
228         public static Map<String, String> addInformationalArtifact(String artifactLabel) throws Exception {
229                 String type = GeneralUIUtils.getSelectList(null, "artifacttype").getFirstSelectedOption().getText();
230                 Map<String, String> artifactValues = new HashMap<String, String>();
231                 String labelName = GeneralUIUtils.getSelectList(artifactLabel, "selectArtifact").getFirstSelectedOption()
232                                 .getText();
233                 ArtifactLabel = GeneralUIUtils.getDriver().findElement(By.name("artifactLabel"));
234                 if (ArtifactLabel.getAttribute("value").equals("")) {
235                         labelName = "New-Test-Artifact";
236                         ArtifactLabel.sendKeys(labelName);
237                         type = GeneralUIUtils.getSelectList("HEAT", "artifacttype").getFirstSelectedOption().getText();
238                 }
239                 String description = "This is Description";
240                 String fileName = "Heat-File.yaml";
241                 GeneralUIUtils.setWebElementByTestId("description", "description");
242                 ResourceUIUtils.importFileWithSendKeyBrowse(ImportAssetUIUtils.FILE_PATH, fileName);
243                 GeneralUIUtils.getWebElementByTestID("Add").click();
244                 GeneralUIUtils.getWebElementByTestID(labelName);
245
246                 artifactValues.put("type", type);
247                 artifactValues.put("description", description);
248                 artifactValues.put("name", labelName);
249                 artifactValues.put("fileName", fileName);
250                 return artifactValues;
251         }
252
253         public static Map<String, String> addDeploymentArtifact(String artifactLabel, String artifactType, String fileName)
254                         throws Exception {
255                 String type = null;
256                 String labelName;
257                 Map<String, String> artifactValues = new HashMap<String, String>();
258                 try {
259                         labelName = GeneralUIUtils.getSelectList(artifactLabel, "selectArtifact").getOptions().get(1).getText();
260                         GeneralUIUtils.getSelectList(artifactLabel, "selectArtifact").selectByVisibleText(labelName);
261                 } catch (Exception e) {
262                         labelName = GeneralUIUtils.getWebElementByClassName(artifactLabel).getText();
263                 }
264                 ArtifactLabel = GeneralUIUtils.getDriver().findElement(By.name("artifactLabel"));
265                 if (ArtifactLabel.getText().equals("")) {
266                         labelName = "New-Test-Artifact";
267                         ArtifactLabel.sendKeys(labelName);
268                         type = GeneralUIUtils.getSelectList(artifactType, "artifacttype").getFirstSelectedOption().getText();
269                 }
270                 String description = "This is Description";
271                 GeneralUIUtils.setWebElementByTestId("description", "description" );
272                 ResourceUIUtils.importFileWithSendKeyBrowse(ImportAssetUIUtils.FILE_PATH, fileName);
273                 try {
274                         GeneralUIUtils.getWebElementByTestID("Add").click();
275                 } catch (Exception e) {
276                         GeneralUIUtils.getWebElementByClassName("w-sdc-form-action add-property").click();
277                 }
278
279                 artifactValues.put("type", artifactType);
280                 artifactValues.put("description", description);
281                 artifactValues.put("name", labelName);
282                 artifactValues.put("fileName", fileName);
283                 return artifactValues;
284         }
285         
286
287         public static Map<String, String> addDeploymentArtifactFromCanvas(String artifactLabel) throws Exception {
288                 String type = null;
289                 Map<String, String> artifactValues = new HashMap<String, String>();
290                 String labelName = GeneralUIUtils.getSelectList(artifactLabel, "selectArtifact").getFirstSelectedOption()
291                                 .getText();
292                 ArtifactLabel = GeneralUIUtils.getDriver().findElement(By.name("artifactLabel"));
293                 if (ArtifactLabel.getText().equals("")) {
294                         labelName = "New-Test-Artifact";
295                         ArtifactLabel.sendKeys(labelName);
296                         type = GeneralUIUtils.getSelectList("OTHER", "artifacttype").getFirstSelectedOption().getText();
297                 }
298                 String description = "This is Description";
299                 String filePath = "C:\\Git_work\\ASDC\\d2-sdnc\\ui-ci\\src\\main\\resources\\Files\\";
300                 String fileName = "Heat-File.yaml";
301                 GeneralUIUtils.setWebElementByTestId("description", "description");
302                 ResourceUIUtils.importFileWithSendKeyBrowse(filePath, fileName);
303                 GeneralUIUtils.getWebElementByTestID("Add").click();
304                 artifactValues.put("type", type);
305                 artifactValues.put("description", description);
306                 artifactValues.put("name", labelName);
307                 artifactValues.put("fileName", fileName);
308                 return artifactValues;
309         }
310
311         public static Map<String, String> valideArtifact(Map<String, String> artifactValues, Boolean condition)
312                         throws Exception {
313                 if (condition) {
314                         GeneralUIUtils.getWebElementByClassName("table-edit-btn").click();
315                 } else {
316                         System.out.println(artifactValues.get("name"));
317                         GeneralUIUtils.getWebElementByTestID("edit_" + artifactValues.get("name")).click();
318                 }
319                 Thread.sleep(1000);
320                 String labelname = GeneralUIUtils.getWebElementByClassName("artifactLabel").getAttribute("value");
321                 String filename = GeneralUIUtils.getWebElementByTestID("filename").getText();
322                 String description = GeneralUIUtils.getWebElementByTestID("description").getAttribute("value");
323                 String type = GeneralUIUtils.getSelectList(null, "artifacttype").getFirstSelectedOption().getText();
324                 labelname.compareToIgnoreCase(artifactValues.get("name").replaceAll("-", ""));
325                 assertEquals(filename, artifactValues.get("fileName").replaceAll(" ", "-"));
326                 assertEquals(type, artifactValues.get("type"));
327                 assertEquals(description, artifactValues.get("description"));
328                 GeneralUIUtils.getWebElementByTestID("Update").click();
329                 return artifactValues;
330         }
331
332         public static void valideArtifactFromCanvas(Map<String, String> artifactValues) throws Exception {
333                 GeneralUIUtils.getWebElementByTestID("artifactDisplayName-" + artifactValues.get("name")).click();
334                 Thread.sleep(1000);
335                 String labelname = GeneralUIUtils.getWebElementByClassName("artifactLabel").getAttribute("value");
336                 String filename = GeneralUIUtils.getWebElementByTestID("filename").getText();
337                 String description = GeneralUIUtils.getWebElementByTestID("description").getAttribute("value");
338                 String type = GeneralUIUtils.getSelectList(null, "artifacttype").getFirstSelectedOption().getText();
339                 labelname.compareToIgnoreCase(artifactValues.get("name").replaceAll("-", ""));
340                 assertEquals(filename, artifactValues.get("fileName"));
341                 assertEquals(type, artifactValues.get("type"));
342                 assertEquals(description, artifactValues.get("description"));
343         }
344
345         public static Map<String, Map<String, Object>> getArtifactsListFromResponse(String jsonResponse,
346                         String fieldOfArtifactList) {
347                 JSONObject object = (JSONObject) JSONValue.parse(jsonResponse);
348                 Map<String, Map<String, Object>> map = (Map<String, Map<String, Object>>) object.get(fieldOfArtifactList);
349                 return map;
350         }
351         
352         public static void validateArtifactNameVersionType(String artifactLabel, String artifactVersion, String artifactType) {
353 //              Assert.assertEquals(GeneralUIUtils.getDriver().findElement(By.xpath("//*[@data-tests-id='" + DataTestIdEnum.ArtifactPageEnum.ARTIFACT_NAME.getValue() + artifactLabel + "']")).getAttribute("textContent").trim(), artifactLabel);
354                 if(!GeneralUIUtils.getDriver().findElement(By.xpath("//*[@data-tests-id='" + DataTestIdEnum.ArtifactPageEnum.ARTIFACT_NAME.getValue() + artifactLabel + "']")).getAttribute("textContent").trim().equals(artifactLabel)) {
355                         SetupCDTest.getExtendTest().log(Status.WARNING, "Artifact label not equal - this warnning represent defect.");  
356                 }
357                 if(artifactVersion != null) {
358 //                      Assert.assertEquals(GeneralUIUtils.getDriver().findElement(By.xpath("//*[@data-tests-id='" + DataTestIdEnum.ArtifactPageEnum.VERSION.getValue() + artifactLabel + "']")).getAttribute("textContent").trim(), artifactVersion, "Artifact version not equal.");
359                         if(!GeneralUIUtils.getDriver().findElement(By.xpath("//*[@data-tests-id='" + DataTestIdEnum.ArtifactPageEnum.VERSION.getValue() + artifactLabel + "']")).getAttribute("textContent").trim().equals(artifactVersion)) {
360                                 SetupCDTest.getExtendTest().log(Status.WARNING, "Artifact version not equal - this warnning represent defect.");        
361                         }
362                 }
363                 if(artifactType != null) {
364 //                      Assert.assertEquals(GeneralUIUtils.getDriver().findElement(By.xpath("//*[@data-tests-id='" + DataTestIdEnum.ArtifactPageEnum.TYPE.getValue() + artifactLabel + "']")).getAttribute("textContent").trim(), artifactType, "Artifact type not equal.");
365                         if(!GeneralUIUtils.getDriver().findElement(By.xpath("//*[@data-tests-id='" + DataTestIdEnum.ArtifactPageEnum.TYPE.getValue() + artifactLabel + "']")).getAttribute("textContent").trim().equals(artifactType)) {
366                                 SetupCDTest.getExtendTest().log(Status.WARNING, "Artifact type not equal - this warnning represent defect.");   
367                         }
368                 }
369         }
370         
371         public static void validateArtifactVersionByTypeAndLabel(String artifactLabel, String expectedArtifactVersion, ArtifactTypeEnum artifactType) {
372                 if(expectedArtifactVersion != null) {
373                         String xPath;
374                         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Going to validate artifact version ..."));
375                         if(artifactType.getType().equals(ArtifactTypeEnum.HEAT_ENV.getType())){
376                                 xPath = "//*[@data-tests-id='" + DataTestIdEnum.ArtifactPageEnum.VERSION_ENV.getValue() + artifactLabel + "']"; 
377                         }else{
378                                 xPath = "//*[@data-tests-id='" + DataTestIdEnum.ArtifactPageEnum.VERSION.getValue() + artifactLabel + "']";
379                         }
380                         String actualartifactVersion = GeneralUIUtils.getDriver().findElement(By.xpath(xPath)).getAttribute("textContent").trim();
381                         Assert.assertEquals(actualartifactVersion, expectedArtifactVersion, "Artifact type " + artifactType.getType() + " expected version is " + expectedArtifactVersion + " not equal to " + actualartifactVersion);
382                 }
383         }
384         
385         public static void validateExistArtifactOnDeploymentInformationPage(String expectedArtifactLabel, String artifactUUID, String artifactVersion, String artifactType, boolean isDownloadable, boolean isEditable, boolean isDeletable, boolean isArtifactParametersEditable) {
386                 
387                 String dataTestId = DataTestIdEnum.ArtifactPageEnum.ARTIFACT_NAME.getValue() + expectedArtifactLabel;
388                 
389                 List<WebElement> artifactElements = GeneralUIUtils.getWebElementsListByContainTestID(dataTestId);
390                 Assert.assertEquals(artifactElements.size(), 1, "There are more then one artifact named " + expectedArtifactLabel);
391                 
392                 WebElement artifact = artifactElements.get(0);
393                 String actualArtifactLabel = GeneralUIUtils.getTextContentAttributeValue(artifact).trim();
394                 Assert.assertEquals(actualArtifactLabel, expectedArtifactLabel);
395                         
396                 if(artifactUUID != null) {
397                         WebElement uuid = GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.UUID.getValue() + expectedArtifactLabel);
398                         Assert.assertEquals(GeneralUIUtils.getTextContentAttributeValue(uuid).trim(), artifactUUID, "Artifact uuid not equal.");
399                 }
400                 if(artifactVersion != null) {
401                         WebElement version = GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.VERSION.getValue() + expectedArtifactLabel);
402                         Assert.assertEquals(GeneralUIUtils.getTextContentAttributeValue(version).trim(), artifactVersion, "Artifact version not equal.");
403                 }
404                 if(artifactType != null) {
405                         WebElement type = GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.TYPE.getValue() + expectedArtifactLabel);
406                         Assert.assertEquals(GeneralUIUtils.getTextContentAttributeValue(type).trim(), artifactType, "Artifact type not equal.");
407                 }
408                 if(isArtifactParametersEditable) {
409                         Assert.assertNotNull(GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.EDIT_PARAMETERS_OF_ARTIFACT.getValue() + expectedArtifactLabel), "Expect that parameters edit button enabled.");
410                 } else if(isArtifactParametersEditable==false) {
411                         Assert.assertNull(GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.EDIT_PARAMETERS_OF_ARTIFACT.getValue() + expectedArtifactLabel), "Expect that parameters edit button disabled.");
412                 }
413                 if(isDownloadable) {
414                         Assert.assertNotNull(GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.DOWNLOAD_ARTIFACT.getValue() + expectedArtifactLabel), "Expect that download button enabled.");
415                 } else if(isDownloadable==false) {
416                         Assert.assertNull(GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.DOWNLOAD_ARTIFACT.getValue() + expectedArtifactLabel), "Expect that download button disabled.");
417                 }
418                 if(isEditable) {
419                         Assert.assertNotNull(GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.EDIT_ARTIFACT.getValue() + expectedArtifactLabel), "Expect that edit button enabled.");
420                 } else if(isEditable==false) {
421                         Assert.assertNull(GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.EDIT_ARTIFACT.getValue() + expectedArtifactLabel), "Expect that edit button disabled.");
422                 }
423                 if(isDeletable) {
424                         Assert.assertNotNull(GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.DELETE_ARTIFACT.getValue() + expectedArtifactLabel), "Expect that delete button enabled.");
425                 } else if(isDeletable==false) {
426                         Assert.assertNull(GeneralUIUtils.getInputElement(DataTestIdEnum.ArtifactPageEnum.DELETE_ARTIFACT.getValue() + expectedArtifactLabel), "Expect that delete button disabled.");
427                 }
428         }
429         
430         public static void validateNotExistArtifactOnDeploymentInformationPage(String artifactLabel) {
431                 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.ArtifactPageEnum.ARTIFACT_NAME.getValue() + artifactLabel), false);
432         }
433         
434         public static void validateExistArtifactOnCompositionRightMenuDeploymentInformationPage(String fileName, String artifactDisplayedName, 
435                         boolean isUpdateable, boolean isParametersEditable, boolean isDownloadable, boolean isDeleteable) {
436                 Assert.assertEquals(GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_NAME.getValue() + artifactDisplayedName).getText(), fileName);
437                 Assert.assertEquals(GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_DISPLAY_NAME.getValue() + artifactDisplayedName).getText(), artifactDisplayedName);
438                 
439                 GeneralUIUtils.hoverOnAreaByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_DISPLAY_NAME.getValue() + artifactDisplayedName);
440                 
441                 if(isParametersEditable) {
442                         Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.EDIT_PARAMETERS_OF_ARTIFACT.getValue() + artifactDisplayedName), true, "Expect that parameters edit button enabled.");
443                 } else {
444                         Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.EDIT_PARAMETERS_OF_ARTIFACT.getValue() + artifactDisplayedName), false, "Expect that parameters edit button disabled.");
445                 }
446                 if(isDownloadable) {
447                         Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.DOWNLOAD.getValue() + artifactDisplayedName), true, "Expect that download button enabled.");
448                 } else {
449                         Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.DOWNLOAD.getValue() + artifactDisplayedName), false, "Expect that download button disabled.");
450                 }
451                 if(isDeleteable) {
452                         Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.DELETE.getValue() + artifactDisplayedName), true, "Expect that delete button enabled.");
453                 } else {
454                         Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.DELETE.getValue() + artifactDisplayedName), false, "Expect that delete button disabled.");
455                 }
456                 if(isUpdateable) {
457                         GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_DISPLAY_NAME.getValue() + artifactDisplayedName);
458                         Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.ArtifactPopup.MODAL_WINDOW.getValue()), true, "Expect that edit button enabled.");
459                         GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ArtifactPopup.DONE_BUTTON.getValue());
460                         GeneralUIUtils.waitForElementInVisibilityByTestId(DataTestIdEnum.ArtifactPopup.DONE_BUTTON.getValue());
461                 } else {
462                         GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_DISPLAY_NAME.getValue() + artifactDisplayedName);
463                         Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.ArtifactPopup.MODAL_WINDOW.getValue()), false, "Expect that edit button disabled.");
464                 }
465                 
466         }
467         
468         public static void validateNotExistArtifactOnCompositionRightMenuDeploymentInformationPage(String artifactDisplayedName) {
469                 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_NAME.getValue() + artifactDisplayedName), false);
470         }
471         
472         public static File verifyUpdatedEnvParameters(HeatWithParametersDefinition pairToUpdate, File updateEnvFile, String dataTestId) throws Exception {
473                 GeneralUIUtils.hoverOnAreaByTestId(dataTestId);
474                 return verifyUpdatedEnvParameters(pairToUpdate, updateEnvFile);
475         }
476         
477         public static File verifyUpdatedEnvParameters(HeatWithParametersDefinition pairToUpdate, File updateEnvFile) throws Exception {
478
479                 String heatDisplayName = pairToUpdate.getHeatArtifactDisplayName();
480                 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ArtifactPageEnum.DOWNLOAD_ARTIFACT_ENV.getValue()+heatDisplayName);
481                 File latestFilefromDir = FileHandling.getLastModifiedFileFromDir();
482                 
483                 String pattern = PARAMETERS;
484                 Map<String, Object> mapUpdetedEnvFile = FileHandling.parseYamlFileToMapByPattern(updateEnvFile, pattern);
485                 Map<String, Object> mapDownloadedEnvFile = FileHandling.parseYamlFileToMapByPattern(latestFilefromDir, pattern);
486                 
487                 SetupCDTest.getExtendTest().log(Status.INFO, "Going to check, that ENV file was updated ...");
488                 assertTrue("File" + latestFilefromDir.getName() + " contains different parameters number from expected file", mapDownloadedEnvFile.size() == mapUpdetedEnvFile.size());
489                 assertTrue("Updated file contains not updated parameters value", mapDownloadedEnvFile.entrySet().containsAll(mapUpdetedEnvFile.entrySet()));
490                 return latestFilefromDir;
491         }
492         
493         /**
494          * compare heat env files by pattern ("parameters")
495          * @param expectedFile
496          * @param actualFile
497          * @param pattern
498          * @throws Exception
499          */
500         public static void compareYamlFilesByPattern(File expectedFile, File actualFile, String pattern) throws Exception {
501
502                 Map<String, Object> mapExpectedFile = FileHandling.parseYamlFileToMapByPattern(expectedFile, pattern);
503                 Map<String, Object> mapActualFile = FileHandling.parseYamlFileToMapByPattern(actualFile, pattern);
504                 SetupCDTest.getExtendTest().log(Status.INFO, "Going to compare files ...");
505                 assertTrue("File" + actualFile.getName() + " contains different parameters number from expected file", mapActualFile.size() == mapExpectedFile.size());
506                 assertTrue("File " + actualFile.getName() + " does not contains all expected parametrs", mapActualFile.entrySet().containsAll(mapExpectedFile.entrySet()));
507         }
508         
509         public static void compareYamlParametersByPattern(Map<String, Object> mapExpectedproperties, File actualFileproperties, String pattern) throws Exception {
510
511                 Map<String, Object> mapActualFileProerties = FileHandling.parseYamlFileToMapByPattern(actualFileproperties, pattern);
512                 SetupCDTest.getExtendTest().log(Status.INFO, "Going to compare files ...");
513                 assertTrue("Actual file contains different parameters number from expected file", mapActualFileProerties.size() == mapExpectedproperties.size());
514                 Map<String, Object> newMap = new HashMap<>(mapActualFileProerties);             
515                 assertTrue("Actual file does not contains all expected parametrs", newMap.entrySet().containsAll(mapExpectedproperties.entrySet()));
516         }
517         
518
519         public static File uploadCreatedUpdateParametersEnvFile(HeatWithParametersDefinition heatEnvDetails, String directoryPath) throws Exception {
520 //              created env file to upload
521                 File pathToEnvParametersFile = prepareEnvParametersFile(heatEnvDetails, directoryPath);
522                 ArtifactInfo heatEnvArtifactInfo = new ArtifactInfo(directoryPath, heatEnvDetails.getHeatEnvLabel()+".env", "heatEnvDesc", heatEnvDetails.getHeatEnvLabel(),heatEnvDetails.getHeatEnvArtifactType());
523                 ArtifactUIUtils.fillAndAddNewEnvArtifactParameters(heatEnvArtifactInfo, CompositionPage.artifactPopup());
524                 return pathToEnvParametersFile;
525         }
526
527         public static File prepareEnvParametersFile(HeatWithParametersDefinition heatEnvDetails, String directoryPath) throws IOException {
528                 File pathToEnvParametersFile = FileHandling.createEmptyFile(directoryPath+heatEnvDetails.getHeatEnvLabel()+".env");
529 //              fill file
530                 FileHandling.writeToFile(pathToEnvParametersFile, "parameters:", 0);
531                 for(HeatParameterDataDefinition paramDefinition : heatEnvDetails.getHeatParameterDefinition()){
532                         Object data = getDataToWrite(paramDefinition);
533                         FileHandling.writeToFile(pathToEnvParametersFile, data, 2);
534                 }
535                 
536                 return pathToEnvParametersFile;
537         }
538
539         public static Object getDataToWrite(HeatParameterDataDefinition paramDefinition) {
540                 Object data = "";
541                 switch (paramDefinition.getType()) {
542                 case "string":
543                         String text = "\"string\"";
544                         data = getFormatedData(paramDefinition.getName(), text);
545                         break;
546                 case "number":
547                         data = getFormatedData(paramDefinition.getName(), 666); 
548                         break;
549                 case "json":
550                         String jsonText = "{\"param1\":\"param1\", \"param2\":2}";
551                         data = getFormatedData(paramDefinition.getName(), jsonText);
552                         break;
553                 case "boolean":
554                         if(paramDefinition.getCurrentValue().equals("true")){
555                                 data = getFormatedData(paramDefinition.getName(), false);
556                         }else{
557                                 data = getFormatedData(paramDefinition.getName(), true);
558                         }
559                         break;
560                 case "comma_delimited_list":
561                         String commaDelimitedListText = "127.0.0.10, 127.0.0.15, 127.0.0.20";
562                         data = getFormatedData(paramDefinition.getName(), commaDelimitedListText);
563                         break;
564                 default:
565                         break;
566                 }
567                 return data;
568         }
569         
570         
571         public static Map<String, Object> getDataToWriteInUI(List<HeatParameterDataDefinition> paramDefinitionFromGetResourceResponse) {
572                 Map<String, Object>newValuesToUpdateInUI=new HashMap<>();
573                 for (HeatParameterDataDefinition param : paramDefinitionFromGetResourceResponse) {
574                         System.out.println(param.getCurrentValue());
575                         switch (param.getType()) {
576
577                         case "string":
578                                 String text = "string";
579                                 newValuesToUpdateInUI.put(param.getName(),text);
580                                 break;
581                         case "number":
582                                 newValuesToUpdateInUI.put(param.getName(),666);
583                                 break;
584                         case "json":
585                                 String jsonText = "{\"param1\":\"param1\", \"param2\":2}";
586                                 newValuesToUpdateInUI.put(param.getName(),jsonText);
587                                 break;
588                         case "boolean":
589                                 if (param.getCurrentValue().equals(true)) {
590                                         newValuesToUpdateInUI.put(param.getName(),false);
591                                 } else {
592                                         newValuesToUpdateInUI.put(param.getName(),true);
593                                 }
594                                 break;
595                         case "comma_delimited_list":
596                                 String commaDelimitedListText = "127.0.0.10, 127.0.0.15, 127.0.0.20";
597                                 newValuesToUpdateInUI.put(param.getName(),commaDelimitedListText);
598                                 break;
599                         default:
600                                 break;
601
602                         }
603
604                 }
605                 return newValuesToUpdateInUI;
606         }
607         
608         public static Object getValue(HeatParameterDataDefinition param) {
609                 String type = param.getType();
610                 Object result = null;
611                 switch(type){
612                 case "string":
613                         result = param.getCurrentValue();
614                         break;
615                 case "number":
616                         result = new Integer(param.getCurrentValue());
617                         break;
618                 case "json":
619                         result = param.getCurrentValue();
620                         break;
621                 case "boolean":
622                         result = new Boolean(param.getCurrentValue());
623                         break;
624                 case "comma_delimited_list":
625                         result = param.getCurrentValue();
626                         break;
627                 default:
628                         break;
629                 }
630                 return result;
631         }
632
633         public static Object getFormatedData(String name, Object text) {
634                 return name + ": " + text;  
635 }
636         
637
638 }