[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-be / lib / openecomp-sdc-validation-lib / openecomp-sdc-validation-impl / src / test / java / org / openecomp / sdc / validation / impl / validators / HeatValidatorTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.validation.impl.validators;
22
23
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;
29
30 import java.io.IOException;
31 import java.util.Map;
32
33
34 public class HeatValidatorTest {
35
36
37   private Validator validator = new HeatValidator();
38
39   @Test
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");
43
44     Assert.assertNotNull(messages);
45     Assert.assertEquals(messages.size(), 1);
46
47     Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 1);
48     Assert.assertEquals(
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" +
52             "        kuku: kuku\n" +
53             "        ^\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" +
56             "        kuku: kuku\n" +
57             "              ^\n" +
58             "]");
59   }
60
61   @Test
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");
65
66     Assert.assertNotNull(messages);
67     Assert.assertEquals(messages.size(), 1);
68
69     Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 2);
70     Assert.assertEquals(
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]");
73     Assert.assertEquals(
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]");
76   }
77
78
79   @Test
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");
83
84     Assert.assertNotNull(messages);
85     Assert.assertEquals(messages.size(), 1);
86
87     Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 2);
88     Assert.assertEquals(
89         messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
90         "ERROR: Referenced resource - not_existing_resource not found");
91     Assert.assertEquals(
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");
94   }
95
96
97   @Test
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");
101
102     Assert.assertNotNull(messages);
103     Assert.assertEquals(messages.size(), 1);
104
105     Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 3);
106     Assert.assertEquals(
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");
109     Assert.assertEquals(
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");
112     Assert.assertEquals(
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");
115   }
116
117   @Test
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);
123   }
124
125   @Test
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");
129
130     Assert.assertNotNull(messages);
131     Assert.assertEquals(messages.size(), 1);
132
133     Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 1);
134     Assert.assertEquals(
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]");
137   }
138
139   @Test
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");
143
144     Assert.assertNotNull(messages);
145     Assert.assertEquals(messages.size(), 1);
146
147     Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 1);
148     Assert.assertEquals(
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]");
151   }
152
153   @Test
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");
157
158     Assert.assertNotNull(messages);
159     Assert.assertEquals(messages.size(), 1);
160
161     Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 1);
162     Assert.assertEquals(
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");
165   }
166
167
168   @Test
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");
172
173     Assert.assertNotNull(messages);
174     Assert.assertEquals(messages.size(), 1);
175
176     Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.env").getErrorMessageList().size(), 1);
177     Assert.assertEquals(
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");
180
181   }
182
183   @Test
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");
187
188     Assert.assertNotNull(messages);
189     Assert.assertEquals(messages.size(), 1);
190
191     Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 1);
192     Assert.assertEquals(
193         messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
194         "ERROR: Missing artifact - nimbus-ethernet");
195
196   }
197
198   @Test
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");
202
203     Assert.assertNotNull(messages);
204     Assert.assertEquals(messages.size(), 1);
205
206     Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.env").getErrorMessageList().size(), 1);
207     Assert.assertEquals(
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");
210   }
211
212   @Test
213   public void testGetParamPseudoParameters() {
214     Map<String, MessageContainer> messages =ValidationTestUtil.testValidator(new HeatValidator(),
215         "/org/openecomp/validation/validators/heat_validator/pseudo_parameters/input");
216
217     Assert.assertNotNull(messages);
218     Assert.assertEquals(messages.size(), 0);
219
220   }
221   @Test
222   public void testNoErrorWhenEmptyValueForParameterInEnv() {
223     Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(validator,
224         "/org/openecomp/validation/validators/heat_validator/env_empty_value/input");
225
226     Assert.assertNotNull(messages);
227     Assert.assertEquals(messages.size(), 0);
228   }
229
230 }