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 / ServiceGeneralPage.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.sdc.frontend.ci.tests.pages;
22
23 import com.aventstack.extentreports.Status;
24 import fj.data.Either;
25 import org.openecomp.sdc.be.model.Service;
26 import org.onap.sdc.frontend.ci.tests.datatypes.DataTestIdEnum;
27 import org.onap.sdc.frontend.ci.tests.datatypes.DataTestIdEnum.ServiceMetadataEnum;
28 import org.onap.sdc.backend.ci.tests.datatypes.ServiceReqDetails;
29 import org.onap.sdc.backend.ci.tests.datatypes.enums.UserRoleEnum;
30 import org.onap.sdc.frontend.ci.tests.execute.setup.SetupCDTest;
31 import org.onap.sdc.backend.ci.tests.tosca.datatypes.ToscaDefinition;
32 import org.onap.sdc.frontend.ci.tests.utilities.FileHandling;
33 import org.onap.sdc.frontend.ci.tests.utilities.GeneralUIUtils;
34 import org.onap.sdc.backend.ci.tests.utils.ToscaParserUtils;
35 import org.onap.sdc.backend.ci.tests.utils.Utils;
36 import org.onap.sdc.backend.ci.tests.utils.general.AtomicOperationUtils;
37 import org.onap.sdc.frontend.ci.tests.verificator.ToscaValidation;
38 import org.openqa.selenium.By;
39 import org.openqa.selenium.WebElement;
40
41 import java.io.File;
42 import java.util.ArrayList;
43 import java.util.List;
44 import java.util.Map;
45
46 public class ServiceGeneralPage extends ResourceGeneralPage {
47
48     public static ServiceLeftMenu getServiceLeftMenu() {
49         return new ServiceLeftMenu();
50     }
51
52     public static void defineName(String serviceName) {
53         WebElement serviceNameTextbox = GeneralUIUtils
54                 .getWebElementByTestID(DataTestIdEnum.ServiceMetadataEnum.SERVICE_NAME.getValue());
55         serviceNameTextbox.clear();
56         serviceNameTextbox.sendKeys(serviceName);
57     }
58
59
60     public static void defineServiceFunction(String serviceFunction) {
61         WebElement serviceFunctionTextbox = GeneralUIUtils
62                 .getWebElementByTestID(DataTestIdEnum.ServiceMetadataEnum.SERVICE_FUNCTION.getValue());
63         serviceFunctionTextbox.clear();
64         serviceFunctionTextbox.sendKeys(serviceFunction);
65     }
66
67     public static void defineProjectCode(String pmat) {
68         WebElement projectCodeTextbox = GeneralUIUtils
69                 .getWebElementByTestID(DataTestIdEnum.ServiceMetadataEnum.PROJECT_CODE.getValue());
70         projectCodeTextbox.clear();
71         projectCodeTextbox.sendKeys(pmat);
72     }
73     public static void defineNamingPolicy(String namingPolicyText) {
74         WebElement namingPolicyTextbox = GeneralUIUtils
75                 .getWebElementByTestID(DataTestIdEnum.ServiceMetadataEnum.NAMING_POLICY.getValue());
76         namingPolicyTextbox.clear();
77         namingPolicyTextbox.sendKeys(namingPolicyText);
78     }
79
80     public static void defineModel(final String model) {
81         GeneralUIUtils.getSelectList(model, getModelDataTestsIdAttribute());
82     }
83
84         public static String getServiceFunctionText(){
85                 return getServiceFunctionField().getAttribute("value");
86         }
87
88     public static String getNamingPolicyText(){
89         return getNamingPolicyField().getAttribute("value");
90     }
91
92     private static WebElement getNamingPolicyField() {
93         return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ServiceMetadataEnum.NAMING_POLICY.getValue());
94     }
95
96
97     public static String getProjectCodeText() {
98         return getProjectCodeField().getAttribute("value");
99     }
100
101     public static String[] getTags() {
102         return getElementsFromTagsTable().stream().map(WebElement::getText).toArray(String[]::new);
103     }
104     private static WebElement getServiceFunctionField() {
105         return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ServiceMetadataEnum.SERVICE_FUNCTION.getValue());
106     }
107
108     private static WebElement getProjectCodeField() {
109         return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ServiceMetadataEnum.PROJECT_CODE.getValue());
110     }
111
112     public static void deleteOldTags(ServiceReqDetails service) {
113         // Delete tag elements
114         int i = GeneralUIUtils.getWebElementsListByTestID("i-sdc-tag-delete").size();
115         while (i > 0) {
116             GeneralUIUtils.getWebElementByTestID("i-sdc-tag-delete").click();
117             i--;
118         }
119
120         service.setTags(new ArrayList<String>());
121     }
122
123     public static String getCategoryText() {
124         return GeneralUIUtils.getSelectedElementFromDropDown(getCategoryDataTestsIdAttribute()).getText();
125     }
126
127     public static List<WebElement> getCategories() {
128         return GeneralUIUtils.getElementFromDropDown(getCategoryDataTestsIdAttribute()).getOptions();
129     }
130
131     public static String getInstantiationTypeChosenValue() {
132         return GeneralUIUtils.getSelectedElementFromDropDown(getInstantiationTypeIdAttribute()).getText();
133     }
134
135     private static String getInstantiationTypeIdAttribute() {
136         return ServiceMetadataEnum.INSTANTIATION_TYPE.getValue();
137     }
138
139     public static void clickAddWorkflow() {
140         SetupCDTest.getExtendTest().log(Status.INFO, "Adding workflow...");
141         GeneralUIUtils.clickOnElementByText("Add Workflow");
142     }
143
144     public static void fillAndAddNewWorkflow(String name, String description) throws InterruptedException {
145         GeneralUIUtils.ultimateWait();
146         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Filling name field with %s", name));
147         insertText(name, "label + input");
148         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Filling description filed with %s", name));
149         insertText(description, "label + textarea");
150         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking save button ");
151         clickSave();
152     }
153
154     public static void insertText(String artifactDescriptoin, String element) throws InterruptedException {
155         GeneralUIUtils.getElementsByCSS("div[class='modal-content']");
156         WebElement artifactDescriptionTextbox = GeneralUIUtils.getWebElementBy(By.cssSelector(element));
157         artifactDescriptionTextbox.clear();
158         artifactDescriptionTextbox.sendKeys(artifactDescriptoin);
159         GeneralUIUtils.ultimateWait();
160     }
161
162     public static void clickSave() {
163         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Save button");
164         GeneralUIUtils.clickOnElementByXpath("//*[@data-test-id='form-submit-button']");
165         GeneralUIUtils.ultimateWait();
166     }
167
168     public static void defineInstantiationType(String instantiationType) {
169         GeneralUIUtils.getSelectList(instantiationType, DataTestIdEnum.ServiceMetadataEnum.INSTANTIATION_TYPE.getValue());
170     }
171
172     public Service prepareServiceObject(ServiceReqDetails serviceMetadata) throws Exception {
173         return AtomicOperationUtils.getServiceObjectByNameAndVersion(UserRoleEnum.DESIGNER, serviceMetadata.getName(), "0.1");
174     }
175
176     public static boolean parseToscaFileIntoServiceAndValidateProperties(ServiceReqDetails serviceMetadata) throws Exception {
177         ServiceGeneralPage serviceGeneralPageObject = new ServiceGeneralPage();
178         Service service = serviceGeneralPageObject.prepareServiceObject(serviceMetadata);
179         Map<String, String> expectedMetadataMap = Utils.generateServiceMetadataToExpectedObject(serviceMetadata, service);
180         File latestFilefromDir = FileHandling.getLastModifiedFileNameFromDir();
181         ToscaDefinition toscaServiceDefinition = ToscaParserUtils.parseToscaMainYamlToJavaObjectByCsarLocation(latestFilefromDir);
182         Either<Boolean, Map<String, Object>> serviceToscaMetadataValidator = ToscaValidation.serviceToscaMetadataValidator(expectedMetadataMap, toscaServiceDefinition);
183         return serviceToscaMetadataValidator.isRight();
184     }
185
186 }