Support complex types in interface operation inputs
[sdc.git] / integration-tests / src / test / java / org / onap / sdc / frontend / ci / tests / pages / component / workspace / InterfaceDefinitionOperationsModal.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.component.workspace;
21
22 import com.aventstack.extentreports.Status;
23 import java.time.Duration;
24 import java.util.List;
25 import lombok.AllArgsConstructor;
26 import lombok.Getter;
27 import org.onap.sdc.frontend.ci.tests.execute.setup.ExtentTestActions;
28 import org.onap.sdc.frontend.ci.tests.pages.AbstractPageObject;
29 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.InterfaceDefinitionOperationsModal.InterfaceOperationsData.InputData;
30 import org.openqa.selenium.By;
31 import org.openqa.selenium.WebDriver;
32 import org.openqa.selenium.WebElement;
33 import org.openqa.selenium.interactions.Actions;
34
35 /**
36  * Represents the Composition Interface Operations Modal.
37  */
38 public class InterfaceDefinitionOperationsModal extends AbstractPageObject {
39
40     private InterfaceOperationInputListComponent inputListComponent;
41     private InterfaceOperationAddInputComponent addInputComponent;
42
43     public InterfaceDefinitionOperationsModal(final WebDriver webDriver) {
44         super(webDriver);
45     }
46
47     @Override
48     public void isLoaded() {
49         isLoaded(false);
50     }
51
52     public void isLoaded(boolean isInViewMode) {
53         waitForElementVisibility(By.xpath(XpathSelector.TITLE_SPAN.getXPath()));
54         waitForElementVisibility(By.xpath(XpathSelector.INTERFACE_NAME_LABEL.getXPath()));
55         waitForElementVisibility(By.xpath(XpathSelector.OPERATION_NAME_LABEL.getXPath()));
56         waitForElementVisibility(By.xpath(XpathSelector.SAVE_BTN.getXPath()));
57         waitToBeClickable(By.xpath(XpathSelector.CANCEL_BTN.getXPath()));
58         this.inputListComponent = new InterfaceOperationInputListComponent(webDriver);
59         this.inputListComponent.isLoaded();
60         if (!isInViewMode) {
61             this.addInputComponent = new InterfaceOperationAddInputComponent(webDriver);
62             this.addInputComponent.isLoaded();
63         }
64     }
65
66     private void clickOnSave() {
67         waitToBeClickable(By.xpath(XpathSelector.SAVE_BTN.getXPath())).click();
68     }
69
70     public void clickOnCancel() {
71         waitToBeClickable(By.xpath(XpathSelector.CANCEL_BTN.getXPath())).click();
72     }
73
74     public void clickOnDelete() {
75         waitToBeClickable(By.xpath(XpathSelector.DELETE_BTN.getXPath())).click();
76     }
77
78     public void deleteInput(String inputName) {
79         inputListComponent.loadInputList();
80         inputListComponent.deleteInput(inputName);
81     }
82
83     public void updateInterfaceOperation(final InterfaceOperationsData interfaceOperationsData) {
84         fillDescription(interfaceOperationsData.getDescription());
85         fillImplementationName(interfaceOperationsData.getImplementationName());
86         interfaceOperationsData.getInputList().forEach(inputData -> {
87             final InterfaceOperationAddInputComponent addInputComponent = new InterfaceOperationAddInputComponent(webDriver);
88             addInputComponent.isLoaded();
89             addInputComponent.clickOnAddInputLink();
90             addInputComponent.fillInput(inputData);
91             addInputComponent.clickOnAddButton();
92             ExtentTestActions.takeScreenshot(Status.INFO,
93                 "compositionInterfaceOperationsModal.addInput." + inputData.getName(),
94                 String.format("Input '%s' added", inputData.getName())
95             );
96             addInputComponent.fillValue(inputData);
97         });
98         clickOnSave();
99         //there is no feedback from the UI to check if the update was successful. Forcing a wait time trying to guarantee that,
100         // although time is never a guarantee in this case.
101         new Actions(webDriver).pause(Duration.ofSeconds(5)).perform();
102     }
103
104     private void fillDescription(final String description) {
105         setInputField(By.xpath(XpathSelector.INTERFACE_OPERATION_DESCRIPTION_INPUT.getXPath()), description);
106     }
107
108     private void fillImplementationName(final String implementationName) {
109         setInputField(By.xpath(XpathSelector.INTERFACE_OPERATION_IMPLEMENTATION_NAME_INPUT.getXPath()), implementationName);
110     }
111
112     private void setInputField(final By locator, final String value) {
113         if (value == null) {
114             return;
115         }
116         final WebElement webElement = findElement(locator);
117         webElement.clear();
118         webElement.sendKeys(value);
119
120         ExtentTestActions.takeScreenshot(Status.INFO, value, value);
121     }
122
123     public void clickOnAddInput() {
124         addInputComponent.clickOnAddInputLink();
125     }
126
127     public String getDescription() {
128         return findElement(By.xpath(XpathSelector.INTERFACE_OPERATION_DESCRIPTION_INPUT.getXPath())).getAttribute("value");
129     }
130
131     public String getImplementationName() {
132         return findElement(By.xpath(XpathSelector.INTERFACE_OPERATION_IMPLEMENTATION_NAME_INPUT.getXPath())).getAttribute("value");
133     }
134
135     public List<InputData> getInputs() {
136         inputListComponent.loadInputList();
137         return inputListComponent.getInputList();
138     }
139
140     @AllArgsConstructor
141     private enum XpathSelector {
142         TITLE_SPAN("//span[@class='title' and contains(text(), 'Edit Operation')]"),
143         DELETE_BTN("//svg-icon[@name='trash-o']"),
144         SAVE_BTN("//button[@data-tests-id='Save']"),
145         CANCEL_BTN("//button[@data-tests-id='Cancel']"),
146         INTERFACE_NAME_LABEL("//label[contains(@class,'sdc-input') and contains(text(), 'Interface Name')]"),
147         OPERATION_NAME_LABEL("//label[contains(@class,'sdc-input') and contains(text(), 'Operation Name')]"),
148         INTERFACE_OPERATION_DESCRIPTION_INPUT("//input[@data-tests-id='interface-operation-description']"),
149         INTERFACE_OPERATION_IMPLEMENTATION_NAME_INPUT("//input[@data-tests-id='interface-operation-implementation-name']");
150
151         private final String xPath;
152
153         public String getXPath(final String... xpathParams) {
154             return String.format(xPath, xpathParams);
155         }
156     }
157
158     @Getter
159     @AllArgsConstructor
160     public static class InterfaceOperationsData {
161
162         private final String description;
163         private final String implementationName;
164         private final List<InputData> inputList;
165
166         @Getter
167         @AllArgsConstructor
168         public static class InputData {
169
170             private final String name;
171             private final String type;
172             private final Object value;
173         }
174     }
175 }