Provide user to specify the ouput name while declaring the atrributes
[sdc.git] / integration-tests / src / test / java / org / onap / sdc / frontend / ci / tests / pages / ServiceCreatePage.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 static org.hamcrest.MatcherAssert.assertThat;
23 import static org.hamcrest.Matchers.equalToIgnoringCase;
24 import static org.hamcrest.core.Is.is;
25
26 import lombok.AllArgsConstructor;
27 import lombok.Getter;
28 import org.onap.sdc.frontend.ci.tests.datatypes.LifeCycleStateEnum;
29 import org.onap.sdc.frontend.ci.tests.datatypes.ServiceCreateData;
30 import org.onap.sdc.frontend.ci.tests.utilities.LoaderHelper;
31 import org.onap.sdc.frontend.ci.tests.utilities.NotificationComponent;
32 import org.onap.sdc.frontend.ci.tests.utilities.NotificationComponent.NotificationType;
33 import org.openqa.selenium.By;
34 import org.openqa.selenium.WebDriver;
35 import org.openqa.selenium.support.ui.Select;
36
37 /**
38  * Represents the Service Create Page
39  */
40 public class ServiceCreatePage extends ComponentPage {
41
42     private final LoaderHelper loaderHelper;
43     private final NotificationComponent notificationComponent;
44     private final ResourceWorkspaceTopBarComponent topBarComponent;
45
46     public ServiceCreatePage(final WebDriver webDriver) {
47         super(webDriver);
48         this.loaderHelper = new LoaderHelper(webDriver);
49         this.notificationComponent = new NotificationComponent(webDriver);
50         this.topBarComponent = new ResourceWorkspaceTopBarComponent(webDriver);
51     }
52
53     @Override
54     public void isLoaded() {
55         topBarComponent.isLoaded();
56         final String lifeCycleState = topBarComponent.getLifecycleState();
57         assertThat("Life cycle state should be as expected",
58             lifeCycleState, is(equalToIgnoringCase(LifeCycleStateEnum.IN_DESIGN.getValue())));
59     }
60
61     /**
62      * Fill the service create form based on the given ServiceCreateData
63      *
64      * @param serviceCreateData the form data
65      */
66     public void fillForm(final ServiceCreateData serviceCreateData) {
67         fillName(serviceCreateData.getName());
68         setModel(serviceCreateData.getModel());
69         setCategory(serviceCreateData.getCategory());
70         setEtsiVersion(serviceCreateData.getEtsiVersion());
71         fillDescription(serviceCreateData.getDescription());
72     }
73
74     private void setEtsiVersion(final String etsiVersion) {
75         if (etsiVersion == null) {
76             return;
77         }
78         final Select categorySelect = new Select(waitForElementVisibility(By.xpath(XpathSelector.ETSI_VERSION_SELECT.getXpath())));
79         categorySelect.selectByVisibleText(etsiVersion);
80     }
81
82     private void setModel(final String model) {
83         if (model == null) {
84             return;
85         }
86         final Select modelSelect = new Select(findElement(By.xpath(XpathSelector.MODEL_SELECT.getXpath())));
87         modelSelect.selectByVisibleText(model);
88     }
89
90     private void setCategory(final String category) {
91         if (category == null) {
92             return;
93         }
94         final Select categorySelect = new Select(findElement(By.xpath(XpathSelector.CATEGORY_SELECT.getXpath())));
95         categorySelect.selectByVisibleText(category);
96     }
97
98     public void fillDescription(final String description) {
99         if (description == null) {
100             return;
101         }
102         findElement(By.xpath(XpathSelector.DESCRIPTION_TEXT_AREA.getXpath()))
103             .sendKeys(description);
104     }
105
106     public void fillName(final String name) {
107         if (name == null) {
108             return;
109         }
110         findElement(By.xpath(XpathSelector.NAME_INPUT.getXpath()))
111             .sendKeys(name);
112     }
113
114     public void clickOnCreate() {
115         topBarComponent.clickOnCreate();
116         loaderHelper.waitForLoader(20);
117         notificationComponent.waitForNotification(NotificationType.SUCCESS, 20);
118     }
119
120     /**
121      * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
122      */
123     @AllArgsConstructor
124     private enum XpathSelector {
125         NAME_INPUT("name", "//input[@data-tests-id='%s']"),
126         MODEL_SELECT("selectModelName", "//select[@data-tests-id='%s']"),
127         CATEGORY_SELECT("selectGeneralCategory", "//select[@data-tests-id='%s']"),
128         ETSI_VERSION_SELECT("ETSI Version", "//select[@data-tests-id='%s']"),
129         DESCRIPTION_TEXT_AREA("description", "//textarea[@data-tests-id='%s']");
130
131         @Getter
132         private final String id;
133         private final String xpathFormat;
134
135         public String getXpath() {
136             return String.format(xpathFormat, id);
137         }
138     }
139 }