re base code
[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 org.openecomp.sdc.be.model.DataTypeDefinition;
24 import org.openecomp.sdc.ci.tests.tosca.datatypes.ToscaDefinition;
25 import org.openecomp.sdc.ci.tests.tosca.datatypes.ToscaTopologyTemplateDefinition;
26 import org.openecomp.sdc.ci.tests.utilities.FileHandling;
27 import org.openecomp.sdc.ci.tests.utils.ToscaParserUtils;
28 import org.testng.Assert;
29
30 import java.io.File;
31 import java.text.SimpleDateFormat;
32 import java.util.Date;
33 import java.util.HashMap;
34 import java.util.Map;
35 import java.util.Set;
36
37
38
39
40
41
42 public class Testing {
43
44 //      public static void main(String[] args) throws Exception {
45 //              // TODO Auto-generated method stub
46 //
47 //              File path = new File("C:\\Users\\rp955r\\Desktop\\US\\US831517\\TCExport\\TC1459238.yml");
48 //              ToscaDefinition toscaDefinition = ToscaParserUtils.parseToscaYamlToJavaObject(path);
49 //              
50 //              Map<String, Object> vl_us831517_1 = new HashMap<String, Object>();
51 //              vl_us831517_1.put("property_1", true);
52 //              vl_us831517_1.put("property_2", "init_value_2");
53 //              vl_us831517_1.put("property_3", "init_value_3");
54 //              
55 //              
56 //              Map<String, Object> vl_us831517_2 = new HashMap<String, Object>();
57 //              vl_us831517_2.put("property_1", false);
58 //              vl_us831517_2.put("property_2", "init_value_2");
59 //              vl_us831517_2.put("property_3", "new_value_3");
60 //              
61 //              Map<String, Object> vl_us831517_3 = new HashMap<String, Object>();
62 //              vl_us831517_3.put("property_1", true);
63 //              vl_us831517_3.put("property_2", "init_value_2");
64 //              vl_us831517_3.put("property_3", "init_value_3");
65 //              vl_us831517_3.put("property_4", false);
66 //              vl_us831517_3.put("property_5", "init_value_5");
67 //              
68 //              Map<String, Map<String, Object>> predefinedProperties = new HashMap<String, Map<String, Object>>();
69 //              predefinedProperties.put("VL_US831517_1", vl_us831517_1);
70 //              predefinedProperties.put("VL_US831517_2", vl_us831517_2);
71 //              predefinedProperties.put("VL_US831517_3", vl_us831517_3);
72 //              
73 //              validateNodeTemplatesProperties(predefinedProperties, toscaDefinition);
74 //              
75 //              
76 //              
77 //      }
78         
79         
80         
81         private static void validateNodeTemplatesProperties(Map<String, Map<String, Object>> predefinedMap, ToscaDefinition toscaDefinition) {
82                 
83                 for(String key: predefinedMap.keySet()) {
84                         Map<String, Object> nodeTemplateProperties = getNodeTemplatePropertiesByNodeTemplateType(key, toscaDefinition);
85                         
86                         predefinedMap.get(key).forEach((i,j) -> {
87                                 Assert.assertEquals(nodeTemplateProperties.get(i), j, "Expected that the properties will be equal");
88                         });
89                 }
90
91         }
92         
93         // Get properties by type
94         private static Map<String, Object> getNodeTemplatePropertiesByNodeTemplateType(String nodeTemplateType, ToscaDefinition toscaDefinition) {
95                 Map<String, Object> propertiesMap = null;
96                 
97                 Set<String> nodeTemplates = getNodeTemplates(toscaDefinition);
98                 
99                 for(String nodeTemplate: nodeTemplates) {
100                         String currentNodeTemplateType = getNodeTemplateType(toscaDefinition, nodeTemplate);
101                         currentNodeTemplateType = currentNodeTemplateType.substring(currentNodeTemplateType.lastIndexOf(".") + 1);
102                         if(currentNodeTemplateType.equals(nodeTemplateType)) {
103                                 propertiesMap = getNodeTemplateProperties(toscaDefinition, nodeTemplate);
104                                 break;
105                         }
106                 }
107                 
108                 return propertiesMap;
109         }
110         
111         // Get node templates
112         private static Set<String> getNodeTemplates(ToscaDefinition toscaDefinition) {
113                 Set<String> resourceInstanceArray = toscaDefinition.getTopology_template().getNode_templates().keySet();
114                 return resourceInstanceArray;
115         }
116         
117         // Get type of node template
118         private static String getNodeTemplateType(ToscaDefinition toscaDefinition, String nodeTemplate) {
119                 return toscaDefinition.getTopology_template().getNode_templates().get(nodeTemplate).getType();
120         }
121         
122         // Get properties of node template
123         private static Map<String, Object> getNodeTemplateProperties(ToscaDefinition toscaDefinition, String nodeTemplate) {
124                 Map<String, Object> propertiesMap = toscaDefinition.getTopology_template().getNode_templates().get(nodeTemplate).getProperties();
125                 return propertiesMap;
126         }
127         
128         
129         
130         
131         
132         
133         
134         
135         
136         
137         
138         
139         
140         
141         
142         
143         
144         
145         
146         public static void main(String[] args) throws Exception {
147                 ToscaDefinition toscaMainAmdocsDefinition, toscaMainVfDefinition, toscaMainServiceDefinition;
148                 File filesFolder = new File("C:/Users/al714h/Downloads/Design/");
149                 File importToscaFilesFolder = new File("C:/Git_work/sdc/catalog-be/src/main/resources/import/tosca/");
150         
151                 File dataTypesLocation = new File(importToscaFilesFolder.getPath() + "/data-types/dataTypes.yml");
152         
153                 File genericVfFileLocation = new File(importToscaFilesFolder.getPath() + "/heat-types/Generic_VF/Generic_VF.yml");
154                 File genericVfcFileLocation = new File (importToscaFilesFolder.getPath() + "/heat-types/Generic_VFC/Generic_VFC.yml");
155                 File genericPnfFileLocation = new File (importToscaFilesFolder.getPath() + "/heat-types/Generic_PNF/Generic_PNF.yml");
156                 File genericServiceFileLocation = new File (importToscaFilesFolder.getPath() + "/heat-types/Generic_Service/Generic_Service.yml");
157         
158                 File amdocsCsarFileName = new File("/77e6b842669f441db20a83489da3f4be.csar");
159                 File VfCsarFileName = new File("/resource-Civfonboarded2016012VmxAv301072E2e1424cb9d-csar.csar");
160                 File serviceCsarFileName = new File("/service-Ciservicefeba0521131d-csar.csar");
161                 
162                 Map<String, DataTypeDefinition> parseDataTypesYaml = FileHandling.parseDataTypesYaml(dataTypesLocation.getAbsoluteFile().toString());
163                 System.out.println("start " + new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date()));
164                 
165                 toscaMainAmdocsDefinition = ToscaParserUtils.parseToscaMainYamlToJavaObjectByCsarLocation(new File(filesFolder.getPath() + amdocsCsarFileName));
166                 toscaMainVfDefinition = ToscaParserUtils.parseToscaMainYamlToJavaObjectByCsarLocation(new File(filesFolder.getPath() + VfCsarFileName));
167                 toscaMainServiceDefinition = ToscaParserUtils.parseToscaMainYamlToJavaObjectByCsarLocation(new File(filesFolder.getPath() + serviceCsarFileName));
168                 ToscaTopologyTemplateDefinition topologyTemplate = toscaMainAmdocsDefinition.getTopology_template();
169                 ToscaDefinition objectHelper = ToscaParserUtils.parseToscaYamlToJavaObject(genericVfFileLocation);
170                 
171                 Map<String, Object> additionalInputs = new HashMap<>();
172                 Set<String> keySet = objectHelper.getNode_types().keySet();
173                 if(keySet != null){
174                         for(String key: keySet){
175                                 additionalInputs = objectHelper.getNode_types().get(key).getProperties();
176                         }
177                 }
178 //              topologyTemplate.addInputs(additionalInputs);
179
180                 
181                 
182                 
183 //        toscaDefinition = ToscaParserUtils.parseToscaYamlToJavaObject(path);
184         System.out.println("listTypeHeatMetaDefinition start " + new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date()));
185 //        List<TypeHeatMetaDefinition> listTypeHeatMetaDefinition = CsarParserUtils.getListTypeHeatMetaDefinition(csarPath);
186         System.out.println("get service start " + new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date()));
187 //        System.out.println(listTypeHeatMetaDefinition);
188 //        for(TypeHeatMetaDefinition typeHeatMetaDefinition : listTypeHeatMetaDefinition){
189 //              for(GroupHeatMetaDefinition groupHeatMetaDefinition : typeHeatMetaDefinition.getGroupHeatMetaDefinition()){
190 //                      List<HeatMetaFirstLevelDefinition> artifactList = groupHeatMetaDefinition.getArtifactList();
191 //                      boolean isBase = groupHeatMetaDefinition.getPropertyHeatMetaDefinition().getValue();
192 //              }
193 //              
194 //        }
195         System.out.println("Finished");
196         System.out.println("get service start " + new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date()));
197         
198         
199     
200         }
201
202         
203         
204
205 }