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.validation.impl.validators;
24 import org.openecomp.sdc.validation.Validator;
25 import org.openecomp.core.validation.types.MessageContainer;
26 import org.openecomp.sdc.validation.util.ValidationTestUtil;
27 import org.testng.Assert;
28 import org.testng.annotations.Test;
30 import java.io.IOException;
34 public class HeatValidatorTest {
37 private Validator validator = new HeatValidator();
40 public void testInvalidHeatFormat() {
41 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
42 "/org/openecomp/validation/validators/heat_validator/invalid_heat_format/negative_test/input");
44 Assert.assertNotNull(messages);
45 Assert.assertEquals(messages.size(), 1);
47 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 1);
49 messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
50 "ERROR: Invalid HEAT format problem - [Cannot create property=kuku for JavaBean=Resource{type='null', properties=null, metadata=null, depends_on=null, update_policy='null', deletion_policy='null'}\n" +
51 " in 'reader', line 25, column 5:\n" +
54 "Unable to find property 'kuku' on class: org.openecomp.sdc.heat.datatypes.model.Resource\n" +
55 " in 'reader', line 25, column 11:\n" +
62 public void testDependsOn() {
63 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
64 "/org/openecomp/validation/validators/heat_validator/depends_on_points_to_existing_resource/input");
66 Assert.assertNotNull(messages);
67 Assert.assertEquals(messages.size(), 1);
69 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 2);
71 messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
72 "ERROR: a Missing resource in depend On, Missing Resource ID [resource_not_exist]");
74 messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(1).getMessage(),
75 "ERROR: a Missing resource in depend On, Missing Resource ID [resource_3]");
80 public void testResourcesReferencesExistInHeat() throws IOException {
81 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(new HeatValidator(),
82 "/org/openecomp/validation/validators/heat_validator/resource_references_exist_in_heat/negative_test/input");
84 Assert.assertNotNull(messages);
85 Assert.assertEquals(messages.size(), 1);
87 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 2);
89 messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
90 "ERROR: Referenced resource - not_existing_resource not found");
92 messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(1).getMessage(),
93 "ERROR: invalid get_resource syntax is in use - null , get_resource function should get the resource id of the referenced resource");
98 public void testGetResourceValueIsValid() {
99 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(new HeatValidator(),
100 "/org/openecomp/validation/validators/heat_validator/get_resource_value_valid/negative_test/input");
102 Assert.assertNotNull(messages);
103 Assert.assertEquals(messages.size(), 1);
105 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 3);
107 messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
108 "ERROR: invalid get_resource syntax is in use - [param_1, param_2] , get_resource function should get the resource id of the referenced resource");
110 messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(1).getMessage(),
111 "ERROR: invalid get_resource syntax is in use - {get_param=param_1} , get_resource function should get the resource id of the referenced resource");
113 messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(2).getMessage(),
114 "ERROR: invalid get_resource syntax is in use - null , get_resource function should get the resource id of the referenced resource");
118 public void testTwoResourcesDoesNotHoldSameId() throws IOException {
119 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(new HeatValidator(),
120 "/org/openecomp/validation/validators/heat_validator/two_resources_does_not_hold_same_id/positive_test/input");
121 Assert.assertNotNull(messages);
122 Assert.assertEquals(messages.size(), 0);
126 public void negativeTestGetParamPointToExistingParameter() throws IOException {
127 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(new HeatValidator(),
128 "/org/openecomp/validation/validators/heat_validator/get_param_points_to_existing_parameter/negative_test/input");
130 Assert.assertNotNull(messages);
131 Assert.assertEquals(messages.size(), 1);
133 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 1);
135 messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
136 "ERROR: Referenced parameter - not_existing_param_1 - not found, used in resource [server_pcrf_psm_001]");
140 public void testGetAttrFromNested() throws IOException {
141 Map<String, MessageContainer> messages =ValidationTestUtil.testValidator(new HeatValidator(),
142 "/org/openecomp/validation/validators/heat_validator/get_attr_from_nested/negative_test/input");
144 Assert.assertNotNull(messages);
145 Assert.assertEquals(messages.size(), 1);
147 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 1);
149 messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
150 "ERROR: get_attr attribute not found, Attribute name [nested_output], Resource ID [server_pcrf_psm_001]");
154 public void testDefaultValueAlignWithType() throws IOException {
155 Map<String, MessageContainer> messages =ValidationTestUtil.testValidator(new HeatValidator(),
156 "/org/openecomp/validation/validators/heat_validator/default_value_align_with_type/negative_test/input");
158 Assert.assertNotNull(messages);
159 Assert.assertEquals(messages.size(), 1);
161 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 1);
163 messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
164 "ERROR: Parameter - pcrf_pps_image_name_1 default value not align with type number");
169 public void testEnvParametersMatchDefinedHeatParameterTypes() throws IOException {
170 Map<String, MessageContainer> messages =ValidationTestUtil.testValidator(new HeatValidator(),
171 "/org/openecomp/validation/validators/heat_validator/env_parameters_match_defined_types/negative_test/input");
173 Assert.assertNotNull(messages);
174 Assert.assertEquals(messages.size(), 1);
176 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.env").getErrorMessageList().size(), 1);
178 messages.get("hot-nimbus-pps_v1.0.env").getErrorMessageList().get(0).getMessage(),
179 "ERROR: Parameter env value pcrf_pps_flavor_name not align with type");
184 public void testReferencedArtifactsExist() throws IOException {
185 Map<String, MessageContainer> messages =ValidationTestUtil.testValidator(new HeatValidator(),
186 "/org/openecomp/validation/validators/heat_validator/referenced_artifacts_exist/negative_test/input");
188 Assert.assertNotNull(messages);
189 Assert.assertEquals(messages.size(), 1);
191 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 1);
193 messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
194 "ERROR: Missing artifact - nimbus-ethernet");
199 public void testEnvContentIsSubSetOfHeatParameters() throws IOException {
200 Map<String, MessageContainer> messages =ValidationTestUtil.testValidator(validator,
201 "/org/openecomp/validation/validators/heat_validator/env_content_is_subset_of_heat/negative_test/input");
203 Assert.assertNotNull(messages);
204 Assert.assertEquals(messages.size(), 1);
206 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.env").getErrorMessageList().size(), 1);
208 messages.get("hot-nimbus-pps_v1.0.env").getErrorMessageList().get(0).getMessage(),
209 "ERROR: Env file hot-nimbus-pps_v1.0.env includes a parameter not in HEAT - mock_param");
213 public void testGetParamPseudoParameters() {
214 Map<String, MessageContainer> messages =ValidationTestUtil.testValidator(new HeatValidator(),
215 "/org/openecomp/validation/validators/heat_validator/pseudo_parameters/input");
217 Assert.assertNotNull(messages);
218 Assert.assertEquals(messages.size(), 0);
222 public void testNoErrorWhenEmptyValueForParameterInEnv() {
223 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
224 "/org/openecomp/validation/validators/heat_validator/env_empty_value/input");
226 Assert.assertNotNull(messages);
227 Assert.assertEquals(messages.size(), 0);