2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.ci.tests.utilities;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertTrue;
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;
32 import java.io.IOException;
33 import java.util.HashMap;
34 import java.util.List;
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;
57 import com.aventstack.extentreports.Status;
59 public final class ArtifactUIUtils {
61 private static final String PARAMETERS = "parameters";
63 private ArtifactUIUtils() {
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();
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()));
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()));
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();
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();
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();
118 public static RestResponse deploymentArtifactResourceInUI(ResourceReqDetails resource, User user,
119 ArtifactReqDetails artifact, String file) throws Exception {
122 List<WebElement> listFormInput = GeneralUIUtils.getDriver()
123 .findElements(By.className("i-sdc-designer-sidebar-tab"));
124 WebElement addArtifactElement = listFormInput.get(2);
125 addArtifactElement.click();
127 WebElement addArtifact = GeneralUIUtils.getDriver()
128 .findElement(By.className("i-sdc-designer-sidebar-section-content-item-artifact-details-name"));
132 WebElement descriptionProperty = GeneralUIUtils.getDriver().findElement(By.className("i-sdc-form-textarea"));
133 descriptionProperty.clear();
134 descriptionProperty.sendKeys(artifact.getDescription());
136 WebElement uploadFile = GeneralUIUtils.getDriver().findElement(By.className("i-sdc-form-label-upload"));
139 StringSelection sel = new StringSelection(file);
140 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(sel, null);
141 // System.out.println("selection" + sel);
144 Robot robot = new Robot();
149 robot.keyPress(KeyEvent.VK_ENTER);
152 robot.keyRelease(KeyEvent.VK_ENTER);
155 robot.keyPress(KeyEvent.VK_CONTROL);
156 robot.keyPress(KeyEvent.VK_V);
159 robot.keyRelease(KeyEvent.VK_CONTROL);
160 robot.keyRelease(KeyEvent.VK_V);
164 robot.keyPress(KeyEvent.VK_ENTER);
165 robot.keyRelease(KeyEvent.VK_ENTER);
168 WebElement clickDone = GeneralUIUtils.getDriver().findElement(By.className("w-sdc-form-action"));
173 GeneralUIUtils.getDriver().findElement(By.cssSelector("button[data-ng-click^=save]")).click();
175 RestResponse getResource = RestCDUtils.getResource(resource, user);
176 assertEquals("Did not succeed to get resource after create", 200, getResource.getErrorCode().intValue());
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();
186 // final WebElement browseWebElement = GeneralUIUtils.retryMethodOnException(
187 // () -> GeneralUIUtils.getWebElementByDataTestId(DataTestIdEnum.ModalItems.BROWSE_BUTTON.getValue()));
189 WebElement browseWebElement = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ModalItems.BROWSE_BUTTON.getValue());
190 browseWebElement.sendKeys(filePath);
192 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ModalItems.DESCRIPTION.getValue())
193 .sendKeys(artifact.getDescription());
194 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ModalItems.ADD.getValue()).click();
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);
204 Robot robot = new Robot();
206 robot.keyPress(KeyEvent.VK_ENTER);
209 robot.keyRelease(KeyEvent.VK_ENTER);
212 robot.keyPress(KeyEvent.VK_CONTROL);
213 robot.keyPress(KeyEvent.VK_V);
216 robot.keyRelease(KeyEvent.VK_CONTROL);
217 robot.keyRelease(KeyEvent.VK_V);
221 robot.keyPress(KeyEvent.VK_ENTER);
222 robot.keyRelease(KeyEvent.VK_ENTER);
226 static WebElement ArtifactLabel;
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()
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();
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);
246 artifactValues.put("type", type);
247 artifactValues.put("description", description);
248 artifactValues.put("name", labelName);
249 artifactValues.put("fileName", fileName);
250 return artifactValues;
253 public static Map<String, String> addDeploymentArtifact(String artifactLabel, String artifactType, String fileName)
257 Map<String, String> artifactValues = new HashMap<String, String>();
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();
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();
270 String description = "This is Description";
271 GeneralUIUtils.setWebElementByTestId("description", "description" );
272 ResourceUIUtils.importFileWithSendKeyBrowse(ImportAssetUIUtils.FILE_PATH, fileName);
274 GeneralUIUtils.getWebElementByTestID("Add").click();
275 } catch (Exception e) {
276 GeneralUIUtils.getWebElementByClassName("w-sdc-form-action add-property").click();
279 artifactValues.put("type", artifactType);
280 artifactValues.put("description", description);
281 artifactValues.put("name", labelName);
282 artifactValues.put("fileName", fileName);
283 return artifactValues;
287 public static Map<String, String> addDeploymentArtifactFromCanvas(String artifactLabel) throws Exception {
289 Map<String, String> artifactValues = new HashMap<String, String>();
290 String labelName = GeneralUIUtils.getSelectList(artifactLabel, "selectArtifact").getFirstSelectedOption()
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();
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;
311 public static Map<String, String> valideArtifact(Map<String, String> artifactValues, Boolean condition)
314 GeneralUIUtils.getWebElementByClassName("table-edit-btn").click();
316 System.out.println(artifactValues.get("name"));
317 GeneralUIUtils.getWebElementByTestID("edit_" + artifactValues.get("name")).click();
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;
332 public static void valideArtifactFromCanvas(Map<String, String> artifactValues) throws Exception {
333 GeneralUIUtils.getWebElementByTestID("artifactDisplayName-" + artifactValues.get("name")).click();
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"));
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);
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.");
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.");
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.");
371 public static void validateArtifactVersionByTypeAndLabel(String artifactLabel, String expectedArtifactVersion, ArtifactTypeEnum artifactType) {
372 if(expectedArtifactVersion != null) {
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 + "']";
378 xPath = "//*[@data-tests-id='" + DataTestIdEnum.ArtifactPageEnum.VERSION.getValue() + artifactLabel + "']";
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);
385 public static void validateExistArtifactOnDeploymentInformationPage(String expectedArtifactLabel, String artifactUUID, String artifactVersion, String artifactType, boolean isDownloadable, boolean isEditable, boolean isDeletable, boolean isArtifactParametersEditable) {
387 String dataTestId = DataTestIdEnum.ArtifactPageEnum.ARTIFACT_NAME.getValue() + expectedArtifactLabel;
389 List<WebElement> artifactElements = GeneralUIUtils.getWebElementsListByContainTestID(dataTestId);
390 Assert.assertEquals(artifactElements.size(), 1, "There are more then one artifact named " + expectedArtifactLabel);
392 WebElement artifact = artifactElements.get(0);
393 String actualArtifactLabel = GeneralUIUtils.getTextContentAttributeValue(artifact).trim();
394 Assert.assertEquals(actualArtifactLabel, expectedArtifactLabel);
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.");
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.");
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.");
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.");
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.");
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.");
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.");
430 public static void validateNotExistArtifactOnDeploymentInformationPage(String artifactLabel) {
431 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.ArtifactPageEnum.ARTIFACT_NAME.getValue() + artifactLabel), false);
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);
439 GeneralUIUtils.hoverOnAreaByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_DISPLAY_NAME.getValue() + artifactDisplayedName);
441 if(isParametersEditable) {
442 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.EDIT_PARAMETERS_OF_ARTIFACT.getValue() + artifactDisplayedName), true, "Expect that parameters edit button enabled.");
444 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.EDIT_PARAMETERS_OF_ARTIFACT.getValue() + artifactDisplayedName), false, "Expect that parameters edit button disabled.");
447 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.DOWNLOAD.getValue() + artifactDisplayedName), true, "Expect that download button enabled.");
449 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.DOWNLOAD.getValue() + artifactDisplayedName), false, "Expect that download button disabled.");
452 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.DELETE.getValue() + artifactDisplayedName), true, "Expect that delete button enabled.");
454 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.DELETE.getValue() + artifactDisplayedName), false, "Expect that delete button disabled.");
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());
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.");
468 public static void validateNotExistArtifactOnCompositionRightMenuDeploymentInformationPage(String artifactDisplayedName) {
469 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_NAME.getValue() + artifactDisplayedName), false);
472 public static File verifyUpdatedEnvParameters(HeatWithParametersDefinition pairToUpdate, File updateEnvFile, String dataTestId) throws Exception {
473 GeneralUIUtils.hoverOnAreaByTestId(dataTestId);
474 return verifyUpdatedEnvParameters(pairToUpdate, updateEnvFile);
477 public static File verifyUpdatedEnvParameters(HeatWithParametersDefinition pairToUpdate, File updateEnvFile) throws Exception {
479 String heatDisplayName = pairToUpdate.getHeatArtifactDisplayName();
480 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ArtifactPageEnum.DOWNLOAD_ARTIFACT_ENV.getValue()+heatDisplayName);
481 File latestFilefromDir = FileHandling.getLastModifiedFileFromDir();
483 String pattern = PARAMETERS;
484 Map<String, Object> mapUpdetedEnvFile = FileHandling.parseYamlFileToMapByPattern(updateEnvFile, pattern);
485 Map<String, Object> mapDownloadedEnvFile = FileHandling.parseYamlFileToMapByPattern(latestFilefromDir, pattern);
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;
494 * compare heat env files by pattern ("parameters")
495 * @param expectedFile
500 public static void compareYamlFilesByPattern(File expectedFile, File actualFile, String pattern) throws Exception {
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()));
509 public static void compareYamlParametersByPattern(Map<String, Object> mapExpectedproperties, File actualFileproperties, String pattern) throws Exception {
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()));
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;
527 public static File prepareEnvParametersFile(HeatWithParametersDefinition heatEnvDetails, String directoryPath) throws IOException {
528 File pathToEnvParametersFile = FileHandling.createEmptyFile(directoryPath+heatEnvDetails.getHeatEnvLabel()+".env");
530 FileHandling.writeToFile(pathToEnvParametersFile, "parameters:", 0);
531 for(HeatParameterDataDefinition paramDefinition : heatEnvDetails.getHeatParameterDefinition()){
532 Object data = getDataToWrite(paramDefinition);
533 FileHandling.writeToFile(pathToEnvParametersFile, data, 2);
536 return pathToEnvParametersFile;
539 public static Object getDataToWrite(HeatParameterDataDefinition paramDefinition) {
541 switch (paramDefinition.getType()) {
543 String text = "\"string\"";
544 data = getFormatedData(paramDefinition.getName(), text);
547 data = getFormatedData(paramDefinition.getName(), 666);
550 String jsonText = "{\"param1\":\"param1\", \"param2\":2}";
551 data = getFormatedData(paramDefinition.getName(), jsonText);
554 if(paramDefinition.getCurrentValue().equals("true")){
555 data = getFormatedData(paramDefinition.getName(), false);
557 data = getFormatedData(paramDefinition.getName(), true);
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);
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()) {
578 String text = "string";
579 newValuesToUpdateInUI.put(param.getName(),text);
582 newValuesToUpdateInUI.put(param.getName(),666);
585 String jsonText = "{\"param1\":\"param1\", \"param2\":2}";
586 newValuesToUpdateInUI.put(param.getName(),jsonText);
589 if (param.getCurrentValue().equals(true)) {
590 newValuesToUpdateInUI.put(param.getName(),false);
592 newValuesToUpdateInUI.put(param.getName(),true);
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);
605 return newValuesToUpdateInUI;
608 public static Object getValue(HeatParameterDataDefinition param) {
609 String type = param.getType();
610 Object result = null;
613 result = param.getCurrentValue();
616 result = new Integer(param.getCurrentValue());
619 result = param.getCurrentValue();
622 result = new Boolean(param.getCurrentValue());
624 case "comma_delimited_list":
625 result = param.getCurrentValue();
633 public static Object getFormatedData(String name, Object text) {
634 return name + ": " + text;