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.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;
58 public class extendNode_TemplatePropertiesWithDefaultValues extends SetupCDTest {
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},
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");
76 LinkedList<String> assetsName = importThreeAsset(fileName_vl1, fileName_vl2, fileName_vl3, resourceTypeEnum);
78 if(ComponentTypeEnum.SERVICE == componentTypeEnum) {
79 ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
80 ServiceUIUtils.createService(serviceMetadata, getUser());
82 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
83 ResourceUIUtils.createResource(resourceMetaData, getUser());
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));
92 canvasManager.clickOnCanvaElement(resourceInstance1);
93 CompositionPage.showPropertiesAndAttributesTab();
94 PropertiesUIUtils.changePropertyDefaultValueInComposition("property_1", "false");
96 canvasManager.clickOnCanvaElement(resourceInstance2);
97 CompositionPage.showPropertiesAndAttributesTab();
98 PropertiesUIUtils.changePropertyDefaultValueInComposition("property_3", "customize");
100 canvasManager.clickOnCanvaElement(resourceInstance3);
101 CompositionPage.showPropertiesAndAttributesTab();
102 PropertiesUIUtils.changePropertyDefaultValueInComposition("property_2", "customize derived");
103 PropertiesUIUtils.changePropertyDefaultValueInComposition("property_5", "customize new");
105 GeneralUIUtils.clickOnElementByTestId("breadcrumbs-button-1");
106 ResourceGeneralPage.getLeftMenu().moveToToscaArtifactsScreen();
107 GeneralUIUtils.clickOnElementByTestId(ToscaArtifactsScreenEnum.TOSCA_TEMPLATE.getValue());
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);
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");
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");
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");
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);
137 validateNodeTemplatesProperties(predefinedProperties, toscaDefinition);
139 RestCDUtils.deleteOnDemand();
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},
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");
159 LinkedList<String> assetsName = importThreeAsset(fileName_vl1, fileName_vl2, fileName_vl3, resourceTypeEnum);
161 if(ComponentTypeEnum.SERVICE == componentTypeEnum) {
162 ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
163 ServiceUIUtils.createService(serviceMetadata, getUser());
165 ResourceReqDetails resourceMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
166 ResourceUIUtils.createResource(resourceMetaData, getUser());
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));
175 GeneralUIUtils.clickOnElementByTestId("breadcrumbs-button-1");
176 ResourceGeneralPage.getLeftMenu().moveToToscaArtifactsScreen();
177 GeneralUIUtils.clickOnElementByTestId(ToscaArtifactsScreenEnum.TOSCA_TEMPLATE.getValue());
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);
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");
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");
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");
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);
207 validateNodeTemplatesProperties(predefinedProperties, toscaDefinition);
209 RestCDUtils.deleteOnDemand();
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>();
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;
219 else if(filePath.isEmpty() && !System.getProperty("os.name").contains("Windows")){
220 filePath = FileHandling.getBasePath() + File.separator + "Files" + File.separator + "US831517" + File.separator;
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);
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());
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());
247 private static void validateNodeTemplatesProperties(Map<String, Map<String, Object>> predefinedMap, ToscaDefinition toscaDefinition) {
249 for(String key: predefinedMap.keySet()) {
250 Map<String, Object> nodeTemplateProperties = getNodeTemplatePropertiesByNodeTemplateType(key, toscaDefinition);
252 predefinedMap.get(key).forEach((i,j) -> {
253 Assert.assertEquals(nodeTemplateProperties.get(i), j, "Expected that the properties will be equal");
259 // Get properties by type
260 private static Map<String, Object> getNodeTemplatePropertiesByNodeTemplateType(String nodeTemplateType, ToscaDefinition toscaDefinition) {
261 Map<String, Object> propertiesMap = null;
263 Set<String> nodeTemplates = getNodeTemplates(toscaDefinition);
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);
274 return propertiesMap;
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;
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();
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;
295 protected UserRoleEnum getRole() {
296 return UserRoleEnum.DESIGNER;