Add integration test for adding directive node filters to a base service
[sdc.git] / integration-tests / src / test / java / org / onap / sdc / frontend / ci / tests / pages / ServiceDependenciesEditor.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 Nordix Foundation
4  *  ================================================================================
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19
20 package org.onap.sdc.frontend.ci.tests.pages;
21
22 import java.util.List;
23 import java.util.stream.Collectors;
24
25 import org.onap.sdc.frontend.ci.tests.datatypes.ServiceDependencyProperty;
26 import org.openqa.selenium.By;
27 import org.openqa.selenium.WebDriver;
28 import org.openqa.selenium.WebElement;
29 import org.openqa.selenium.support.ui.Select;
30
31 import lombok.AllArgsConstructor;
32 import lombok.Getter;
33
34 /**
35  * Represents the Service Dependencies Editor
36  */
37 public class ServiceDependenciesEditor extends AbstractPageObject {
38
39     public ServiceDependenciesEditor(final WebDriver webDriver) {
40         super(webDriver);
41     }
42
43     @Override
44     public void isLoaded() {
45         waitForElementVisibility(By.xpath(XpathSelector.SERVICE_DEPENDENCIES_EDITOR.xPath));
46     }
47     /**
48      * Returns a list of strings based on the property UI Select
49      * @return List of property names which can be selected
50      */
51     public List<String> getPropertySelectOptions() {
52         return new Select(webDriver.findElement(By.xpath(XpathSelector.SERVICE_PROPERTY_NAME.xPath)))
53                 .getOptions().stream()
54                 .map(option -> option.getAttribute("innerText")).collect(Collectors.toList());
55     }
56
57     public void addProperty(final ServiceDependencyProperty property) {
58         final Select properties = new Select(webDriver.findElement(By.xpath(XpathSelector.SERVICE_PROPERTY_NAME.xPath)));
59         properties.selectByVisibleText(property.getName());
60         final Select logicalOperator = new Select(webDriver.findElement(By.xpath(XpathSelector.CONSTRAINT_OPERATOR.xPath)));
61         logicalOperator.selectByVisibleText(property.getLogicalOperator().getOperator());
62         final Select sourceType = new Select(webDriver.findElement(By.xpath(XpathSelector.SOURCE_TYPE.xPath)));
63         sourceType.selectByVisibleText(property.getSource());
64         addRuleAssignedValue(webDriver.findElement(
65                 By.xpath(XpathSelector.RULE_ASSIGNED_VALUE.xPath)), property.getValue());
66         webDriver.findElement(By.xpath(XpathSelector.CREATE_BUTTON.xPath)).click();
67     }
68
69     private void addRuleAssignedValue(final WebElement element, final String value) {
70         if ("select".equals(element.getTagName())) {
71             new Select(element).selectByVisibleText(value);
72         } else {
73             element.sendKeys(value);
74         }
75     }
76
77     @AllArgsConstructor
78     @Getter
79     private enum XpathSelector {
80         SERVICE_DEPENDENCIES_EDITOR("//service-dependencies-editor"),
81         SERVICE_PROPERTY_NAME("//*[@data-tests-id='servicePropertyName']/select"),
82         CONSTRAINT_OPERATOR("//*[@data-tests-id='constraintOperator']/select"),
83         SOURCE_TYPE("//*[@data-tests-id='sourceType']/select"),
84         RULE_ASSIGNED_VALUE("//*[@data-tests-id='ruleAssignedValue']//*[self::input or self::select]"),
85         CREATE_BUTTON("//button[text()='Create']");
86
87         private final String xPath;
88
89     }
90 }