[SDC-29] rebase continue work to align source
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / US / extendNode_TemplatePropertiesWithDefaultValues.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.io.File;
24 import java.util.HashMap;
25 import java.util.LinkedList;
26 import java.util.Map;
27 import java.util.Set;
28
29 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
30 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
31 import org.openecomp.sdc.ci.tests.datatypes.TopMenuButtonsEnum;
32 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.ToscaArtifactsScreenEnum;
33 import org.openecomp.sdc.ci.tests.datatypes.TopMenuButtonsEnum;
34 import org.openecomp.sdc.ci.tests.datatypes.CanvasElement;
35 import org.openecomp.sdc.ci.tests.datatypes.CanvasManager;
36 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
37 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
38 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
39 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
40 import org.openecomp.sdc.ci.tests.pages.CompositionPage;
41 import org.openecomp.sdc.ci.tests.pages.GeneralPageElements;
42 import org.openecomp.sdc.ci.tests.pages.ResourceGeneralPage;
43 import org.openecomp.sdc.ci.tests.pages.TesterOperationPage;
44 import org.openecomp.sdc.ci.tests.tosca.datatypes.ToscaDefinition;
45 import org.openecomp.sdc.ci.tests.utilities.FileHandling;
46 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
47 import org.openecomp.sdc.ci.tests.utilities.PropertiesUIUtils;
48 import org.openecomp.sdc.ci.tests.utilities.ResourceUIUtils;
49 import org.openecomp.sdc.ci.tests.utilities.RestCDUtils;
50 import org.openecomp.sdc.ci.tests.utilities.ServiceUIUtils;
51 import org.openecomp.sdc.ci.tests.utils.ToscaParserUtils;
52 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
53 import org.testng.Assert;
54 import org.testng.annotations.DataProvider;
55 import org.testng.annotations.Test;
56
57
58 public class extendNode_TemplatePropertiesWithDefaultValues extends SetupCDTest {
59
60         @DataProvider(name="customizeServiceVfUsedVlsCps") 
61         public static Object[][] dataProviderCustomizeServiceVfUsedVlsCps() {
62                 return new Object[][] {
63 //                      {"VL_US831517_1.yml", "VL_US831517_2.yml", "VL_US831517_3.yml", ResourceTypeEnum.VL, ComponentTypeEnum.SERVICE},
64                         {"CP_US831517_1.yml", "CP_US831517_2.yml", "CP_US831517_3.yml", ResourceTypeEnum.CP, ComponentTypeEnum.SERVICE},
65                         {"VL_US831517_1.yml", "VL_US831517_2.yml", "VL_US831517_3.yml", ResourceTypeEnum.VL, ComponentTypeEnum.RESOURCE},
66                         {"CP_US831517_1.yml", "CP_US831517_2.yml", "CP_US831517_3.yml", ResourceTypeEnum.CP, ComponentTypeEnum.RESOURCE},
67                         };
68         }
69         
70         // US831517 - Story [BE] - Extend node_template properties with default values
71         @Test(dataProvider="customizeServiceVfUsedVlsCps")
72         public void customizeServiceVfUsedVlsCps(String fileName_vl1, String fileName_vl2, String fileName_vl3, ResourceTypeEnum resourceTypeEnum, ComponentTypeEnum componentTypeEnum) throws Exception {
73                 setLog("Extend node_template properties with default values");
74
75                 // import Resource
76                 LinkedList<String> assetsName = importThreeAsset(fileName_vl1, fileName_vl2, fileName_vl3, resourceTypeEnum);
77                 
78                 if(ComponentTypeEnum.SERVICE == componentTypeEnum) {
79                         ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
80                         ServiceUIUtils.createService(serviceMetadata, getUser());
81                 } else {
82                         ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
83                         ResourceUIUtils.createResource(resourceMetaData, getUser());
84                 }
85                 
86                 ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();            
87                 CanvasManager canvasManager = CanvasManager.getCanvasManager();
88                 CanvasElement resourceInstance1 = canvasManager.createElementOnCanvas(assetsName.get(0));
89                 CanvasElement resourceInstance2 = canvasManager.createElementOnCanvas(assetsName.get(1));
90                 CanvasElement resourceInstance3 = canvasManager.createElementOnCanvas(assetsName.get(2));
91                 
92                 canvasManager.clickOnCanvaElement(resourceInstance1);
93                 CompositionPage.showPropertiesAndAttributesTab();
94                 PropertiesUIUtils.changePropertyDefaultValueInComposition("property_1", "false");
95                 
96                 canvasManager.clickOnCanvaElement(resourceInstance2);
97                 CompositionPage.showPropertiesAndAttributesTab();
98                 PropertiesUIUtils.changePropertyDefaultValueInComposition("property_3", "customize");
99                 
100                 canvasManager.clickOnCanvaElement(resourceInstance3);
101                 CompositionPage.showPropertiesAndAttributesTab();
102                 PropertiesUIUtils.changePropertyDefaultValueInComposition("property_2", "customize derived");
103                 PropertiesUIUtils.changePropertyDefaultValueInComposition("property_5", "customize new");
104                 
105                 GeneralUIUtils.clickOnElementByTestId("breadcrumbs-button-1");
106                 ResourceGeneralPage.getLeftMenu().moveToToscaArtifactsScreen();
107                 GeneralUIUtils.clickOnElementByTestId(ToscaArtifactsScreenEnum.TOSCA_TEMPLATE.getValue());
108                 
109                 // TODO: Replace it by automatic download to path
110                 // TODO: After it remove
111                 File path = new File("C:\\Users\\rp955r\\Desktop\\US\\US831517\\TCExport\\TC1459238.yml");
112                 ToscaDefinition toscaDefinition = ToscaParserUtils.parseToscaYamlToJavaObject(path);
113                 
114                 Map<String, Object> vl_us831517_1 = new HashMap<String, Object>();
115                 vl_us831517_1.put("property_1", false);
116                 vl_us831517_1.put("property_2", "init_value_2");
117                 vl_us831517_1.put("property_3", "init_value_3");
118                 
119                 
120                 Map<String, Object> vl_us831517_2 = new HashMap<String, Object>();
121                 vl_us831517_2.put("property_1", false);
122                 vl_us831517_2.put("property_2", "init_value_2");
123                 vl_us831517_2.put("property_3", "customize");
124                 
125                 Map<String, Object> vl_us831517_3 = new HashMap<String, Object>();
126                 vl_us831517_3.put("property_1", true);
127                 vl_us831517_3.put("property_2", "customize derived");
128                 vl_us831517_3.put("property_3", "init_value_3");
129                 vl_us831517_3.put("property_4", false);
130                 vl_us831517_3.put("property_5", "customize new");
131                 
132                 Map<String, Map<String, Object>> predefinedProperties = new HashMap<String, Map<String, Object>>();
133                 predefinedProperties.put("VL_US831517_1", vl_us831517_1);
134                 predefinedProperties.put("VL_US831517_2", vl_us831517_2);
135                 predefinedProperties.put("VL_US831517_3", vl_us831517_3);
136                 
137                 validateNodeTemplatesProperties(predefinedProperties, toscaDefinition);
138                 
139                 RestCDUtils.deleteOnDemand();
140         }
141         
142         @DataProvider(name="serviceVfUsedVlsCps") 
143         public static Object[][] dataProviderServiceVfUsedVlsCps() {
144                 return new Object[][] {
145                         {"VL_US831517_1.yml", "VL_US831517_2.yml", "VL_US831517_3.yml", ResourceTypeEnum.VL, ComponentTypeEnum.SERVICE},
146                         {"CP_US831517_1.yml", "CP_US831517_2.yml", "CP_US831517_3.yml", ResourceTypeEnum.CP, ComponentTypeEnum.SERVICE},
147                         {"VL_US831517_1.yml", "VL_US831517_2.yml", "VL_US831517_3.yml", ResourceTypeEnum.VL, ComponentTypeEnum.RESOURCE},
148                         {"CP_US831517_1.yml", "CP_US831517_2.yml", "CP_US831517_3.yml", ResourceTypeEnum.CP, ComponentTypeEnum.RESOURCE},
149                         };
150         }
151         
152         
153         // US831517 - Story [BE] - Extend node_template properties with default values
154         @Test(dataProvider="serviceVfUsedVlsCps")
155         public void serviceVfUsedVlsCps(String fileName_vl1, String fileName_vl2, String fileName_vl3, ResourceTypeEnum resourceTypeEnum, ComponentTypeEnum componentTypeEnum) throws Exception {
156                 setLog("Extend node_template properties with default values");
157
158                 // import Resource
159                 LinkedList<String> assetsName = importThreeAsset(fileName_vl1, fileName_vl2, fileName_vl3, resourceTypeEnum);
160                 
161                 if(ComponentTypeEnum.SERVICE == componentTypeEnum) {
162                         ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
163                         ServiceUIUtils.createService(serviceMetadata, getUser());
164                 } else {
165                         ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
166                         ResourceUIUtils.createResource(resourceMetaData, getUser());
167                 }
168                 
169                 ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();            
170                 CanvasManager canvasManager = CanvasManager.getCanvasManager();
171                 canvasManager.createElementOnCanvas(assetsName.get(0));
172                 canvasManager.createElementOnCanvas(assetsName.get(1));
173                 canvasManager.createElementOnCanvas(assetsName.get(2));
174                 
175                 GeneralUIUtils.clickOnElementByTestId("breadcrumbs-button-1");
176                 ResourceGeneralPage.getLeftMenu().moveToToscaArtifactsScreen();
177                 GeneralUIUtils.clickOnElementByTestId(ToscaArtifactsScreenEnum.TOSCA_TEMPLATE.getValue());
178                 
179                 // TODO: Replace it by automatic download to path
180                 // TODO: After it remove
181                 File path = new File("C:\\Users\\rp955r\\Desktop\\US\\US831517\\TCExport\\TC1459238.yml");
182                 ToscaDefinition toscaDefinition = ToscaParserUtils.parseToscaYamlToJavaObject(path);
183                 
184                 Map<String, Object> vl_us831517_1 = new HashMap<String, Object>();
185                 vl_us831517_1.put("property_1", true);
186                 vl_us831517_1.put("property_2", "init_value_2");
187                 vl_us831517_1.put("property_3", "init_value_3");
188                 
189                 
190                 Map<String, Object> vl_us831517_2 = new HashMap<String, Object>();
191                 vl_us831517_2.put("property_1", false);
192                 vl_us831517_2.put("property_2", "init_value_2");
193                 vl_us831517_2.put("property_3", "new_value_3");
194                 
195                 Map<String, Object> vl_us831517_3 = new HashMap<String, Object>();
196                 vl_us831517_3.put("property_1", true);
197                 vl_us831517_3.put("property_2", "init_value_2");
198                 vl_us831517_3.put("property_3", "init_value_3");
199                 vl_us831517_3.put("property_4", false);
200                 vl_us831517_3.put("property_5", "init_value_5");
201                 
202                 Map<String, Map<String, Object>> predefinedProperties = new HashMap<String, Map<String, Object>>();
203                 predefinedProperties.put("VL_US831517_1", vl_us831517_1);
204                 predefinedProperties.put("VL_US831517_2", vl_us831517_2);
205                 predefinedProperties.put("VL_US831517_3", vl_us831517_3);
206                 
207                 validateNodeTemplatesProperties(predefinedProperties, toscaDefinition);
208                 
209                 RestCDUtils.deleteOnDemand();
210         }
211         
212         private LinkedList<String> importThreeAsset(String fileName_vl1, String fileName_vl2, String fileName_vl3, ResourceTypeEnum resourceTypeEnum) throws Exception {
213                 LinkedList<String> assetsNames = new LinkedList<String>();
214                 
215                 String filePath = System.getProperty("filepath");
216                 if (filePath == null && System.getProperty("os.name").contains("Windows")) {
217                         filePath = FileHandling.getResourcesFilesPath() + File.separator + "US831517" + File.separator;
218                 }
219                 else if(filePath.isEmpty() && !System.getProperty("os.name").contains("Windows")){
220                         filePath = FileHandling.getBasePath() + File.separator + "Files" + File.separator + "US831517" + File.separator;
221                 }
222                 
223                 // import Resource
224                 ResourceReqDetails resourceMetaDataVl1 = ElementFactory.getDefaultResourceByType(resourceTypeEnum, getUser());
225                 assetsNames.add(resourceMetaDataVl1.getName());
226                 ResourceUIUtils.importVfc(resourceMetaDataVl1, filePath, fileName_vl1, getUser());
227                 GeneralPageElements.clickSubmitForTestingButton(resourceMetaDataVl1.getName());
228                 reloginWithNewRole(UserRoleEnum.TESTER);
229                 GeneralUIUtils.findComponentAndClick(resourceMetaDataVl1.getName());
230                 TesterOperationPage.certifyComponent(resourceMetaDataVl1.getName());
231                 reloginWithNewRole(UserRoleEnum.DESIGNER);
232                 
233                 ResourceReqDetails resourceMetaDataVl2 = ElementFactory.getDefaultResourceByType(resourceTypeEnum, getUser());
234                 assetsNames.add(resourceMetaDataVl2.getName());
235                 ResourceUIUtils.importVfc(resourceMetaDataVl2, filePath, fileName_vl2, getUser());
236                 GeneralPageElements.clickCheckinButton(resourceMetaDataVl2.getName());
237                 
238                 ResourceReqDetails resourceMetaDataVl3 = ElementFactory.getDefaultResourceByType(resourceTypeEnum, getUser());
239                 assetsNames.add(resourceMetaDataVl3.getName());
240                 ResourceUIUtils.importVfc(resourceMetaDataVl3, filePath, fileName_vl3, getUser());
241                 GeneralPageElements.clickCheckinButton(resourceMetaDataVl2.getName());
242                 
243                 return assetsNames;
244         }
245         
246         
247         private static void validateNodeTemplatesProperties(Map<String, Map<String, Object>> predefinedMap, ToscaDefinition toscaDefinition) {
248                 
249                 for(String key: predefinedMap.keySet()) {
250                         Map<String, Object> nodeTemplateProperties = getNodeTemplatePropertiesByNodeTemplateType(key, toscaDefinition);
251                         
252                         predefinedMap.get(key).forEach((i,j) -> {
253                                 Assert.assertEquals(nodeTemplateProperties.get(i), j, "Expected that the properties will be equal");
254                         });
255                 }
256
257         }
258         
259         // Get properties by type
260         private static Map<String, Object> getNodeTemplatePropertiesByNodeTemplateType(String nodeTemplateType, ToscaDefinition toscaDefinition) {
261                 Map<String, Object> propertiesMap = null;
262                 
263                 Set<String> nodeTemplates = getNodeTemplates(toscaDefinition);
264                 
265                 for(String nodeTemplate: nodeTemplates) {
266                         String currentNodeTemplateType = getNodeTemplateType(toscaDefinition, nodeTemplate);
267                         currentNodeTemplateType = currentNodeTemplateType.substring(currentNodeTemplateType.lastIndexOf(".") + 1);
268                         if(currentNodeTemplateType.equals(nodeTemplateType)) {
269                                 propertiesMap = getNodeTemplateProperties(toscaDefinition, nodeTemplate);
270                                 break;
271                         }
272                 }
273                 
274                 return propertiesMap;
275         }
276         
277         // Get node templates
278         private static Set<String> getNodeTemplates(ToscaDefinition toscaDefinition) {
279                 Set<String> resourceInstanceArray = toscaDefinition.getTopology_template().getNode_templates().keySet();
280                 return resourceInstanceArray;
281         }
282         
283         // Get type of node template
284         private static String getNodeTemplateType(ToscaDefinition toscaDefinition, String nodeTemplate) {
285                 return toscaDefinition.getTopology_template().getNode_templates().get(nodeTemplate).getType();
286         }
287                 
288         // Get properties of node template
289         private static Map<String, Object> getNodeTemplateProperties(ToscaDefinition toscaDefinition, String nodeTemplate) {
290                 Map<String, Object> propertiesMap = toscaDefinition.getTopology_template().getNode_templates().get(nodeTemplate).getProperties();
291                 return propertiesMap;
292         }
293         
294         @Override
295         protected UserRoleEnum getRole() {
296                 return UserRoleEnum.DESIGNER;
297         }
298
299 }