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.heat.datatypes.model;
23 import org.junit.Assert;
24 import org.junit.Test;
25 import org.openecomp.core.utilities.yaml.YamlUtil;
27 import java.io.InputStream;
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 import java.util.List;
33 public class HeatOrchestrationTemplateTest {
36 public void testYamlToServiceTemplateObj() {
37 YamlUtil yamlUtil = new YamlUtil();
38 InputStream yamlFile = yamlUtil.loadYamlFileIs("/mock/model/testHeat.yml");
39 HeatOrchestrationTemplate heatOrchestrationTemplate =
40 yamlUtil.yamlToObject(yamlFile, HeatOrchestrationTemplate.class);
41 heatOrchestrationTemplate.toString();
45 public void createHotTemplate() {
46 HeatOrchestrationTemplate template = new HeatOrchestrationTemplate();
47 template.setHeat_template_version("2016-04-14");
48 template.setDescription("test description for hot template");
49 Map<String, Parameter> params = createParameters();
50 template.setParameters(params);
51 List<ParameterGroup> parameterGroup = new ArrayList<>();
52 ParameterGroup paramsGroup = new ParameterGroup();
53 paramsGroup.setDescription("params group test description");
54 paramsGroup.setLabel("params group test label");
55 String paramName = params.get("param1").getLabel();
56 List<String> paramsNames = new ArrayList<>();
57 paramsNames.add(paramName);
58 paramsGroup.setParameters(paramsNames);
59 parameterGroup.add(paramsGroup);
60 template.setParameter_groups(parameterGroup);
61 Map<String, Object> conditions = new HashMap<>();
62 conditions.put("key1", "val1");
63 HashMap<String, Object> mapValue = new HashMap<>();
64 mapValue.put("innerKey", "innerVal");
65 conditions.put("key2", mapValue);
66 template.setConditions(conditions);
68 Map<String, Resource> resources = new HashMap<>();
69 Resource resource = new Resource();
70 resource.setMetadata("resource metadata");
71 resource.setType("resource type");
72 //Map<String, String> resourceProps = new ;
73 Map<String, Object> resourceProps = new HashMap<>();
74 resourceProps.put("aaa", "bbb");
75 //resourceProps.add(resourceProp);
76 resource.setProperties(resourceProps);
77 resources.put("R1", resource);
78 resource = new Resource();
79 resource.setMetadata("resource2 metadata");
80 resource.setType("resource2 type");
81 //resourceProps = new ArrayList<>();
82 resourceProps = new HashMap<>();
83 resourceProps.put("aaa2", "bbb2");
84 //resourceProps.add(resourceProp);
85 resource.setProperties(resourceProps);
86 List<String> dependsOn = new ArrayList<>();
88 resource.setDepends_on(dependsOn);
89 resource.setDeletion_policy("all");
90 resource.setUpdate_policy("once");
91 resources.put("R2", resource);
92 template.setResources(resources);
94 YamlUtil yamlUtil = new YamlUtil();
95 String yml = yamlUtil.objectToYaml(template);
96 Assert.assertNotNull(yml);
98 HeatOrchestrationTemplate heatOrchestrationTemplate =
99 yamlUtil.yamlToObject(yml, HeatOrchestrationTemplate.class);
100 Assert.assertNotNull(heatOrchestrationTemplate);
101 } catch (Exception ignored) {
105 private Map<String, Parameter> createParameters() {
106 Map<String, Parameter> params = new HashMap<>();
108 for (int i = 0; i < 2; i++) {
109 param = new Parameter();
110 param.setDescription("param " + i + " desc");
111 param.setLabel("param " + i + " label");
112 param.set_default("PARAM " + i + " default");
113 param.setHidden(i % 2 == 0);
114 param.setImmutable(i % 2 == 0);
115 param.setType(i % 2 == 0 ? ParameterType.STRING.getDisplayName()
116 : ParameterType.BOOLEAN.getDisplayName());
117 params.put("param" + i, param);
123 private List<Constraint> createConstraints() {
124 List<Constraint> constraints = new ArrayList<>();
125 Constraint constraint = new Constraint();
126 constraint.setLength(new Integer[]{2, 4});
127 constraints.add(constraint);
128 constraint = new Constraint();
129 constraint.setPattern("some regex");
130 constraints.add(constraint);
131 constraint = new Constraint();
132 constraint.setRange(new Integer[]{5, 8});
133 constraints.add(constraint);
134 constraint = new Constraint();
135 List<Object> validValues = new ArrayList<>();
136 validValues.add("abc");
137 validValues.add("def");
138 constraint.setValidValues(validValues);
139 constraints.add(constraint);