2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.ci.tests.US;
24 import java.util.HashMap;
25 import java.util.LinkedList;
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.CanvasElement;
32 import org.openecomp.sdc.ci.tests.datatypes.CanvasManager;
33 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.ToscaArtifactsScreenEnum;
34 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
35 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
36 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
37 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
38 import org.openecomp.sdc.ci.tests.pages.CompositionPage;
39 import org.openecomp.sdc.ci.tests.pages.GeneralPageElements;
40 import org.openecomp.sdc.ci.tests.pages.ResourceGeneralPage;
41 import org.openecomp.sdc.ci.tests.pages.TesterOperationPage;
42 import org.openecomp.sdc.ci.tests.tosca.datatypes.ToscaDefinition;
43 import org.openecomp.sdc.ci.tests.utilities.FileHandling;
44 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
45 import org.openecomp.sdc.ci.tests.utilities.PropertiesUIUtils;
46 import org.openecomp.sdc.ci.tests.utilities.ResourceUIUtils;
47 import org.openecomp.sdc.ci.tests.utilities.RestCDUtils;
48 import org.openecomp.sdc.ci.tests.utilities.ServiceUIUtils;
49 import org.openecomp.sdc.ci.tests.utils.ToscaParserUtils;
50 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
51 import org.testng.Assert;
52 import org.testng.annotations.DataProvider;
53 import org.testng.annotations.Test;
56 public class extendNode_TemplatePropertiesWithDefaultValues extends SetupCDTest {
58 @DataProvider(name="customizeServiceVfUsedVlsCps")
59 public static Object[][] dataProviderCustomizeServiceVfUsedVlsCps() {
60 return new Object[][] {
61 // {"VL_US831517_1.yml", "VL_US831517_2.yml", "VL_US831517_3.yml", ResourceTypeEnum.VL, ComponentTypeEnum.SERVICE},
62 {"CP_US831517_1.yml", "CP_US831517_2.yml", "CP_US831517_3.yml", ResourceTypeEnum.CP, ComponentTypeEnum.SERVICE},
63 {"VL_US831517_1.yml", "VL_US831517_2.yml", "VL_US831517_3.yml", ResourceTypeEnum.VL, ComponentTypeEnum.RESOURCE},
64 {"CP_US831517_1.yml", "CP_US831517_2.yml", "CP_US831517_3.yml", ResourceTypeEnum.CP, ComponentTypeEnum.RESOURCE},
68 // US831517 - Story [BE] - Extend node_template properties with default values
69 @Test(dataProvider="customizeServiceVfUsedVlsCps")
70 public void customizeServiceVfUsedVlsCps(String fileName_vl1, String fileName_vl2, String fileName_vl3, ResourceTypeEnum resourceTypeEnum, ComponentTypeEnum componentTypeEnum) throws Exception {
71 setLog("Extend node_template properties with default values");
74 LinkedList<String> assetsName = importThreeAsset(fileName_vl1, fileName_vl2, fileName_vl3, resourceTypeEnum);
76 if(ComponentTypeEnum.SERVICE == componentTypeEnum) {
77 ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
78 ServiceUIUtils.createService(serviceMetadata, getUser());
80 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
81 ResourceUIUtils.createVF(resourceMetaData, getUser());
84 ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();
85 CanvasManager canvasManager = CanvasManager.getCanvasManager();
86 CanvasElement resourceInstance1 = canvasManager.createElementOnCanvas(assetsName.get(0));
87 CanvasElement resourceInstance2 = canvasManager.createElementOnCanvas(assetsName.get(1));
88 CanvasElement resourceInstance3 = canvasManager.createElementOnCanvas(assetsName.get(2));
90 canvasManager.clickOnCanvaElement(resourceInstance1);
91 CompositionPage.showPropertiesAndAttributesTab();
92 PropertiesUIUtils.changePropertyDefaultValueInComposition("property_1", "false");
94 canvasManager.clickOnCanvaElement(resourceInstance2);
95 CompositionPage.showPropertiesAndAttributesTab();
96 PropertiesUIUtils.changePropertyDefaultValueInComposition("property_3", "customize");
98 canvasManager.clickOnCanvaElement(resourceInstance3);
99 CompositionPage.showPropertiesAndAttributesTab();
100 PropertiesUIUtils.changePropertyDefaultValueInComposition("property_2", "customize derived");
101 PropertiesUIUtils.changePropertyDefaultValueInComposition("property_5", "customize new");
103 GeneralUIUtils.clickOnElementByTestId("breadcrumbs-button-1");
104 ResourceGeneralPage.getLeftMenu().moveToToscaArtifactsScreen();
105 GeneralUIUtils.clickOnElementByTestId(ToscaArtifactsScreenEnum.TOSCA_TEMPLATE.getValue());
107 // TODO: Replace it by automatic download to path
108 // TODO: After it remove
109 File path = new File("C:\\Users\\rp955r\\Desktop\\US\\US831517\\TCExport\\TC1459238.yml");
110 ToscaDefinition toscaDefinition = ToscaParserUtils.parseToscaYamlToJavaObject(path);
112 Map<String, Object> vl_us831517_1 = new HashMap<String, Object>();
113 vl_us831517_1.put("property_1", false);
114 vl_us831517_1.put("property_2", "init_value_2");
115 vl_us831517_1.put("property_3", "init_value_3");
118 Map<String, Object> vl_us831517_2 = new HashMap<String, Object>();
119 vl_us831517_2.put("property_1", false);
120 vl_us831517_2.put("property_2", "init_value_2");
121 vl_us831517_2.put("property_3", "customize");
123 Map<String, Object> vl_us831517_3 = new HashMap<String, Object>();
124 vl_us831517_3.put("property_1", true);
125 vl_us831517_3.put("property_2", "customize derived");
126 vl_us831517_3.put("property_3", "init_value_3");
127 vl_us831517_3.put("property_4", false);
128 vl_us831517_3.put("property_5", "customize new");
130 Map<String, Map<String, Object>> predefinedProperties = new HashMap<String, Map<String, Object>>();
131 predefinedProperties.put("VL_US831517_1", vl_us831517_1);
132 predefinedProperties.put("VL_US831517_2", vl_us831517_2);
133 predefinedProperties.put("VL_US831517_3", vl_us831517_3);
135 validateNodeTemplatesProperties(predefinedProperties, toscaDefinition);
137 RestCDUtils.deleteOnDemand();
140 @DataProvider(name="serviceVfUsedVlsCps")
141 public static Object[][] dataProviderServiceVfUsedVlsCps() {
142 return new Object[][] {
143 {"VL_US831517_1.yml", "VL_US831517_2.yml", "VL_US831517_3.yml", ResourceTypeEnum.VL, ComponentTypeEnum.SERVICE},
144 {"CP_US831517_1.yml", "CP_US831517_2.yml", "CP_US831517_3.yml", ResourceTypeEnum.CP, ComponentTypeEnum.SERVICE},
145 {"VL_US831517_1.yml", "VL_US831517_2.yml", "VL_US831517_3.yml", ResourceTypeEnum.VL, ComponentTypeEnum.RESOURCE},
146 {"CP_US831517_1.yml", "CP_US831517_2.yml", "CP_US831517_3.yml", ResourceTypeEnum.CP, ComponentTypeEnum.RESOURCE},
151 // US831517 - Story [BE] - Extend node_template properties with default values
152 @Test(dataProvider="serviceVfUsedVlsCps")
153 public void serviceVfUsedVlsCps(String fileName_vl1, String fileName_vl2, String fileName_vl3, ResourceTypeEnum resourceTypeEnum, ComponentTypeEnum componentTypeEnum) throws Exception {
154 setLog("Extend node_template properties with default values");
157 LinkedList<String> assetsName = importThreeAsset(fileName_vl1, fileName_vl2, fileName_vl3, resourceTypeEnum);
159 if(ComponentTypeEnum.SERVICE == componentTypeEnum) {
160 ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
161 ServiceUIUtils.createService(serviceMetadata, getUser());
163 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
164 ResourceUIUtils.createVF(resourceMetaData, getUser());
167 ResourceGeneralPage.getLeftMenu().moveToCompositionScreen();
168 CanvasManager canvasManager = CanvasManager.getCanvasManager();
169 canvasManager.createElementOnCanvas(assetsName.get(0));
170 canvasManager.createElementOnCanvas(assetsName.get(1));
171 canvasManager.createElementOnCanvas(assetsName.get(2));
173 GeneralUIUtils.clickOnElementByTestId("breadcrumbs-button-1");
174 ResourceGeneralPage.getLeftMenu().moveToToscaArtifactsScreen();
175 GeneralUIUtils.clickOnElementByTestId(ToscaArtifactsScreenEnum.TOSCA_TEMPLATE.getValue());
177 // TODO: Replace it by automatic download to path
178 // TODO: After it remove
179 File path = new File("C:\\Users\\rp955r\\Desktop\\US\\US831517\\TCExport\\TC1459238.yml");
180 ToscaDefinition toscaDefinition = ToscaParserUtils.parseToscaYamlToJavaObject(path);
182 Map<String, Object> vl_us831517_1 = new HashMap<String, Object>();
183 vl_us831517_1.put("property_1", true);
184 vl_us831517_1.put("property_2", "init_value_2");
185 vl_us831517_1.put("property_3", "init_value_3");
188 Map<String, Object> vl_us831517_2 = new HashMap<String, Object>();
189 vl_us831517_2.put("property_1", false);
190 vl_us831517_2.put("property_2", "init_value_2");
191 vl_us831517_2.put("property_3", "new_value_3");
193 Map<String, Object> vl_us831517_3 = new HashMap<String, Object>();
194 vl_us831517_3.put("property_1", true);
195 vl_us831517_3.put("property_2", "init_value_2");
196 vl_us831517_3.put("property_3", "init_value_3");
197 vl_us831517_3.put("property_4", false);
198 vl_us831517_3.put("property_5", "init_value_5");
200 Map<String, Map<String, Object>> predefinedProperties = new HashMap<String, Map<String, Object>>();
201 predefinedProperties.put("VL_US831517_1", vl_us831517_1);
202 predefinedProperties.put("VL_US831517_2", vl_us831517_2);
203 predefinedProperties.put("VL_US831517_3", vl_us831517_3);
205 validateNodeTemplatesProperties(predefinedProperties, toscaDefinition);
207 RestCDUtils.deleteOnDemand();
210 private LinkedList<String> importThreeAsset(String fileName_vl1, String fileName_vl2, String fileName_vl3, ResourceTypeEnum resourceTypeEnum) throws Exception {
211 LinkedList<String> assetsNames = new LinkedList<String>();
213 String filePath = System.getProperty("filepath");
214 if (filePath == null && System.getProperty("os.name").contains("Windows")) {
215 filePath = FileHandling.getResourcesFilesPath() + File.separator + "US831517" + File.separator;
217 else if(filePath.isEmpty() && !System.getProperty("os.name").contains("Windows")){
218 filePath = FileHandling.getBasePath() + File.separator + "Files" + File.separator + "US831517" + File.separator;
222 ResourceReqDetails resourceMetaDataVl1 = ElementFactory.getDefaultResourceByType(resourceTypeEnum, getUser());
223 assetsNames.add(resourceMetaDataVl1.getName());
224 ResourceUIUtils.importVfc(resourceMetaDataVl1, filePath, fileName_vl1, getUser());
225 GeneralPageElements.clickSubmitForTestingButton(resourceMetaDataVl1.getName());
226 reloginWithNewRole(UserRoleEnum.TESTER);
227 GeneralUIUtils.findComponentAndClick(resourceMetaDataVl1.getName());
228 TesterOperationPage.certifyComponent(resourceMetaDataVl1.getName());
229 reloginWithNewRole(UserRoleEnum.DESIGNER);
231 ResourceReqDetails resourceMetaDataVl2 = ElementFactory.getDefaultResourceByType(resourceTypeEnum, getUser());
232 assetsNames.add(resourceMetaDataVl2.getName());
233 ResourceUIUtils.importVfc(resourceMetaDataVl2, filePath, fileName_vl2, getUser());
234 GeneralPageElements.clickCheckinButton(resourceMetaDataVl2.getName());
236 ResourceReqDetails resourceMetaDataVl3 = ElementFactory.getDefaultResourceByType(resourceTypeEnum, getUser());
237 assetsNames.add(resourceMetaDataVl3.getName());
238 ResourceUIUtils.importVfc(resourceMetaDataVl3, filePath, fileName_vl3, getUser());
239 GeneralPageElements.clickCheckinButton(resourceMetaDataVl2.getName());
245 private static void validateNodeTemplatesProperties(Map<String, Map<String, Object>> predefinedMap, ToscaDefinition toscaDefinition) {
247 for(String key: predefinedMap.keySet()) {
248 Map<String, Object> nodeTemplateProperties = getNodeTemplatePropertiesByNodeTemplateType(key, toscaDefinition);
250 predefinedMap.get(key).forEach((i,j) -> {
251 Assert.assertEquals(nodeTemplateProperties.get(i), j, "Expected that the properties will be equal");
257 // Get properties by type
258 private static Map<String, Object> getNodeTemplatePropertiesByNodeTemplateType(String nodeTemplateType, ToscaDefinition toscaDefinition) {
259 Map<String, Object> propertiesMap = null;
261 Set<String> nodeTemplates = getNodeTemplates(toscaDefinition);
263 for(String nodeTemplate: nodeTemplates) {
264 String currentNodeTemplateType = getNodeTemplateType(toscaDefinition, nodeTemplate);
265 currentNodeTemplateType = currentNodeTemplateType.substring(currentNodeTemplateType.lastIndexOf(".") + 1);
266 if(currentNodeTemplateType.equals(nodeTemplateType)) {
267 propertiesMap = getNodeTemplateProperties(toscaDefinition, nodeTemplate);
272 return propertiesMap;
275 // Get node templates
276 private static Set<String> getNodeTemplates(ToscaDefinition toscaDefinition) {
277 Set<String> resourceInstanceArray = toscaDefinition.getTopology_template().getNode_templates().keySet();
278 return resourceInstanceArray;
281 // Get type of node template
282 private static String getNodeTemplateType(ToscaDefinition toscaDefinition, String nodeTemplate) {
283 return toscaDefinition.getTopology_template().getNode_templates().get(nodeTemplate).getType();
286 // Get properties of node template
287 private static Map<String, Object> getNodeTemplateProperties(ToscaDefinition toscaDefinition, String nodeTemplate) {
288 Map<String, Object> propertiesMap = toscaDefinition.getTopology_template().getNode_templates().get(nodeTemplate).getProperties();
289 return propertiesMap;
293 protected UserRoleEnum getRole() {
294 return UserRoleEnum.DESIGNER;