Provide input name when declaring service property as input
[sdc.git] / integration-tests / src / test / java / org / onap / sdc / frontend / ci / tests / pages / ResourcePropertiesAssignmentPage.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 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 com.aventstack.extentreports.Status;
23 import java.util.List;
24 import java.util.Map;
25 import lombok.AllArgsConstructor;
26 import lombok.Getter;
27 import org.onap.sdc.frontend.ci.tests.execute.setup.ExtentTestActions;
28 import org.openqa.selenium.By;
29 import org.openqa.selenium.WebDriver;
30
31 /**
32  * Handles the Resource Properties Assignment Page UI actions.
33  */
34 public class ResourcePropertiesAssignmentPage extends ComponentPage {
35
36     private ResourcePropertiesAssignmentTab resourcePropertiesAssignmentTab;
37     private ResourcePropertiesAssignmentInputTab resourcePropertiesAssignmentInputTab;
38
39     public ResourcePropertiesAssignmentPage(final WebDriver webDriver) {
40         super(webDriver);
41         resourcePropertiesAssignmentTab = new ResourcePropertiesAssignmentTab(webDriver);
42         resourcePropertiesAssignmentInputTab = new ResourcePropertiesAssignmentInputTab(webDriver);
43     }
44
45     @Override
46     public void isLoaded() {
47         super.isLoaded();
48         waitForElementVisibility((By.xpath(XpathSelector.MAIN_DIV.getXpath())));
49         waitForElementVisibility(By.xpath(XpathSelector.TITLE_DIV.getXpath()));
50         resourcePropertiesAssignmentTab.isLoaded();
51     }
52
53     /**
54      * Select the Properties Tab to be displayed
55      */
56     public void selectPropertiesTab() {
57         findElement(By.xpath(XpathSelector.PROPERTIES_TAB.getXpath())).click();
58         resourcePropertiesAssignmentTab.isLoaded();
59     }
60
61     /**
62      * Select the Input Tab to be displayed
63      */
64     public void selectInputTab() {
65         findElement(By.xpath(XpathSelector.INPUT_TAB.getXpath())).click();
66         resourcePropertiesAssignmentInputTab.isLoaded();
67     }
68
69     public List<String> getSoftwareVersionProperty() {
70         return resourcePropertiesAssignmentTab.getSoftwareVersionProperty();
71     }
72
73     public void setPropertyValue(final String propertyName, final Object value) {
74         resourcePropertiesAssignmentTab.setPropertyValue(propertyName, value);
75     }
76
77     /**
78      * Retrieves a property value.
79      *
80      * @param propertyName the property name
81      * @return the property value
82      */
83     public Object getPropertyValue(final String propertyName) {
84         return resourcePropertiesAssignmentTab.getPropertyValue(propertyName);
85     }
86
87     public boolean isPropertyPresent(final String propertyName) {
88         return resourcePropertiesAssignmentTab.isPropertyPresent(propertyName);
89     }
90
91     public boolean isInputPresent(final String inputName) {
92         return resourcePropertiesAssignmentInputTab.isInputPresent(inputName);
93     }
94
95     /**
96      * Saves a property
97      */
98     public void saveProperties() {
99         resourcePropertiesAssignmentTab.saveProperties();
100     }
101
102     public void saveInputs() {
103         resourcePropertiesAssignmentInputTab.saveInputProperties();
104     }
105
106     public void addProperties(final Map<String, String> propertiesMap) {
107         resourcePropertiesAssignmentTab.addProperties(propertiesMap);
108     }
109
110     public void addInputs(final Map<String, String> inputsMap) {
111         resourcePropertiesAssignmentInputTab.addInputs(inputsMap);
112     }
113
114     public void verifyInputs(final Map<String, String> inputsMap) {
115         resourcePropertiesAssignmentInputTab.verifyInputs(inputsMap);
116     }
117
118     public Map<String, String> getPropertyNamesAndTypes() {
119         return resourcePropertiesAssignmentTab.getPropertyNamesAndTypes();
120     }
121
122     public void setInputPropertyMetadata(String name, String key, String value) {
123         resourcePropertiesAssignmentInputTab.setInputPropertyMetadata(name, key, value);
124     }
125
126     public List<String> getInputPropertyNames() {
127         return resourcePropertiesAssignmentInputTab.getInputPropertyNames();
128     }
129
130     /**
131      * select property
132      */
133     public void selectProperty(String propertyName){
134         resourcePropertiesAssignmentTab.selectProperty(propertyName);
135     }
136
137     public void loadComponentInstanceProperties(final String instanceName){
138         resourcePropertiesAssignmentTab.loadComponentInstanceProperties(instanceName);
139     }
140
141     public void clickOnDeclareInput(final String inputName){
142         resourcePropertiesAssignmentTab.clickOnDeclareInput(inputName);
143     }
144
145     public void loadCompositionTab(){
146         resourcePropertiesAssignmentTab.loadCompositionTab();
147     }
148
149     public void clickInputTab(String propertyName){
150         waitForElementVisibility(By.xpath(XpathSelector.DECLARE_NOTIFIFICATION.getXpath()));
151         ExtentTestActions.takeScreenshot(Status.INFO, "Declare-Input", String.format("Added declared input for property %s", propertyName));
152         selectInputTab();
153     }
154
155     /**
156      * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
157      */
158     @AllArgsConstructor
159     private enum XpathSelector {
160         MAIN_DIV("w-sdc-main-right-container", "//div[@class='%s']"),
161         TITLE_DIV("tab-title", "//div[contains(@class,'%s') and contains(text(), 'Properties Assignment')]"),
162         PROPERTIES_TAB("//*[contains(@data-tests-id, 'Properties') and contains(@class, 'tab')]"),
163         INPUT_TAB("//*[contains(@data-tests-id, 'Inputs') and contains(@class, 'tab')]"),
164         DECLARE_NOTIFIFICATION("//div[@data-tests-id='Inputs']/div[contains(@class, 'tab-indication')]");
165
166         @Getter
167         private String id;
168         private final String xpathFormat;
169
170         XpathSelector(final String xpathFormat) {
171             this.xpathFormat = xpathFormat;
172         }
173
174         public String getXpath() {
175             return String.format(xpathFormat, id);
176         }
177     }
178
179 }