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