[SDC-29] rebase continue work to align source
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / utilities / PropertiesUIUtils.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.openecomp.sdc.ci.tests.utilities;
22
23 import java.util.HashMap;
24 import java.util.Map;
25
26 import org.openecomp.sdc.ci.tests.datatypes.enums.PropertyTypeEnum;
27 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
28 import org.openecomp.sdc.ci.tests.pages.PropertiesPage;
29 import org.openqa.selenium.WebElement;
30
31 import com.aventstack.extentreports.Status;
32
33 public class PropertiesUIUtils {
34
35         // public static void addPropertByType(String type,String name,String
36         // defaultValue,String description) throws Exception{
37         //
38         // ResourceUIUtils.defineNewSelectList(type);
39         // ResourceUIUtils.definePropertyName(name);
40         // ResourceUIUtils.defineDefaultValueByType(defaultValue);
41         // ResourceUIUtils.defineDescription(description);
42         // Thread.sleep(2000);
43         // ResourceUIUtils.clickButton("Add");
44         // }
45         public static Map<String, String> addProperties(String name, String itemType, String defaultValue,
46                         String description, String schemaType) throws Exception {
47                 Map<String, String> propertyvalues = new HashMap<String, String>();
48                 GeneralUIUtils.getSelectList(itemType, "propertyType");
49                 ResourceUIUtils.definePropertyName(name);
50                 if (itemType == "boolean") {
51                         ResourceUIUtils.defineBoolenDefaultValue(defaultValue);
52                         GeneralUIUtils.setWebElementByTestId("description","description");
53                         Thread.sleep(2000);
54                         GeneralUIUtils.getWebElementByTestID("Add").click();
55                         ;
56                 } else if (itemType == "list" || itemType == "map") {
57                         GeneralUIUtils.getSelectList(schemaType, "schemaType");
58                 }
59                 if (!(itemType == "boolean")) {
60                         ResourceUIUtils.defineDefaultValueByType(defaultValue);
61                         GeneralUIUtils.setWebElementByTestId("description", "des");
62                         GeneralUIUtils.getWebElementByTestID("Add").click();
63                         ;
64                         Thread.sleep(2000);
65                 }
66                 propertyvalues.put("type", itemType);
67                 propertyvalues.put("defaultValue", defaultValue);
68                 propertyvalues.put("description", description);
69                 propertyvalues.put("name", name);
70
71                 return propertyvalues;
72         }
73
74         public static void vlidateProperties(Map<String, String> propertyValues) throws InterruptedException {
75                 WebElement name = GeneralUIUtils.getWebElementByTestID(propertyValues.get("name"));
76                 name.getText().equalsIgnoreCase(propertyValues.get("name"));
77                 WebElement defaultValue = GeneralUIUtils.getWebElementByTestID(propertyValues.get("name"));
78                 defaultValue.getText().equalsIgnoreCase(propertyValues.get("defaultValue"));
79                 WebElement type = GeneralUIUtils.getWebElementByTestID(propertyValues.get("type"));
80                 type.getText().equalsIgnoreCase(propertyValues.get("type"));
81         }
82
83         public static void addNewProperty(PropertyTypeEnum property) {
84                 GeneralUIUtils.ultimateWait();
85                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Adding new %s property", property.name()));
86                 PropertiesPage.clickAddPropertyArtifact();
87                 PropertiesPage.getPropertyPopup().insertPropertyName(property.getName());
88                 PropertiesPage.getPropertyPopup().selectPropertyType(property.getType());
89                 PropertiesPage.getPropertyPopup().insertPropertyDescription(property.getDescription());
90                 PropertiesPage.getPropertyPopup().insertPropertyDefaultValue(property.getValue());
91                 PropertiesPage.getPropertyPopup().clickSave();
92         }
93         
94         public static void updateProperty(PropertyTypeEnum property) {
95                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Updating property: %s", property.name()));
96                 PropertiesPage.clickOnProperty(property.getName());
97                 PropertiesPage.getPropertyPopup().insertPropertyDescription(property.getDescription());
98                 PropertiesPage.getPropertyPopup().insertPropertyDefaultValue(property.getValue());
99                 PropertiesPage.getPropertyPopup().clickSave();
100         }
101         
102         public static void changePropertyDefaultValueInComposition(String propertyName, String defaultValue) {
103                 GeneralUIUtils.clickOnElementByTestId(propertyName);
104                 PropertiesPage.getPropertyPopup().insertPropertyDefaultValue(defaultValue);
105                 PropertiesPage.getPropertyPopup().clickSave();
106         }
107
108 }