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