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;
28 import org.openecomp.sdc.ci.tests.tosca.datatypes.ToscaDefinition;
29 import org.openecomp.sdc.ci.tests.utils.ToscaParserUtils;
30 import org.testng.Assert;
37 public class Testing {
39 public static void main(String[] args) throws Exception {
40 // TODO Auto-generated method stub
42 File path = new File("C:\\Users\\rp955r\\Desktop\\US\\US831517\\TCExport\\TC1459238.yml");
43 ToscaDefinition toscaDefinition = ToscaParserUtils.parseToscaYamlToJavaObject(path);
45 Map<String, Object> vl_us831517_1 = new HashMap<String, Object>();
46 vl_us831517_1.put("property_1", true);
47 vl_us831517_1.put("property_2", "init_value_2");
48 vl_us831517_1.put("property_3", "init_value_3");
51 Map<String, Object> vl_us831517_2 = new HashMap<String, Object>();
52 vl_us831517_2.put("property_1", false);
53 vl_us831517_2.put("property_2", "init_value_2");
54 vl_us831517_2.put("property_3", "new_value_3");
56 Map<String, Object> vl_us831517_3 = new HashMap<String, Object>();
57 vl_us831517_3.put("property_1", true);
58 vl_us831517_3.put("property_2", "init_value_2");
59 vl_us831517_3.put("property_3", "init_value_3");
60 vl_us831517_3.put("property_4", false);
61 vl_us831517_3.put("property_5", "init_value_5");
63 Map<String, Map<String, Object>> predefinedProperties = new HashMap<String, Map<String, Object>>();
64 predefinedProperties.put("VL_US831517_1", vl_us831517_1);
65 predefinedProperties.put("VL_US831517_2", vl_us831517_2);
66 predefinedProperties.put("VL_US831517_3", vl_us831517_3);
68 validateNodeTemplatesProperties(predefinedProperties, toscaDefinition);
76 private static void validateNodeTemplatesProperties(Map<String, Map<String, Object>> predefinedMap, ToscaDefinition toscaDefinition) {
78 for(String key: predefinedMap.keySet()) {
79 Map<String, Object> nodeTemplateProperties = getNodeTemplatePropertiesByNodeTemplateType(key, toscaDefinition);
81 predefinedMap.get(key).forEach((i,j) -> {
82 Assert.assertEquals(nodeTemplateProperties.get(i), j, "Expected that the properties will be equal");
88 // Get properties by type
89 private static Map<String, Object> getNodeTemplatePropertiesByNodeTemplateType(String nodeTemplateType, ToscaDefinition toscaDefinition) {
90 Map<String, Object> propertiesMap = null;
92 Set<String> nodeTemplates = getNodeTemplates(toscaDefinition);
94 for(String nodeTemplate: nodeTemplates) {
95 String currentNodeTemplateType = getNodeTemplateType(toscaDefinition, nodeTemplate);
96 currentNodeTemplateType = currentNodeTemplateType.substring(currentNodeTemplateType.lastIndexOf(".") + 1);
97 if(currentNodeTemplateType.equals(nodeTemplateType)) {
98 propertiesMap = getNodeTemplateProperties(toscaDefinition, nodeTemplate);
103 return propertiesMap;
106 // Get node templates
107 private static Set<String> getNodeTemplates(ToscaDefinition toscaDefinition) {
108 Set<String> resourceInstanceArray = toscaDefinition.getTopology_template().getNode_templates().keySet();
109 return resourceInstanceArray;
112 // Get type of node template
113 private static String getNodeTemplateType(ToscaDefinition toscaDefinition, String nodeTemplate) {
114 return toscaDefinition.getTopology_template().getNode_templates().get(nodeTemplate).getType();
117 // Get properties of node template
118 private static Map<String, Object> getNodeTemplateProperties(ToscaDefinition toscaDefinition, String nodeTemplate) {
119 Map<String, Object> propertiesMap = toscaDefinition.getTopology_template().getNode_templates().get(nodeTemplate).getProperties();
120 return propertiesMap;