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.text.SimpleDateFormat;
25 import java.util.Arrays;
26 import java.util.Date;
27 import java.util.HashMap;
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;
45 public class Testing {
47 // public static void main(String[] args) throws Exception {
48 // // TODO Auto-generated method stub
50 // File path = new File("C:\\Users\\rp955r\\Desktop\\US\\US831517\\TCExport\\TC1459238.yml");
51 // ToscaDefinition toscaDefinition = ToscaParserUtils.parseToscaYamlToJavaObject(path);
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");
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");
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");
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);
76 // validateNodeTemplatesProperties(predefinedProperties, toscaDefinition);
84 private static void validateNodeTemplatesProperties(Map<String, Map<String, Object>> predefinedMap, ToscaDefinition toscaDefinition) {
86 for(String key: predefinedMap.keySet()) {
87 Map<String, Object> nodeTemplateProperties = getNodeTemplatePropertiesByNodeTemplateType(key, toscaDefinition);
89 predefinedMap.get(key).forEach((i,j) -> {
90 Assert.assertEquals(nodeTemplateProperties.get(i), j, "Expected that the properties will be equal");
96 // Get properties by type
97 private static Map<String, Object> getNodeTemplatePropertiesByNodeTemplateType(String nodeTemplateType, ToscaDefinition toscaDefinition) {
98 Map<String, Object> propertiesMap = null;
100 Set<String> nodeTemplates = getNodeTemplates(toscaDefinition);
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);
111 return propertiesMap;
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;
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();
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;
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/");
154 File dataTypesLocation = new File(importToscaFilesFolder.getPath() + "/data-types/dataTypes.yml");
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");
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");
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()));
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);
174 Map<String, Object> additionalInputs = new HashMap<>();
175 Set<String> keySet = objectHelper.getNode_types().keySet();
177 for(String key: keySet){
178 additionalInputs = objectHelper.getNode_types().get(key).getProperties();
181 // topologyTemplate.addInputs(additionalInputs);
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();
198 System.out.println("Finished");
199 System.out.println("get service start " + new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date()));