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