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.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;
58 import com.aventstack.extentreports.Status;
60 public final class ArtifactUIUtils {
62 private static final String PARAMETERS = "parameters";
64 private ArtifactUIUtils() {
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();
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()));
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()));
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();
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();
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();
119 public static RestResponse deploymentArtifactResourceInUI(ResourceReqDetails resource, User user,
120 ArtifactReqDetails artifact, String file) throws Exception {
123 List<WebElement> listFormInput = GeneralUIUtils.getDriver()
124 .findElements(By.className("i-sdc-designer-sidebar-tab"));
125 WebElement addArtifactElement = listFormInput.get(2);
126 addArtifactElement.click();
128 WebElement addArtifact = GeneralUIUtils.getDriver()
129 .findElement(By.className("i-sdc-designer-sidebar-section-content-item-artifact-details-name"));
133 WebElement descriptionProperty = GeneralUIUtils.getDriver().findElement(By.className("i-sdc-form-textarea"));
134 descriptionProperty.clear();
135 descriptionProperty.sendKeys(artifact.getDescription());
137 WebElement uploadFile = GeneralUIUtils.getDriver().findElement(By.className("i-sdc-form-label-upload"));
140 StringSelection sel = new StringSelection(file);
141 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(sel, null);
142 // System.out.println("selection" + sel);
145 Robot robot = new Robot();
150 robot.keyPress(KeyEvent.VK_ENTER);
153 robot.keyRelease(KeyEvent.VK_ENTER);
156 robot.keyPress(KeyEvent.VK_CONTROL);
157 robot.keyPress(KeyEvent.VK_V);
160 robot.keyRelease(KeyEvent.VK_CONTROL);
161 robot.keyRelease(KeyEvent.VK_V);
165 robot.keyPress(KeyEvent.VK_ENTER);
166 robot.keyRelease(KeyEvent.VK_ENTER);
169 WebElement clickDone = GeneralUIUtils.getDriver().findElement(By.className("w-sdc-form-action"));
174 GeneralUIUtils.getDriver().findElement(By.cssSelector("button[data-ng-click^=save]")).click();
176 RestResponse getResource = RestCDUtils.getResource(resource, user);
177 assertEquals("Did not succeed to get resource after create", 200, getResource.getErrorCode().intValue());
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();
187 // final WebElement browseWebElement = GeneralUIUtils.retryMethodOnException(
188 // () -> GeneralUIUtils.getWebElementByDataTestId(DataTestIdEnum.ModalItems.BROWSE_BUTTON.getValue()));
190 WebElement browseWebElement = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ModalItems.BROWSE_BUTTON.getValue());
191 browseWebElement.sendKeys(filePath);
193 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ModalItems.DESCRIPTION.getValue())
194 .sendKeys(artifact.getDescription());
195 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ModalItems.ADD.getValue()).click();
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);
205 Robot robot = new Robot();
207 robot.keyPress(KeyEvent.VK_ENTER);
210 robot.keyRelease(KeyEvent.VK_ENTER);
213 robot.keyPress(KeyEvent.VK_CONTROL);
214 robot.keyPress(KeyEvent.VK_V);
217 robot.keyRelease(KeyEvent.VK_CONTROL);
218 robot.keyRelease(KeyEvent.VK_V);
222 robot.keyPress(KeyEvent.VK_ENTER);
223 robot.keyRelease(KeyEvent.VK_ENTER);
227 static WebElement ArtifactLabel;
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()
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();
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);
247 artifactValues.put("type", type);
248 artifactValues.put("description", description);
249 artifactValues.put("name", labelName);
250 artifactValues.put("fileName", fileName);
251 return artifactValues;
254 public static Map<String, String> addDeploymentArtifact(String artifactLabel, String artifactType, String fileName)
258 Map<String, String> artifactValues = new HashMap<String, String>();
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();
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();
271 String description = "This is Description";
272 GeneralUIUtils.setWebElementByTestId("description", "description" );
273 ResourceUIUtils.importFileWithSendKeyBrowse(ImportAssetUIUtils.FILE_PATH, fileName);
275 GeneralUIUtils.getWebElementByTestID("Add").click();
276 } catch (Exception e) {
277 GeneralUIUtils.getWebElementByClassName("w-sdc-form-action add-property").click();
280 artifactValues.put("type", artifactType);
281 artifactValues.put("description", description);
282 artifactValues.put("name", labelName);
283 artifactValues.put("fileName", fileName);
284 return artifactValues;
288 public static Map<String, String> addDeploymentArtifactFromCanvas(String artifactLabel) throws Exception {
290 Map<String, String> artifactValues = new HashMap<String, String>();
291 String labelName = GeneralUIUtils.getSelectList(artifactLabel, "selectArtifact").getFirstSelectedOption()
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();
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;
312 public static Map<String, String> valideArtifact(Map<String, String> artifactValues, Boolean condition)
315 GeneralUIUtils.getWebElementByClassName("table-edit-btn").click();
317 System.out.println(artifactValues.get("name"));
318 GeneralUIUtils.getWebElementByTestID("edit_" + artifactValues.get("name")).click();
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;
333 public static void valideArtifactFromCanvas(Map<String, String> artifactValues) throws Exception {
334 GeneralUIUtils.getWebElementByTestID("artifactDisplayName-" + artifactValues.get("name")).click();
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"));
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);
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.");
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.");
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.");
372 public static void validateArtifactVersionByTypeAndLabel(String artifactLabel, String expectedArtifactVersion, ArtifactTypeEnum artifactType) {
373 if(expectedArtifactVersion != null) {
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 + "']";
379 xPath = "//*[@data-tests-id='" + DataTestIdEnum.ArtifactPageEnum.VERSION.getValue() + artifactLabel + "']";
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);
386 public static void validateExistArtifactOnDeploymentInformationPage(String expectedArtifactLabel, String artifactUUID, String artifactVersion, String artifactType, boolean isDownloadable, boolean isEditable, boolean isDeletable, boolean isArtifactParametersEditable) {
388 String dataTestId = DataTestIdEnum.ArtifactPageEnum.ARTIFACT_NAME.getValue() + expectedArtifactLabel;
390 List<WebElement> artifactElements = GeneralUIUtils.getWebElementsListByContainTestID(dataTestId);
391 Assert.assertEquals(artifactElements.size(), 1, "There are more then one artifact named " + expectedArtifactLabel);
393 WebElement artifact = artifactElements.get(0);
394 String actualArtifactLabel = GeneralUIUtils.getTextContentAttributeValue(artifact).trim();
395 Assert.assertEquals(actualArtifactLabel, expectedArtifactLabel);
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.");
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.");
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.");
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.");
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.");
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.");
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.");
431 public static void validateNotExistArtifactOnDeploymentInformationPage(String artifactLabel) {
432 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.ArtifactPageEnum.ARTIFACT_NAME.getValue() + artifactLabel), false);
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);
440 GeneralUIUtils.hoverOnAreaByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_DISPLAY_NAME.getValue() + artifactDisplayedName);
442 if(isParametersEditable) {
443 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.EDIT_PARAMETERS_OF_ARTIFACT.getValue() + artifactDisplayedName), true, "Expect that parameters edit button enabled.");
445 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.EDIT_PARAMETERS_OF_ARTIFACT.getValue() + artifactDisplayedName), false, "Expect that parameters edit button disabled.");
448 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.DOWNLOAD.getValue() + artifactDisplayedName), true, "Expect that download button enabled.");
450 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.DOWNLOAD.getValue() + artifactDisplayedName), false, "Expect that download button disabled.");
453 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.DELETE.getValue() + artifactDisplayedName), true, "Expect that delete button enabled.");
455 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.DELETE.getValue() + artifactDisplayedName), false, "Expect that delete button disabled.");
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());
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.");
469 public static void validateNotExistArtifactOnCompositionRightMenuDeploymentInformationPage(String artifactDisplayedName) {
470 Assert.assertEquals(GeneralUIUtils.isWebElementExistByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_NAME.getValue() + artifactDisplayedName), false);
473 public static File verifyUpdatedEnvParameters(HeatWithParametersDefinition pairToUpdate, File updateEnvFile, String dataTestId) throws Exception {
474 GeneralUIUtils.hoverOnAreaByTestId(dataTestId);
475 return verifyUpdatedEnvParameters(pairToUpdate, updateEnvFile);
478 public static File verifyUpdatedEnvParameters(HeatWithParametersDefinition pairToUpdate, File updateEnvFile) throws Exception {
480 String heatDisplayName = pairToUpdate.getHeatArtifactDisplayName();
481 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ArtifactPageEnum.DOWNLOAD_ARTIFACT_ENV.getValue()+heatDisplayName);
482 File latestFilefromDir = FileHandling.getLastModifiedFileNameFromDir();
484 String pattern = PARAMETERS;
485 Map<String, Object> mapUpdetedEnvFile = FileHandling.parseYamlFileToMapByPattern(updateEnvFile, pattern);
486 Map<String, Object> mapDownloadedEnvFile = FileHandling.parseYamlFileToMapByPattern(latestFilefromDir, pattern);
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;
495 * compare heat env files by pattern ("parameters")
496 * @param expectedFile
501 public static void compareYamlFilesByPattern(File expectedFile, File actualFile, String pattern) throws Exception {
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()));
510 public static void compareYamlParametersByPattern(Map<String, Object> mapExpectedProperties, File actualFileProperties, String pattern) throws Exception {
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()));
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;
528 public static File prepareEnvParametersFile(HeatWithParametersDefinition heatEnvDetails, String directoryPath) throws IOException {
529 File pathToEnvParametersFile = FileHandling.createEmptyFile(directoryPath+heatEnvDetails.getHeatEnvLabel()+".env");
531 FileHandling.writeToFile(pathToEnvParametersFile, "parameters:", 0);
532 for(HeatParameterDataDefinition paramDefinition : heatEnvDetails.getHeatParameterDefinition()){
533 Object data = getDataToWrite(paramDefinition);
534 FileHandling.writeToFile(pathToEnvParametersFile, data, 2);
537 return pathToEnvParametersFile;
540 public static Object getDataToWrite(HeatParameterDataDefinition paramDefinition) {
542 switch (paramDefinition.getType()) {
544 String text = "\"string\"";
545 data = getFormatedData(paramDefinition.getName(), text);
548 data = getFormatedData(paramDefinition.getName(), 666);
551 String jsonText = "{\"param1\":\"param1\", \"param2\":2}";
552 data = getFormatedData(paramDefinition.getName(), jsonText);
555 if(paramDefinition.getCurrentValue().equals("true")){
556 data = getFormatedData(paramDefinition.getName(), false);
558 data = getFormatedData(paramDefinition.getName(), true);
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);
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()) {
579 String text = "string";
580 newValuesToUpdateInUI.put(param.getName(),text);
583 newValuesToUpdateInUI.put(param.getName(),666);
586 String jsonText = "{\"param1\":\"param1\", \"param2\":2}";
587 newValuesToUpdateInUI.put(param.getName(),jsonText);
590 if (param.getCurrentValue().equals(true)) {
591 newValuesToUpdateInUI.put(param.getName(),false);
593 newValuesToUpdateInUI.put(param.getName(),true);
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);
606 return newValuesToUpdateInUI;
609 public static Object getValue(HeatParameterDataDefinition param) {
610 String type = param.getType();
611 Object result = null;
614 result = param.getCurrentValue();
617 result = new Integer(param.getCurrentValue());
620 result = param.getCurrentValue();
623 result = new Boolean(param.getCurrentValue());
625 case "comma_delimited_list":
626 result = param.getCurrentValue();
634 public static Object getFormatedData(String name, Object text) {
635 return name + ": " + text;