From f5f13c4f6b6fe3b4d98e349dfd7db59339803436 Mon Sep 17 00:00:00 2001 From: Michael Lando Date: Sun, 19 Feb 2017 12:35:04 +0200 Subject: push addional code Change-Id: Ia427bb3460cda3a896f8faced2de69eaf3807b74 Signed-off-by: Michael Lando --- .../sdc/heat/datatypes/model/EnvironmentTest.java | 38 +++++++ .../model/HeatOrchestrationTemplateTest.java | 122 +++++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/EnvironmentTest.java create mode 100644 openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/HeatOrchestrationTemplateTest.java (limited to 'openecomp-be/lib/openecomp-heat-lib/src/test/java/org') diff --git a/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/EnvironmentTest.java b/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/EnvironmentTest.java new file mode 100644 index 0000000000..2c0cf0b1aa --- /dev/null +++ b/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/EnvironmentTest.java @@ -0,0 +1,38 @@ +package org.openecomp.sdc.heat.datatypes.model; + +import org.openecomp.core.utilities.yaml.YamlUtil; +import org.junit.Test; + +import java.io.InputStream; + +public class EnvironmentTest { + + @Test + public void testYamlToServiceTemplateObj() { + YamlUtil yamlUtil = new YamlUtil(); + InputStream yamlFile = yamlUtil.loadYamlFileIs("/mock/model/envSettings.env"); + Environment envVars = yamlUtil.yamlToObject(yamlFile, Environment.class); + envVars.toString(); + } + + @Test + public void test() { + String heatResourceName = "server_abc_0u"; + String novaServerPrefix = "server_"; + if (heatResourceName.startsWith(novaServerPrefix)) { + heatResourceName = heatResourceName.substring(novaServerPrefix.length()); + } + int lastIndexOfUnderscore = heatResourceName.lastIndexOf("_"); + if (heatResourceName.length() == lastIndexOfUnderscore) { + System.out.println(heatResourceName); + } else { + String heatResourceNameSuffix = heatResourceName.substring(lastIndexOfUnderscore + 1); + try { + Integer.parseInt(heatResourceNameSuffix); + System.out.println(heatResourceName.substring(0, lastIndexOfUnderscore)); + } catch (NumberFormatException ignored) { + System.out.println(heatResourceName); + } + } + } +} \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/HeatOrchestrationTemplateTest.java b/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/HeatOrchestrationTemplateTest.java new file mode 100644 index 0000000000..09c83ca217 --- /dev/null +++ b/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/HeatOrchestrationTemplateTest.java @@ -0,0 +1,122 @@ +package org.openecomp.sdc.heat.datatypes.model; + +import org.openecomp.core.utilities.yaml.YamlUtil; +import org.junit.Assert; +import org.junit.Test; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class HeatOrchestrationTemplateTest { + + @Test + public void testYamlToServiceTemplateObj() { + YamlUtil yamlUtil = new YamlUtil(); + InputStream yamlFile = yamlUtil.loadYamlFileIs("/mock/model/testHeat.yml"); + HeatOrchestrationTemplate heatOrchestrationTemplate = + yamlUtil.yamlToObject(yamlFile, HeatOrchestrationTemplate.class); + heatOrchestrationTemplate.toString(); + } + + @Test + public void createHotTemplate() { + HeatOrchestrationTemplate template = new HeatOrchestrationTemplate(); + template.setHeat_template_version("2016-04-14"); + template.setDescription("test description for hot template"); + Map params = createParameters(); + template.setParameters(params); + List parameterGroup = new ArrayList<>(); + ParameterGroup paramsGroup = new ParameterGroup(); + paramsGroup.setDescription("params group test description"); + paramsGroup.setLabel("params group test label"); + String paramName = params.get("param1").getLabel(); + List paramsNames = new ArrayList<>(); + paramsNames.add(paramName); + paramsGroup.setParameters(paramsNames); + parameterGroup.add(paramsGroup); + template.setParameter_groups(parameterGroup); + Map conditions = new HashMap<>(); + conditions.put("key1", "val1"); + HashMap mapValue = new HashMap<>(); + mapValue.put("innerKey", "innerVal"); + conditions.put("key2", mapValue); + template.setConditions(conditions); + + Map resources = new HashMap<>(); + Resource resource = new Resource(); + resource.setMetadata("resource metadata"); + resource.setType("resource type"); + //Map resourceProps = new ; + Map resourceProps = new HashMap<>(); + resourceProps.put("aaa", "bbb"); + //resourceProps.add(resourceProp); + resource.setProperties(resourceProps); + resources.put("R1", resource); + resource = new Resource(); + resource.setMetadata("resource2 metadata"); + resource.setType("resource2 type"); + //resourceProps = new ArrayList<>(); + resourceProps = new HashMap<>(); + resourceProps.put("aaa2", "bbb2"); + //resourceProps.add(resourceProp); + resource.setProperties(resourceProps); + List dependsOn = new ArrayList<>(); + dependsOn.add("R1"); + resource.setDepends_on(dependsOn); + resource.setDeletion_policy("all"); + resource.setUpdate_policy("once"); + resources.put("R2", resource); + template.setResources(resources); + + YamlUtil yamlUtil = new YamlUtil(); + String yml = yamlUtil.objectToYaml(template); + Assert.assertNotNull(yml); + try { + HeatOrchestrationTemplate heatOrchestrationTemplate = + yamlUtil.yamlToObject(yml, HeatOrchestrationTemplate.class); + Assert.assertNotNull(heatOrchestrationTemplate); + } catch (Exception ignored) { + } + } + + private Map createParameters() { + Map params = new HashMap<>(); + Parameter param; + for (int i = 0; i < 2; i++) { + param = new Parameter(); + param.setDescription("param " + i + " desc"); + param.setLabel("param " + i + " label"); + param.set_default("PARAM " + i + " default"); + param.setHidden(i % 2 == 0); + param.setImmutable(i % 2 == 0); + param.setType(i % 2 == 0 ? ParameterType.STRING.getDisplayName() + : ParameterType.BOOLEAN.getDisplayName()); + params.put("param" + i, param); + } + + return params; + } + + private List createConstraints() { + List constraints = new ArrayList<>(); + Constraint constraint = new Constraint(); + constraint.setLength(new Integer[]{2, 4}); + constraints.add(constraint); + constraint = new Constraint(); + constraint.setPattern("some regex"); + constraints.add(constraint); + constraint = new Constraint(); + constraint.setRange(new Integer[]{5, 8}); + constraints.add(constraint); + constraint = new Constraint(); + List validValues = new ArrayList<>(); + validValues.add("abc"); + validValues.add("def"); + constraint.setValid_values(validValues); + constraints.add(constraint); + return constraints; + } +} \ No newline at end of file -- cgit 1.2.3-korg