summaryrefslogtreecommitdiffstats
path: root/integration-tests
diff options
context:
space:
mode:
authordavsad <david.sadlier@est.tech>2021-06-08 07:17:07 +0100
committerMichael Morris <michael.morris@est.tech>2021-10-06 11:31:51 +0000
commita03a1059f8e4b8b46ab662e9a865b3ae6bb77b53 (patch)
tree13f488a090b3ec57c07ee04584aa24b9a47080c7 /integration-tests
parent7b60bd7a745d38fd9e51630b6245c2f227abe830 (diff)
Adding type safety to the service dependency editor.
Issue-ID: SDC-3725 Signed-off-by: davsad <david.sadlier@est.tech> Change-Id: I63d77837fb0df24f5ee12baa5b852a76ce5f55e3
Diffstat (limited to 'integration-tests')
-rw-r--r--integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/datatypes/ServiceDependencyProperty.java4
-rw-r--r--integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/execute/sanity/ServiceTemplateDesignUiTests.java14
-rw-r--r--integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/pages/ResourcePropertiesPage.java20
-rw-r--r--integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/pages/ServiceDependenciesEditor.java62
4 files changed, 82 insertions, 18 deletions
diff --git a/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/datatypes/ServiceDependencyProperty.java b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/datatypes/ServiceDependencyProperty.java
index 6afbdc244a..47b8df26ad 100644
--- a/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/datatypes/ServiceDependencyProperty.java
+++ b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/datatypes/ServiceDependencyProperty.java
@@ -32,12 +32,14 @@ public class ServiceDependencyProperty {
private final String name;
private final String value;
private final String source;
+ private final String type;
private final LogicalOperator logicalOperator;
- public ServiceDependencyProperty(String name, String value, LogicalOperator logicalOperator) {
+ public ServiceDependencyProperty(String name, String type, String value, LogicalOperator logicalOperator) {
this.name = name;
this.value = value;
this.source = "Static";
+ this.type = type;
this.logicalOperator = logicalOperator;
}
}
diff --git a/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/execute/sanity/ServiceTemplateDesignUiTests.java b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/execute/sanity/ServiceTemplateDesignUiTests.java
index e944ab329a..8bec8353ef 100644
--- a/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/execute/sanity/ServiceTemplateDesignUiTests.java
+++ b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/execute/sanity/ServiceTemplateDesignUiTests.java
@@ -284,8 +284,10 @@ public class ServiceTemplateDesignUiTests extends SetupCDTest {
componentPage.isLoaded();
final ResourcePropertiesPage vfcPropertiesPage = componentPage.goToProperties();
vfcPropertiesPage.isLoaded();
- final List<String> propertyNames = vfcPropertiesPage.getPropertyNames();
- final ServiceDependencyProperty serviceDependencyProperty = new ServiceDependencyProperty(propertyNames.get(0), value, operator);
+ final Map<String, String> propertyNamesAndTypes = vfcPropertiesPage.getPropertyNamesAndTypes();
+ final List<String> propertyNames = propertyNamesAndTypes.keySet().stream().collect(Collectors.toList());
+ final ServiceDependencyProperty serviceDependencyProperty =
+ new ServiceDependencyProperty(propertyNames.get(0), propertyNamesAndTypes.get(propertyNames.get(0)), value, operator);
homePage.getTopNavComponent().clickOnHome();
homePage.isLoaded();
@@ -881,7 +883,7 @@ public class ServiceTemplateDesignUiTests extends SetupCDTest {
assertThat(String.format("The Component '%s' should have properties", vfResourceCreateData.getName()), propertyNamesAndTypes,
not(anEmptyMap()));
propertyNamesAndTypes.forEach((name, type)
- -> substitutionFilterProperties.add(new ServiceDependencyProperty(name, getPropertyValueByType(type), LogicalOperator.EQUALS)));
+ -> substitutionFilterProperties.add(new ServiceDependencyProperty(name, type, getPropertyValueByType(type), LogicalOperator.EQUALS)));
}
private String getPropertyValueByType(final String type) {
@@ -895,9 +897,9 @@ public class ServiceTemplateDesignUiTests extends SetupCDTest {
case "boolean":
return "TRUE";
case "list":
- return "[value1, value2]";
+ return "[\"value1\", \"value2\"]";
case "map":
- return "MyKey: MyValue";
+ return "{\"MyKey\": \"MyValue\"}";
default:
throw new UnsupportedOperationException("Not yet implemented for " + type);
}
@@ -925,7 +927,7 @@ public class ServiceTemplateDesignUiTests extends SetupCDTest {
substitutionFilterMap.containsKey(substitutionFilterProperty.getName()));
final Map<?, ?> substitutionFilterValue = (Map<?, ?>) ((List<?>) substitutionFilterMap.get(substitutionFilterProperty.getName())).get(0);
assertThat("Substitution Filter Value should not be empty", substitutionFilterMap, not(anEmptyMap()));
- final String expectedSubstitutionPropertyValue = substitutionFilterProperty.getValue();
+ final String expectedSubstitutionPropertyValue = substitutionFilterProperty.getValue().replaceAll("[\"{}]", "");
final String actualSubstitutionPropertyValue = substitutionFilterValue.values().stream().findFirst().get() instanceof Map
? substitutionFilterValue.values().stream().findFirst().get().toString().replace("=", ": ")
.replaceAll("\\{(.*?)\\}", "$1").trim()
diff --git a/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/pages/ResourcePropertiesPage.java b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/pages/ResourcePropertiesPage.java
index ace3041577..2d45c7c22a 100644
--- a/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/pages/ResourcePropertiesPage.java
+++ b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/pages/ResourcePropertiesPage.java
@@ -19,11 +19,13 @@
package org.onap.sdc.frontend.ci.tests.pages;
+import java.util.HashMap;
import java.util.List;
-import java.util.stream.Collectors;
+import java.util.Map;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
import lombok.AllArgsConstructor;
import lombok.Getter;
@@ -52,13 +54,19 @@ public class ResourcePropertiesPage extends AbstractPageObject {
}
/**
- * Returns a list based on property names
- * @return list of names from the properties table
+ * Creates a map based on property names and data types
*/
- public List<String> getPropertyNames() {
+ public Map<String, String> getPropertyNamesAndTypes() {
waitPropertiesToLoad();
- return findElements(By.xpath(XpathSelector.PROPERTY_NAMES.getXpath())).stream()
- .map(ele -> ele.getAttribute("innerText")).collect(Collectors.toList());
+ final Map<String, String> namesAndTypes = new HashMap<>();
+ final List<WebElement> names = findElements(By.xpath(XpathSelector.PROPERTY_NAMES.getXpath()));
+ final List<WebElement> types = findElements(By.xpath(XpathSelector.PROPERTY_TYPES.getXpath()));
+
+ for (int i = 0;i < names.size();i++) {
+ namesAndTypes.put(names.get(i).getAttribute("innerText"), types.get(i).getAttribute("innerText"));
+ }
+
+ return namesAndTypes;
}
@AllArgsConstructor
diff --git a/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/pages/ServiceDependenciesEditor.java b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/pages/ServiceDependenciesEditor.java
index cc3e28448c..969854b214 100644
--- a/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/pages/ServiceDependenciesEditor.java
+++ b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/pages/ServiceDependenciesEditor.java
@@ -19,7 +19,11 @@
package org.onap.sdc.frontend.ci.tests.pages;
+import static org.junit.jupiter.api.Assertions.fail;
+
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import java.util.stream.Collectors;
import org.onap.sdc.frontend.ci.tests.datatypes.ServiceDependencyProperty;
@@ -28,6 +32,8 @@ import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;
+import com.fasterxml.jackson.databind.json.JsonMapper;
+
import lombok.AllArgsConstructor;
import lombok.Getter;
@@ -61,16 +67,56 @@ public class ServiceDependenciesEditor extends AbstractPageObject {
logicalOperator.selectByVisibleText(property.getLogicalOperator().getOperator());
final Select sourceType = new Select(webDriver.findElement(By.xpath(XpathSelector.SOURCE_TYPE.xPath)));
sourceType.selectByVisibleText(property.getSource());
- addRuleAssignedValue(webDriver.findElement(
- By.xpath(XpathSelector.RULE_ASSIGNED_VALUE.xPath)), property.getValue());
+ try {
+ addRuleAssignedValue(property);
+ } catch (Exception e) {
+ fail("Failed to add property due to exception while adding rule value :: {}", e);
+ }
webDriver.findElement(By.xpath(XpathSelector.CREATE_BUTTON.xPath)).click();
}
- private void addRuleAssignedValue(final WebElement element, final String value) {
+ private void addRuleAssignedValue(final ServiceDependencyProperty property) throws Exception {
+ final var type = property.getType();
+ final var value = property.getValue();
+ switch (type) {
+ case "list":
+ addListInput(property.getName(), value);
+ break;
+ case "map":
+ addMapInput(property.getName(), value);
+ break;
+ default:
+ addStringInput(waitForElementVisibility(By.xpath(XpathSelector.RULE_ASSIGNED_VALUE.xPath)), value);
+ break;
+ }
+ }
+
+ private void addStringInput(WebElement element, Object value) {
if ("select".equals(element.getTagName())) {
- new Select(element).selectByVisibleText(value);
+ new Select(element).selectByVisibleText(value.toString());
} else {
- element.sendKeys(value);
+ element.sendKeys(value.toString());
+ }
+ }
+
+ private void addListInput(final String name, final String value) throws Exception {
+ final List<?> values = new JsonMapper().readValue(value, List.class);
+ final WebElement addToListElement = waitForElementVisibility(By.xpath(XpathSelector.RULE_ASSIGNED_VALUE_ADD_TO_LIST.formatXpath(name)));
+ for (int i=0;i<values.size();i++) {
+ addToListElement.click();
+ addStringInput(waitForElementVisibility(By.xpath(XpathSelector.RULE_ASSIGNED_LIST_VALUE.formatXpath(name, i))), values.get((i)));
+ }
+ }
+
+ private void addMapInput(final String name, final String value) throws Exception {
+ final Map<?, ?> values = new JsonMapper().readValue(value, Map.class);
+ int i = 0;
+ final WebElement addToListElement = waitForElementVisibility(By.xpath(XpathSelector.RULE_ASSIGNED_VALUE_ADD_TO_LIST.formatXpath(name)));
+ for(Entry<?, ?> entry : values.entrySet()) {
+ addToListElement.click();
+ final List<WebElement> KeyValueInputs = waitForAllElementsVisibility(By.xpath(XpathSelector.RULE_ASSIGNED_MAP_KEY_VALUE.formatXpath(name, i++)));
+ addStringInput(KeyValueInputs.get(0), entry.getKey());
+ addStringInput(KeyValueInputs.get(1), entry.getValue());
}
}
@@ -82,9 +128,15 @@ public class ServiceDependenciesEditor extends AbstractPageObject {
CONSTRAINT_OPERATOR("//*[@data-tests-id='constraintOperator']/select"),
SOURCE_TYPE("//*[@data-tests-id='sourceType']/select"),
RULE_ASSIGNED_VALUE("//*[@data-tests-id='ruleAssignedValue']//*[self::input or self::select]"),
+ RULE_ASSIGNED_VALUE_ADD_TO_LIST("//a[@data-tests-id = 'add-to-list-%s']"),
+ RULE_ASSIGNED_LIST_VALUE("//*[@data-tests-id='value-prop-%s.%d']"),
+ RULE_ASSIGNED_MAP_KEY_VALUE("//*[contains(@data-tests-id, 'value-prop') and contains(@data-tests-id, '%s.%d')]"),
CREATE_BUTTON("//button[text()='Create']");
private final String xPath;
+ public String formatXpath(Object... values) {
+ return String.format(xPath, values);
+ }
}
}