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.onap.sdc.frontend.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.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;
42 import java.util.ArrayList;
43 import java.util.List;
46 public class ServiceGeneralPage extends ResourceGeneralPage {
48 public static ServiceLeftMenu getServiceLeftMenu() {
49 return new ServiceLeftMenu();
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);
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);
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);
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);
80 public static void defineModel(final String model) {
81 GeneralUIUtils.getSelectList(model, getModelDataTestsIdAttribute());
84 public static String getServiceFunctionText(){
85 return getServiceFunctionField().getAttribute("value");
88 public static String getNamingPolicyText(){
89 return getNamingPolicyField().getAttribute("value");
92 private static WebElement getNamingPolicyField() {
93 return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ServiceMetadataEnum.NAMING_POLICY.getValue());
97 public static String getProjectCodeText() {
98 return getProjectCodeField().getAttribute("value");
101 public static String[] getTags() {
102 return getElementsFromTagsTable().stream().map(WebElement::getText).toArray(String[]::new);
104 private static WebElement getServiceFunctionField() {
105 return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ServiceMetadataEnum.SERVICE_FUNCTION.getValue());
108 private static WebElement getProjectCodeField() {
109 return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ServiceMetadataEnum.PROJECT_CODE.getValue());
112 public static void deleteOldTags(ServiceReqDetails service) {
113 // Delete tag elements
114 int i = GeneralUIUtils.getWebElementsListByTestID("i-sdc-tag-delete").size();
116 GeneralUIUtils.getWebElementByTestID("i-sdc-tag-delete").click();
120 service.setTags(new ArrayList<String>());
123 public static String getCategoryText() {
124 return GeneralUIUtils.getSelectedElementFromDropDown(getCategoryDataTestsIdAttribute()).getText();
127 public static List<WebElement> getCategories() {
128 return GeneralUIUtils.getElementFromDropDown(getCategoryDataTestsIdAttribute()).getOptions();
131 public static String getInstantiationTypeChosenValue() {
132 return GeneralUIUtils.getSelectedElementFromDropDown(getInstantiationTypeIdAttribute()).getText();
135 private static String getInstantiationTypeIdAttribute() {
136 return ServiceMetadataEnum.INSTANTIATION_TYPE.getValue();
139 public static void clickAddWorkflow() {
140 SetupCDTest.getExtendTest().log(Status.INFO, "Adding workflow...");
141 GeneralUIUtils.clickOnElementByText("Add Workflow");
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 ");
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();
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();
168 public static void defineInstantiationType(String instantiationType) {
169 GeneralUIUtils.getSelectList(instantiationType, DataTestIdEnum.ServiceMetadataEnum.INSTANTIATION_TYPE.getValue());
172 public Service prepareServiceObject(ServiceReqDetails serviceMetadata) throws Exception {
173 return AtomicOperationUtils.getServiceObjectByNameAndVersion(UserRoleEnum.DESIGNER, serviceMetadata.getName(), "0.1");
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();