1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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;
}
}
|