2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.ci.tests.pages;
23 import com.aventstack.extentreports.Status;
24 import fj.data.Either;
25 import org.openecomp.sdc.be.model.Service;
26 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
27 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.ServiceMetadataEnum;
28 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
29 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
30 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
31 import org.openecomp.sdc.ci.tests.tosca.datatypes.ToscaDefinition;
32 import org.openecomp.sdc.ci.tests.utilities.FileHandling;
33 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
34 import org.openecomp.sdc.ci.tests.utils.ToscaParserUtils;
35 import org.openecomp.sdc.ci.tests.utils.Utils;
36 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
37 import org.openecomp.sdc.ci.tests.verificator.ToscaValidation;
38 import org.openqa.selenium.By;
39 import org.openqa.selenium.WebElement;
42 import java.util.ArrayList;
45 public class ServiceGeneralPage extends ResourceGeneralPage {
47 public static ServiceLeftMenu getServiceLeftMenu() {
48 return new ServiceLeftMenu();
51 public static void defineName(String serviceName) {
52 WebElement serviceNameTextbox = GeneralUIUtils
53 .getWebElementByTestID(DataTestIdEnum.ServiceMetadataEnum.SERVICE_NAME.getValue());
54 serviceNameTextbox.clear();
55 serviceNameTextbox.sendKeys(serviceName);
59 public static void defineServiceFunction(String serviceFunction) {
60 WebElement serviceFunctionTextbox = GeneralUIUtils
61 .getWebElementByTestID(DataTestIdEnum.ServiceMetadataEnum.SERVICE_FUNCTION.getValue());
62 serviceFunctionTextbox.clear();
63 serviceFunctionTextbox.sendKeys(serviceFunction);
66 public static void defineProjectCode(String pmat) {
67 WebElement projectCodeTextbox = GeneralUIUtils
68 .getWebElementByTestID(DataTestIdEnum.ServiceMetadataEnum.PROJECT_CODE.getValue());
69 projectCodeTextbox.clear();
70 projectCodeTextbox.sendKeys(pmat);
72 public static void defineNamingPolicy(String namingPolicyText) {
73 WebElement namingPolicyTextbox = GeneralUIUtils
74 .getWebElementByTestID(DataTestIdEnum.ServiceMetadataEnum.NAMING_POLICY.getValue());
75 namingPolicyTextbox.clear();
76 namingPolicyTextbox.sendKeys(namingPolicyText);
79 public static String getServiceFunctionText(){
80 return getServiceFunctionField().getAttribute("value");
83 public static String getNamingPolicyText(){
84 return getNamingPolicyField().getAttribute("value");
87 private static WebElement getNamingPolicyField() {
88 return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ServiceMetadataEnum.NAMING_POLICY.getValue());
92 public static String getProjectCodeText() {
93 return getProjectCodeField().getAttribute("value");
96 public static String[] getTags() {
97 return ResourceGeneralPage.getElementsFromTagsTable().stream().map(WebElement::getText).toArray(String[]::new);
99 private static WebElement getServiceFunctionField() {
100 return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ServiceMetadataEnum.SERVICE_FUNCTION.getValue());
103 private static WebElement getProjectCodeField() {
104 return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ServiceMetadataEnum.PROJECT_CODE.getValue());
107 public static void deleteOldTags(ServiceReqDetails service) {
108 // Delete tag elements
109 int i = GeneralUIUtils.getWebElementsListByTestID("i-sdc-tag-delete").size();
111 GeneralUIUtils.getWebElementByTestID("i-sdc-tag-delete").click();
115 service.setTags(new ArrayList<String>());
118 public static String getCategoryText() {
119 return GeneralUIUtils.getSelectedElementFromDropDown(getCategoryDataTestsIdAttribute()).getText();
122 public static String getInstantiationTypeChosenValue() {
123 return GeneralUIUtils.getSelectedElementFromDropDown(getInstantiationTypeIdAttribute()).getText();
126 private static String getInstantiationTypeIdAttribute() {
127 return ServiceMetadataEnum.INSTANTIATION_TYPE.getValue();
130 public static void clickAddWorkflow() {
131 SetupCDTest.getExtendTest().log(Status.INFO, "Adding workflow...");
132 GeneralUIUtils.clickOnElementByText("Add Workflow");
135 public static void fillAndAddNewWorkflow(String name, String description) throws InterruptedException {
136 GeneralUIUtils.ultimateWait();
137 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Filling name field with %s", name));
138 insertText(name, "label + input");
139 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Filling description filed with %s", name));
140 insertText(description, "label + textarea");
141 SetupCDTest.getExtendTest().log(Status.INFO, "Clicking save button ");
145 public static void insertText(String artifactDescriptoin, String element) throws InterruptedException {
146 GeneralUIUtils.getElementsByCSS("div[class='modal-content']");
147 WebElement artifactDescriptionTextbox = GeneralUIUtils.getWebElementBy(By.cssSelector(element));
148 artifactDescriptionTextbox.clear();
149 artifactDescriptionTextbox.sendKeys(artifactDescriptoin);
150 GeneralUIUtils.ultimateWait();
153 public static void clickSave() {
154 SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Save button");
155 GeneralUIUtils.clickOnElementByXpath("//*[@data-test-id='form-submit-button']");
156 GeneralUIUtils.ultimateWait();
159 public static void defineInstantiationType(String instantiationType) {
160 GeneralUIUtils.getSelectList(instantiationType, DataTestIdEnum.ServiceMetadataEnum.INSTANTIATION_TYPE.getValue());
163 public Service prepareServiceObject(ServiceReqDetails serviceMetadata) throws Exception {
164 return AtomicOperationUtils.getServiceObjectByNameAndVersion(UserRoleEnum.DESIGNER, serviceMetadata.getName(), "0.1");
167 public static boolean parseToscaFileIntoServiceAndValidateProperties(ServiceReqDetails serviceMetadata) throws Exception {
168 ServiceGeneralPage serviceGeneralPageObject = new ServiceGeneralPage();
169 Service service = serviceGeneralPageObject.prepareServiceObject(serviceMetadata);
170 Map<String, String> expectedMetadataMap = Utils.generateServiceMetadataToExpectedObject(serviceMetadata, service);
171 File latestFilefromDir = FileHandling.getLastModifiedFileNameFromDir();
172 ToscaDefinition toscaServiceDefinition = ToscaParserUtils.parseToscaMainYamlToJavaObjectByCsarLocation(latestFilefromDir);
173 Either<Boolean, Map<String, Object>> serviceToscaMetadataValidator = ToscaValidation.serviceToscaMetadataValidator(expectedMetadataMap, toscaServiceDefinition);
174 return serviceToscaMetadataValidator.isRight();