[SDC-29] rebase continue work to align source
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / US / Testing.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 java.io.File;
24 import java.util.HashMap;
25 import java.util.Map;
26 import java.util.Set;
27
28 import org.openecomp.sdc.ci.tests.tosca.datatypes.ToscaDefinition;
29 import org.openecomp.sdc.ci.tests.utils.ToscaParserUtils;
30 import org.testng.Assert;
31
32
33
34
35
36
37 public class Testing {
38
39         public static void main(String[] args) throws Exception {
40                 // TODO Auto-generated method stub
41
42                 File path = new File("C:\\Users\\rp955r\\Desktop\\US\\US831517\\TCExport\\TC1459238.yml");
43                 ToscaDefinition toscaDefinition = ToscaParserUtils.parseToscaYamlToJavaObject(path);
44                 
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");
49                 
50                 
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");
55                 
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");
62                 
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);
67                 
68                 validateNodeTemplatesProperties(predefinedProperties, toscaDefinition);
69                 
70                 
71                 
72         }
73         
74         
75         
76         private static void validateNodeTemplatesProperties(Map<String, Map<String, Object>> predefinedMap, ToscaDefinition toscaDefinition) {
77                 
78                 for(String key: predefinedMap.keySet()) {
79                         Map<String, Object> nodeTemplateProperties = getNodeTemplatePropertiesByNodeTemplateType(key, toscaDefinition);
80                         
81                         predefinedMap.get(key).forEach((i,j) -> {
82                                 Assert.assertEquals(nodeTemplateProperties.get(i), j, "Expected that the properties will be equal");
83                         });
84                 }
85
86         }
87         
88         // Get properties by type
89         private static Map<String, Object> getNodeTemplatePropertiesByNodeTemplateType(String nodeTemplateType, ToscaDefinition toscaDefinition) {
90                 Map<String, Object> propertiesMap = null;
91                 
92                 Set<String> nodeTemplates = getNodeTemplates(toscaDefinition);
93                 
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);
99                                 break;
100                         }
101                 }
102                 
103                 return propertiesMap;
104         }
105         
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;
110         }
111         
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();
115         }
116         
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;
121         }
122         
123         
124
125 }