[SDC-29] rebase continue work to align source
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / US / Inputs.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.US;
22
23 import java.util.Arrays;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27
28 import org.openecomp.sdc.ci.tests.datatypes.CanvasElement;
29 import org.openecomp.sdc.ci.tests.datatypes.CanvasManager;
30 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
31 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
32 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
33 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
34 import org.openecomp.sdc.ci.tests.pages.CompositionPage;
35 import org.openecomp.sdc.ci.tests.pages.DeploymentArtifactPage;
36 import org.openecomp.sdc.ci.tests.pages.InputsPage;
37 import org.openecomp.sdc.ci.tests.pages.PropertyPopup;
38 import org.openecomp.sdc.ci.tests.utilities.FileHandling;
39 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
40 import org.openecomp.sdc.ci.tests.utilities.ServiceUIUtils;
41 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
42 import org.openqa.selenium.By;
43 import org.openqa.selenium.WebElement;
44 import org.testng.Assert;
45 import org.testng.TestException;
46 import org.testng.annotations.BeforeMethod;
47 import org.testng.annotations.Test;
48
49 public class Inputs extends SetupCDTest {
50         
51         private static final String DESCRIPTION = "kuku";
52         private static final String ARTIFACT_LABEL = "artifact3";
53         private static final String ARTIFACT_LABEL_UPDATE = "artifactUpdate";
54         private static final String GET_ARTIFACT_LIST_BY_CLASS_NAME = "i-sdc-designer-sidebar-section-content-item-artifact";
55         private static final String HEAT_FILE_YAML_NAME = "Heat-File.yaml";
56         private static final String HEAT_FILE_YAML_UPDATE_NAME = "Heat-File-Update.yaml";
57         private String filePath;
58         
59         @BeforeMethod
60         public void beforeTest(){
61                 filePath = FileHandling.getFilePath("");
62         }
63         
64         // TODO: There is defect that imported VFC checkin not appear in service until refresh
65         // TODO: add support for CP (there is no normative CP's with complex properties which can be selected - import one) - importVFCWithComplexProperty.yml
66         // TC1508249
67         // Delete Input declared from VLi/CPi in service level - Deleting an Input that was declared from Complex property.
68         @Test
69         public void  deletingAnInputThatWasDeclaredFromComplexProperty() throws Exception{
70                 ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
71                 ServiceUIUtils.createService(serviceMetadata, getUser());
72                 
73                 DeploymentArtifactPage.getLeftMenu().moveToCompositionScreen();
74                 CanvasManager canvasManager = CanvasManager.getCanvasManager();
75                 Map<String, List<String>> resourceInstanceToProperty = new HashMap<>();
76                 CompositionPage.searchForElement("ExtVL");
77                 CanvasElement computeElement = canvasManager.createElementOnCanvas("ExtVL");
78                 canvasManager.clickOnCanvaElement(computeElement);
79                 resourceInstanceToProperty.put(CompositionPage.getSelectedInstanceName(), Arrays.asList("network_homing", "instance_node_target"));
80                 
81 //              CompositionPage.searchForElement("ExtCP");
82 //              computeElement = canvasManager.createElementOnCanvas("ExtCP");
83 //              canvasManager.clickOnCanvaElement(computeElement);
84 //              resourceInstanceToProperty.put(CompositionPage.getSelectedInstanceName(), "order");
85                 
86                 GeneralUIUtils.clickOnElementByTestId("breadcrumbs-button-1");
87                 DeploymentArtifactPage.getLeftMenu().moveToInputsScreen();
88                 
89                 
90                 for(String element: resourceInstanceToProperty.keySet()) {
91                         String propertyName = resourceInstanceToProperty.get(element).get(0);
92                         String innerPropertyName = resourceInstanceToProperty.get(element).get(1);
93                         String dataTestIdPropertyCheckbox = DataTestIdEnum.InputsScreenService.RESOURCE_INSTANCE_PROPERTY_CHECKBOX.getValue() + propertyName;
94                         
95                         GeneralUIUtils.clickOnElementByText(element);
96                         GeneralUIUtils.ultimateWait();
97                         
98                         InputsPage.clickOnProperty(propertyName);
99                         
100                         PropertyPopup propertyPopup = new PropertyPopup();
101                         propertyPopup.selectPropertyRadioButton(innerPropertyName);
102                         propertyPopup.clickSave();
103                         
104                         InputsPage.clickOnAddInputButton();
105                         
106                         // Verify that input checkbox selected
107                         verifyPropertyCheckBoxSelected(dataTestIdPropertyCheckbox);
108                         
109                         InputsPage.deleteServiceInput(element, propertyName + "_" + innerPropertyName);
110                         
111                         // Trying to find deleted service input
112                         try{
113                                 InputsPage.getServiceInput(element, propertyName + "_" + innerPropertyName);
114                                 assert(false);
115                         } catch(TestException e){       
116                                 System.out.println("Verfied that service input deleted");
117                         }
118                         
119                         // Verify that input checkbox not selected
120                         verifyPropertyCheckBoxNotSelected(dataTestIdPropertyCheckbox);
121                         
122                         GeneralUIUtils.clickOnElementByText(element);
123                         GeneralUIUtils.ultimateWait();
124                 }
125                 
126         }
127
128         
129         // TC1508248
130         // Delete inputs who come from CP/VL properties
131         @Test
132         public void  deleteInputsWhoComeFromCpVlProperties() throws Exception{
133                 ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
134                 ServiceUIUtils.createService(serviceMetadata, getUser());
135                 
136                 DeploymentArtifactPage.getLeftMenu().moveToCompositionScreen();
137                 CanvasManager canvasManager = CanvasManager.getCanvasManager();
138                 Map<String, String> resourceInstanceToProperty = new HashMap<>();
139                 CompositionPage.searchForElement("ExtVL");
140                 CanvasElement computeElement = canvasManager.createElementOnCanvas("ExtVL");
141                 canvasManager.clickOnCanvaElement(computeElement);
142                 resourceInstanceToProperty.put(CompositionPage.getSelectedInstanceName(), "network_role");
143                 
144                 CompositionPage.searchForElement("ExtCP");
145                 computeElement = canvasManager.createElementOnCanvas("ExtCP");
146                 canvasManager.clickOnCanvaElement(computeElement);
147                 resourceInstanceToProperty.put(CompositionPage.getSelectedInstanceName(), "order");
148                 
149                 GeneralUIUtils.clickOnElementByTestId("breadcrumbs-button-1");
150                 DeploymentArtifactPage.getLeftMenu().moveToInputsScreen();
151                 
152                 
153                 for(String element: resourceInstanceToProperty.keySet()) {
154                         GeneralUIUtils.clickOnElementByText(element);
155                         GeneralUIUtils.ultimateWait();
156                         
157                         WebElement webElementByTestID = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.InputsScreenService.RESOURCE_INSTANCE_PROPERTY_CHECKBOX.getValue() + resourceInstanceToProperty.get(element));
158                         InputsPage.clickOnVFInputCheckbox(webElementByTestID);
159                         
160                         InputsPage.clickOnAddInputButton();
161                         
162                         // Verify that input checkbox selected
163                         verifyPropertyCheckBoxSelected(DataTestIdEnum.InputsScreenService.RESOURCE_INSTANCE_PROPERTY_CHECKBOX.getValue() + resourceInstanceToProperty.get(element));
164                         
165                         InputsPage.deleteServiceInput(element, resourceInstanceToProperty.get(element));
166                         
167                         // Trying to find deleted service input
168                         try{
169                                 InputsPage.getServiceInput(element, resourceInstanceToProperty.get(element));
170                                 assert(false);
171                         } catch(TestException e){       
172                                 System.out.println("Verfied that service input deleted");
173                         }
174                         
175                         // Verify that input checkbox not selected
176                         verifyPropertyCheckBoxNotSelected(DataTestIdEnum.InputsScreenService.RESOURCE_INSTANCE_PROPERTY_CHECKBOX.getValue() + resourceInstanceToProperty.get(element));
177                         
178                         GeneralUIUtils.clickOnElementByText(element);
179                         GeneralUIUtils.ultimateWait();
180                 }
181                 
182         }
183         
184         
185         
186         
187         
188         
189         
190         public String verifyPropertyCheckBox(String dataTestId) {
191                 WebElement webElementByTestID = GeneralUIUtils.getWebElementByTestID(dataTestId);
192                 webElementByTestID = webElementByTestID.findElement(By.className("tlv-checkbox-i"));
193                 if(webElementByTestID.getAttribute("checked") == null) {
194                         return "false";
195                 }
196                 return "true";
197         }
198         
199         public void verifyPropertyCheckBoxSelected(String dataTestId) {
200                 if(!verifyPropertyCheckBox(dataTestId).equals("true")) {
201                         Assert.assertEquals(true, false, "Expected that checkbox will be selected.");
202                 }
203         }
204         
205         public void verifyPropertyCheckBoxNotSelected(String dataTestId) {
206                 if(!verifyPropertyCheckBox(dataTestId).equals("false")) {
207                         Assert.assertEquals(false, true, "Expected that checkbox will not be selected.");
208                 }
209         }
210
211         public String getNormalizedName(String notNormalizedName) {
212                 String normalizedName = notNormalizedName.toLowerCase();
213                 normalizedName = normalizedName.replaceAll(" ", "");
214                 
215                 return normalizedName;
216         }
217         
218
219
220
221         @Override
222         protected UserRoleEnum getRole() {
223                 return UserRoleEnum.DESIGNER;
224         }
225
226 }