summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-heat-lib/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-heat-lib/src/test/java')
-rw-r--r--openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/EnvironmentTest.java38
-rw-r--r--openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/HeatOrchestrationTemplateTest.java122
2 files changed, 160 insertions, 0 deletions
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<String, Parameter> params = createParameters();
+ template.setParameters(params);
+ List<ParameterGroup> 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<String> paramsNames = new ArrayList<>();
+ paramsNames.add(paramName);
+ paramsGroup.setParameters(paramsNames);
+ parameterGroup.add(paramsGroup);
+ template.setParameter_groups(parameterGroup);
+ Map<String, Object> conditions = new HashMap<>();
+ conditions.put("key1", "val1");
+ HashMap<String, Object> mapValue = new HashMap<>();
+ mapValue.put("innerKey", "innerVal");
+ conditions.put("key2", mapValue);
+ template.setConditions(conditions);
+
+ Map<String, Resource> resources = new HashMap<>();
+ Resource resource = new Resource();
+ resource.setMetadata("resource metadata");
+ resource.setType("resource type");
+ //Map<String, String> resourceProps = new ;
+ Map<String, Object> 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<String> 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<String, Parameter> createParameters() {
+ Map<String, Parameter> 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<Constraint> createConstraints() {
+ List<Constraint> 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<Object> validValues = new ArrayList<>();
+ validValues.add("abc");
+ validValues.add("def");
+ constraint.setValid_values(validValues);
+ constraints.add(constraint);
+ return constraints;
+ }
+} \ No newline at end of file