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;
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;
31 import java.text.SimpleDateFormat;
32 import java.util.Date;
33 import java.util.HashMap;
42 public class Testing {
44 // public static void main(String[] args) throws Exception {
45 // // TODO Auto-generated method stub
47 // File path = new File("C:\\Users\\rp955r\\Desktop\\US\\US831517\\TCExport\\TC1459238.yml");
48 // ToscaDefinition toscaDefinition = ToscaParserUtils.parseToscaYamlToJavaObject(path);
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");
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");
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");
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);
73 // validateNodeTemplatesProperties(predefinedProperties, toscaDefinition);
81 private static void validateNodeTemplatesProperties(Map<String, Map<String, Object>> predefinedMap, ToscaDefinition toscaDefinition) {
83 for(String key: predefinedMap.keySet()) {
84 Map<String, Object> nodeTemplateProperties = getNodeTemplatePropertiesByNodeTemplateType(key, toscaDefinition);
86 predefinedMap.get(key).forEach((i,j) -> {
87 Assert.assertEquals(nodeTemplateProperties.get(i), j, "Expected that the properties will be equal");
93 // Get properties by type
94 private static Map<String, Object> getNodeTemplatePropertiesByNodeTemplateType(String nodeTemplateType, ToscaDefinition toscaDefinition) {
95 Map<String, Object> propertiesMap = null;
97 Set<String> nodeTemplates = getNodeTemplates(toscaDefinition);
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);
108 return propertiesMap;
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;
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();
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;
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/");
151 File dataTypesLocation = new File(importToscaFilesFolder.getPath() + "/data-types/dataTypes.yml");
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");
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");
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()));
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);
171 Map<String, Object> additionalInputs = new HashMap<>();
172 Set<String> keySet = objectHelper.getNode_types().keySet();
174 for(String key: keySet){
175 additionalInputs = objectHelper.getNode_types().get(key).getProperties();
178 // topologyTemplate.addInputs(additionalInputs);
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();
195 System.out.println("Finished");
196 System.out.println("get service start " + new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date()));