diff options
author | davsad <david.sadlier@est.tech> | 2021-03-09 18:29:48 +0000 |
---|---|---|
committer | Christophe Closset <christophe.closset@intl.att.com> | 2021-04-06 09:09:21 +0000 |
commit | 565444adc4ddac4530eccb489a18f4b74e888ea3 (patch) | |
tree | c38efa6b2db54d60f58eea126b8204488d2a5cd9 /integration-tests/src/test/java/org | |
parent | 0a1f233687c98d6574494681e123d44cc49596a5 (diff) |
Add Create Service Substituition Filter Intergration Test
Issue-ID: SDC-3543
Signed-off-by: davsad <david.sadlier@est.tech>
Change-Id: Id6aabc02e36f199ee9106ec1fb145b57c8493c88
Diffstat (limited to 'integration-tests/src/test/java/org')
9 files changed, 486 insertions, 8 deletions
diff --git a/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/datatypes/LogicalOperator.java b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/datatypes/LogicalOperator.java new file mode 100644 index 0000000000..5a4cfce427 --- /dev/null +++ b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/datatypes/LogicalOperator.java @@ -0,0 +1,15 @@ +package org.onap.sdc.frontend.ci.tests.datatypes; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor +@Getter +public enum LogicalOperator { + EQUALS("equal","="), + GREATER_THAN("greater_than",">"), + LESS_THAN("less_than","<"); + + private final String name; + private final String operator; +} 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 new file mode 100644 index 0000000000..6afbdc244a --- /dev/null +++ b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/datatypes/ServiceDependencyProperty.java @@ -0,0 +1,43 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.sdc.frontend.ci.tests.datatypes; + +import org.onap.sdc.frontend.ci.tests.pages.ServiceDependenciesEditor; + +import lombok.Data; + +/** + * Represents the a property within the Service Dependencies Editor + * @see ServiceDependenciesEditor + */ +@Data +public class ServiceDependencyProperty { + private final String name; + private final String value; + private final String source; + private final LogicalOperator logicalOperator; + + public ServiceDependencyProperty(String name, String value, LogicalOperator logicalOperator) { + this.name = name; + this.value = value; + this.source = "Static"; + this.logicalOperator = logicalOperator; + } +} diff --git a/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/execute/sanity/CreateServiceSubstitutionFilterTest.java b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/execute/sanity/CreateServiceSubstitutionFilterTest.java new file mode 100644 index 0000000000..c49c2dc447 --- /dev/null +++ b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/execute/sanity/CreateServiceSubstitutionFilterTest.java @@ -0,0 +1,138 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.sdc.frontend.ci.tests.execute.sanity; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.onap.sdc.backend.ci.tests.datatypes.enums.ServiceInstantiationType; +import org.onap.sdc.frontend.ci.tests.datatypes.LogicalOperator; +import org.onap.sdc.frontend.ci.tests.datatypes.ServiceCreateData; +import org.onap.sdc.frontend.ci.tests.datatypes.ServiceDependencyProperty; +import org.onap.sdc.frontend.ci.tests.execute.setup.DriverFactory; +import org.onap.sdc.frontend.ci.tests.execute.setup.SetupCDTest; +import org.onap.sdc.frontend.ci.tests.flow.CreateServiceFlow; +import org.onap.sdc.frontend.ci.tests.flow.CreateSubtitutionFilterFlow; +import org.onap.sdc.frontend.ci.tests.flow.DownloadToscaTemplateFlow; +import org.onap.sdc.frontend.ci.tests.pages.ResourcePropertiesAssignmentPage; +import org.onap.sdc.frontend.ci.tests.pages.ServiceComponentPage; +import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionPage; +import org.onap.sdc.frontend.ci.tests.pages.component.workspace.ToscaArtifactsPage; +import org.onap.sdc.frontend.ci.tests.pages.home.HomePage; +import org.onap.sdc.frontend.ci.tests.utilities.FileHandling; +import org.openqa.selenium.WebDriver; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class CreateServiceSubstitutionFilterTest extends SetupCDTest { + private final String serviceName = "CreateServiceSubstitutionFilterTest"; + private final String stringValue = "Test"; + private final String booleanValue = "TRUE"; + private final LogicalOperator operator = LogicalOperator.EQUALS; + private final List<ServiceDependencyProperty> substitutionFilterProperties = new ArrayList<ServiceDependencyProperty>(); + private final ServiceCreateData serviceCreateData = loadServiceCreateData(); + + private WebDriver webDriver; + + @BeforeClass + public void classSetup() { + webDriver = DriverFactory.getDriver(); + } + + @Test + public void createSubsitutionFilter() throws Exception { + new CreateServiceFlow(webDriver, serviceCreateData).run(new HomePage(webDriver)); + + ServiceComponentPage serviceComponentPage = new ServiceComponentPage(webDriver); + serviceComponentPage.isLoaded(); + + loadSubstitutionFilterProperties(serviceComponentPage); + final CompositionPage compositionPage = serviceComponentPage.goToComposition(); + + substitutionFilterProperties.forEach(substitutionFilterProperty -> { + final CreateSubtitutionFilterFlow createSubtitutionFilterFlow = new CreateSubtitutionFilterFlow(webDriver, substitutionFilterProperty); + createSubtitutionFilterFlow.run(); + }); + + serviceComponentPage = compositionPage.goToServiceGeneral(); + serviceComponentPage.isLoaded(); + + verifyToscaTemplateYaml(serviceComponentPage, false); + } + + private ServiceCreateData loadServiceCreateData() { + ServiceCreateData serviceCreateData = new ServiceCreateData(); + serviceCreateData.setRandomName(serviceName); + serviceCreateData.setDescription(serviceName); + serviceCreateData.setCategory("Network Service"); + serviceCreateData.setInstantiationType(ServiceInstantiationType.A_LA_CARTE); + return serviceCreateData; + } + + private void loadSubstitutionFilterProperties(final ServiceComponentPage serviceComponentPage) { + final ResourcePropertiesAssignmentPage propertiesPage = serviceComponentPage.goToPropertiesAssignment(); + propertiesPage.isLoaded(); + final Map<String, String> propertyNamesAndTypes = propertiesPage.getPropertyNamesAndTypes(); + propertyNamesAndTypes.forEach((name, type) + -> substitutionFilterProperties.add(new ServiceDependencyProperty(name, getPropertyValueByType(type), operator))); + } + + private void verifyToscaTemplateYaml(final ServiceComponentPage serviceComponentPage, final boolean delete) throws Exception { + final DownloadToscaTemplateFlow downloadCsarTemplateFlow = new DownloadToscaTemplateFlow(webDriver); + final ToscaArtifactsPage toscaArtifactsPage = (ToscaArtifactsPage) downloadCsarTemplateFlow.run(serviceComponentPage).get(); + final Map<?, ?> yaml = FileHandling.parseYamlFile(getConfig().getDownloadAutomationFolder() + .concat(java.io.File.separator).concat(toscaArtifactsPage.getDownloadedArtifactList().get(0))); + verifyToscaTemplateHasSubstitutionFilter(yaml); + } + + private void verifyToscaTemplateHasSubstitutionFilter(final Map<?, ?> yaml) { + assertNotNull(yaml, "No contents in TOSCA Template"); + final List<?> substitutionFilters = (List<?>) getSubstitutionFilterFromYaml(yaml).get("properties"); + substitutionFilterProperties.forEach(substitutionFilterProperty -> { + final Map<?, ?> substitutionFilter = (Map<?, ?>) substitutionFilters.stream() + .filter(subFilter -> ((Map<?, ?>) subFilter).containsKey(substitutionFilterProperty.getName())).findAny().get(); + assertTrue(substitutionFilter.containsKey(substitutionFilterProperty.getName()), "Added substitution filter not found in TOSCA Template"); + + final Map<?, ?> substitutionFilterValue = (Map<?, ?>) ((List<?>) substitutionFilter.get(substitutionFilterProperty.getName())).get(0); + assertTrue(substitutionFilterValue.containsValue(convertValue(substitutionFilterProperty.getValue())) + , "Invalid value for added substitution filters found in TOSCA Template"); + assertTrue(substitutionFilterValue.containsKey(substitutionFilterProperty.getLogicalOperator().getName()) + , "Invalid logical operator for added substitution filters found in TOSCA Template"); + }); + } + + private Map<?,?> getSubstitutionFilterFromYaml(final Map<?,?> yaml) { + final Map<?, ?> topology = (Map<?, ?>) yaml.get("topology_template"); + final Map<?, ?> substitutionMappings = (Map<?, ?>) topology.get("substitution_mappings"); + return (Map<?, ?>) substitutionMappings.get("substitution_filter"); + } + + private Object convertValue(String value) { + return booleanValue.equals(value) ? Boolean.parseBoolean(value) : value; + } + + private String getPropertyValueByType(String type) { + return "string".equals(type) ? stringValue : booleanValue; + } +} diff --git a/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/flow/CreateSubtitutionFilterFlow.java b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/flow/CreateSubtitutionFilterFlow.java new file mode 100644 index 0000000000..c293d1cc5f --- /dev/null +++ b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/flow/CreateSubtitutionFilterFlow.java @@ -0,0 +1,81 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.sdc.frontend.ci.tests.flow; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.Optional; + +import org.onap.sdc.frontend.ci.tests.datatypes.ServiceDependencyProperty; +import org.onap.sdc.frontend.ci.tests.pages.PageObject; +import org.onap.sdc.frontend.ci.tests.pages.ServiceDependenciesEditor; +import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionDetailSideBarComponent; +import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionDetailSideBarComponent.CompositionDetailTabName; +import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionPage; +import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionSubstitutionFilterTab; +import org.openqa.selenium.WebDriver; + +import com.aventstack.extentreports.Status; + +public class CreateSubtitutionFilterFlow extends AbstractUiTestFlow { + + private CompositionPage compositionPage; + private final ServiceDependencyProperty substitutionFilterProperty; + + public CreateSubtitutionFilterFlow(final WebDriver webDriver, final ServiceDependencyProperty substitutionFilterProperty) { + super(webDriver); + this.substitutionFilterProperty = substitutionFilterProperty; + } + + @Override + public Optional<PageObject> run(final PageObject... pageObjects) { + extendTest.log(Status.INFO, "Creating substitution filter"); + + compositionPage = getCompositionPage(pageObjects); + compositionPage.isLoaded(); + + final CompositionDetailSideBarComponent sideBar = compositionPage.getDetailSideBar(); + sideBar.isLoaded(); + + final CompositionSubstitutionFilterTab compositionSubstitutionFilterTab = (CompositionSubstitutionFilterTab) sideBar.selectTab(CompositionDetailTabName.SUBSTITUTION_FILTER); + compositionSubstitutionFilterTab.isLoaded(); + + final ServiceDependenciesEditor compositionSubstitutionDependenciesEditor = compositionSubstitutionFilterTab.clickAddSubstitutionFilter(); + compositionSubstitutionDependenciesEditor.isLoaded(); + compositionSubstitutionDependenciesEditor.addProperty(substitutionFilterProperty); + + compositionSubstitutionFilterTab.isLoaded(); + assertTrue(compositionSubstitutionFilterTab.isSubstitutionFilterPresent(substitutionFilterProperty.getName()), "Created substitution filter is not present"); + + return Optional.of(compositionPage); + } + + @Override + public Optional<? extends PageObject> getLandedPage() { + return Optional.ofNullable(compositionPage); + } + + private CompositionPage getCompositionPage(final PageObject... pageObjects) { + return getParameter(pageObjects, CompositionPage.class) + .orElseGet(() -> { + return new CompositionPage(webDriver); + }); + } +} diff --git a/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/flow/DownloadToscaTemplateFlow.java b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/flow/DownloadToscaTemplateFlow.java new file mode 100644 index 0000000000..1ad470600f --- /dev/null +++ b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/flow/DownloadToscaTemplateFlow.java @@ -0,0 +1,80 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.sdc.frontend.ci.tests.flow; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; + +import java.io.File; +import java.time.Duration; +import java.util.Optional; + +import org.onap.sdc.frontend.ci.tests.execute.setup.ExtentTestActions; +import org.onap.sdc.frontend.ci.tests.pages.ComponentPage; +import org.onap.sdc.frontend.ci.tests.pages.PageObject; +import org.onap.sdc.frontend.ci.tests.pages.component.workspace.ToscaArtifactsPage; +import org.onap.sdc.frontend.ci.tests.utilities.FileHandling; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.support.ui.FluentWait; + +import com.aventstack.extentreports.Status; + +import lombok.Setter; + +public class DownloadToscaTemplateFlow extends AbstractUiTestFlow { + + private ToscaArtifactsPage toscaArtifactsPage; + @Setter + private long waitBeforeGetTheFile = 0L; + + public DownloadToscaTemplateFlow(final WebDriver webDriver) { + super(webDriver); + } + + @Override + public Optional<PageObject> run(final PageObject... pageObjects) { + final ComponentPage componentPage = findParameter(pageObjects, ComponentPage.class); + toscaArtifactsPage = (ToscaArtifactsPage) componentPage.goToToscaArtifacts(); + toscaArtifactsPage.isLoaded(); + + toscaArtifactsPage.clickOnDownload("Tosca Template"); + final File downloadedTemplate = waitAndGetDowloadedTemplate(); + assertThat("The downloaded Template exists", downloadedTemplate, is(notNullValue())); + assertThat("The downloaded Template exists", downloadedTemplate.exists(), is(true)); + toscaArtifactsPage.addToDownloadedArtifactList(downloadedTemplate.getName()); + ExtentTestActions.takeScreenshot(Status.INFO, "tosca-template-download", "TOSCA template downloaded"); + + return Optional.of(toscaArtifactsPage); + } + + @Override + public Optional<ToscaArtifactsPage> getLandedPage() { + return Optional.ofNullable(toscaArtifactsPage); + } + + private File waitAndGetDowloadedTemplate() { + new Actions(webDriver).pause(Duration.ofSeconds(waitBeforeGetTheFile)).perform(); + final FluentWait<String> fluentWait = new FluentWait<>("").withTimeout(Duration.ofSeconds(5)).pollingEvery(Duration.ofSeconds(1)); + fluentWait.until(s -> FileHandling.getLastModifiedFileNameFromDir() != null); + return FileHandling.getLastModifiedFileNameFromDir(); + } +} diff --git a/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/pages/ResourcePropertiesAssignmentPage.java b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/pages/ResourcePropertiesAssignmentPage.java index 9cb104d67e..0b38c9d2ad 100644 --- a/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/pages/ResourcePropertiesAssignmentPage.java +++ b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/pages/ResourcePropertiesAssignmentPage.java @@ -22,9 +22,10 @@ package org.onap.sdc.frontend.ci.tests.pages; import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; -import lombok.AllArgsConstructor; -import lombok.Getter; +import java.util.Map; + import org.onap.sdc.frontend.ci.tests.utilities.LoaderHelper; import org.onap.sdc.frontend.ci.tests.utilities.NotificationComponent; import org.onap.sdc.frontend.ci.tests.utilities.NotificationComponent.NotificationType; @@ -33,6 +34,9 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.ExpectedConditions; +import lombok.AllArgsConstructor; +import lombok.Getter; + /** * Handles the Resource Properties Assignment Page UI actions */ @@ -159,6 +163,22 @@ public class ResourcePropertiesAssignmentPage extends AbstractPageObject { } /** + * Creates a map based on property names and data types + */ + public Map<String, String> getPropertyNamesAndTypes() { + waitPropertiesToLoad(); + final Map<String, String> namesAndTypes = new HashMap<String, String>(); + 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; + } + + /** * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object. */ @AllArgsConstructor @@ -171,7 +191,9 @@ public class ResourcePropertiesAssignmentPage extends AbstractPageObject { SOFTWARE_VERSION_INPUT("value-prop-software_versions", "//input[starts-with(@data-tests-id,'%s')]"), PROPERTY_CHECKBOX("//checkbox[@data-tests-id='%s']"), PROPERTY_SAVE_BTN("properties-save-button", "//button[@data-tests-id='%s']"), - INPUT_PROPERTY("//input[@data-tests-id='value-prop-%s']"); + INPUT_PROPERTY("//input[@data-tests-id='value-prop-%s']"), + PROPERTY_TYPES("//*[contains(@data-tests-id, 'propertyType')]"), + PROPERTY_NAMES("//*[contains(@data-tests-id, 'propertyName')]"); @Getter private String id; 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 new file mode 100644 index 0000000000..d1ec6d0cdf --- /dev/null +++ b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/pages/ServiceDependenciesEditor.java @@ -0,0 +1,78 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.sdc.frontend.ci.tests.pages; + +import org.onap.sdc.frontend.ci.tests.datatypes.ServiceDependencyProperty; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.Select; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * Represents the Service Dependencies Editor + */ +public class ServiceDependenciesEditor extends AbstractPageObject { + + public ServiceDependenciesEditor(final WebDriver webDriver) { + super(webDriver); + } + + @Override + public void isLoaded() { + waitForElementVisibility(By.xpath(XpathSelector.SERVICE_DEPENDENCIES_EDITOR.xPath)); + } + + public void addProperty(final ServiceDependencyProperty property) { + final Select properties = new Select(webDriver.findElement(By.xpath(XpathSelector.SERVICE_PROPERTY_NAME.xPath))); + properties.selectByVisibleText(property.getName()); + final Select logicalOperator = new Select(webDriver.findElement(By.xpath(XpathSelector.CONSTRAINT_OPERATOR.xPath))); + 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()); + webDriver.findElement(By.xpath(XpathSelector.CREATE_BUTTON.xPath)).click(); + } + + private void addRuleAssignedValue(final WebElement element, final String value) { + if ("select".equals(element.getTagName())) { + new Select(element).selectByVisibleText(value); + } else { + element.sendKeys(value); + } + } + + @AllArgsConstructor + @Getter + private enum XpathSelector { + SERVICE_DEPENDENCIES_EDITOR("//service-dependencies-editor"), + SERVICE_PROPERTY_NAME("//*[@data-tests-id='servicePropertyName']/select"), + 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]"), + CREATE_BUTTON("//button[text()='Create']"); + + private final String xPath; + + } +} diff --git a/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/pages/component/workspace/CompositionPage.java b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/pages/component/workspace/CompositionPage.java index 19a21503e5..fb07aec13c 100644 --- a/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/pages/component/workspace/CompositionPage.java +++ b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/pages/component/workspace/CompositionPage.java @@ -81,6 +81,11 @@ public class CompositionPage extends AbstractPageObject { return new ResourceCreatePage(webDriver); } + public ServiceComponentPage goToServiceGeneral() { + topNavComponent.clickOnBreadCrumb(1); + return new ServiceComponentPage(webDriver); + } + /** * Get the composition page detail sidebar component * diff --git a/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/pages/component/workspace/CompositionSubstitutionFilterTab.java b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/pages/component/workspace/CompositionSubstitutionFilterTab.java index d279e1f07d..f0b6b7152b 100644 --- a/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/pages/component/workspace/CompositionSubstitutionFilterTab.java +++ b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/pages/component/workspace/CompositionSubstitutionFilterTab.java @@ -19,12 +19,14 @@ package org.onap.sdc.frontend.ci.tests.pages.component.workspace; -import lombok.AllArgsConstructor; -import lombok.Getter; import org.onap.sdc.frontend.ci.tests.pages.AbstractPageObject; +import org.onap.sdc.frontend.ci.tests.pages.ServiceDependenciesEditor; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; +import lombok.AllArgsConstructor; +import lombok.Getter; + /** * Represents the composition page, details panel, Substitution Filters tab */ @@ -36,15 +38,29 @@ public class CompositionSubstitutionFilterTab extends AbstractPageObject { @Override public void isLoaded() { - waitForElementVisibility(By.xpath(XpathSelector.SUBSTITUTION_FILTER_TAB.getXPath())); - waitForElementVisibility(By.xpath(XpathSelector.ADD_SUBSTITUTION_FILTER_BTN.getXPath())); + waitForElementVisibility(By.xpath(XpathSelector.SUBSTITUTION_FILTER_TAB.xPath)); + waitForElementVisibility(By.xpath(XpathSelector.SUBSTITUTION_FILTER_ADD_BTN.xPath)); + } + + public ServiceDependenciesEditor clickAddSubstitutionFilter() { + findElement(By.xpath(XpathSelector.SUBSTITUTION_FILTER_ADD_BTN.xPath)).click(); + return new ServiceDependenciesEditor(webDriver); + } + + public boolean isSubstitutionFilterPresent(final String propertyName) { + try { + return waitForElementVisibility(By.xpath(String.format(XpathSelector.SUBSTITUTION_FILTER_DESC.xPath, propertyName))) != null; + } catch (final Exception ignored) { + return false; + } } @AllArgsConstructor @Getter private enum XpathSelector { SUBSTITUTION_FILTER_TAB("//substitution-filter-tab"), - ADD_SUBSTITUTION_FILTER_BTN("//button[@data-tests-id='add-substitution-filter-button']"); + SUBSTITUTION_FILTER_ADD_BTN("//button[@data-tests-id='add-substitution-filter-button']"), + SUBSTITUTION_FILTER_DESC("//*[@class='rule-desc' and contains(text(),'%s')]"); private final String xPath; |