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