2 * Copyright © 2016-2017 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.validation.impl.validators.heatresource;
20 import org.junit.Assert;
21 import org.junit.Test;
22 import org.openecomp.core.validation.types.MessageContainer;
23 import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
24 import org.openecomp.sdc.validation.impl.validators.HeatResourceValidator;
25 import org.openecomp.sdc.validation.util.ValidationTestUtil;
28 * Created by TALIO on 2/28/2017.
30 public class ResourceGroupResourceValidatorTest {
32 private final HeatResourceValidator baseValidator = new HeatResourceValidator();
33 private final ResourceGroupResourceValidator resourceValidator = new ResourceGroupResourceValidator();
35 private static final String PATH = "/org/openecomp/validation/validators/heat_validator/";
37 public void testResourceGroupWithInvalidIndexVar() {
38 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
39 resourceValidator, HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource(),
40 PATH + "resource_group_invalid_indexvar/negative_test/input");
42 Assert.assertNotNull(messages);
43 Assert.assertEquals(messages.size(), 1);
45 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 14);
47 messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
48 "WARNING: [HRR8]: OS::Heat::ResourceGroup resource with resource_def which is not pointing to nested heat file is not supported, Resource ID [resource_with_resources_group_1], resource_def type [yamlFile.yaml]");
50 messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(1).getMessage(),
51 "ERROR: [HRR1]: Wrong value assigned to a ResourceGroup index_var property (functions are not allowed but only strings), Resource ID [resource_with_resources_group_1]");
53 messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(2).getMessage(),
54 "WARNING: [HRR8]: OS::Heat::ResourceGroup resource with resource_def which is not pointing to nested heat file is not supported, Resource ID [resource_with_resources_group_2], resource_def type [yamlFile.yaml]");
56 messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(3).getMessage(),
57 "WARNING: [HRR5]: Wrong value type assigned to a nested input parameter, nested resource [resource_with_resources_group_2], property name [index_boolean], nested file [yamlFile.yaml]");
59 messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(4).getMessage(),
60 "WARNING: [HRR8]: OS::Heat::ResourceGroup resource with resource_def which is not pointing to nested heat file is not supported, Resource ID [resource_with_resources_group_3], resource_def type [yamlFile.yaml]");
62 messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(5).getMessage(),
63 "WARNING: [HRR5]: Wrong value type assigned to a nested input parameter, nested resource [resource_with_resources_group_3], property name [index_boolean], nested file [yamlFile.yaml]");
65 messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(6).getMessage(),
66 "WARNING: [HRR5]: Wrong value type assigned to a nested input parameter, nested resource [resource_with_resources_group_3], property name [index_number], nested file [yamlFile.yaml]");
68 messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(7).getMessage(),
69 "WARNING: [HRR8]: OS::Heat::ResourceGroup resource with resource_def which is not pointing to nested heat file is not supported, Resource ID [resource_with_resources_group_4], resource_def type [yamlFile.yaml]");
71 messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(8).getMessage(),
72 "WARNING: [HRR5]: Wrong value type assigned to a nested input parameter, nested resource [resource_with_resources_group_4], property name [index_boolean], nested file [yamlFile.yaml]");
74 messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(9).getMessage(),
75 "WARNING: [HRR8]: OS::Heat::ResourceGroup resource with resource_def which is not pointing to nested heat file is not supported, Resource ID [resource_with_resources_group_5], resource_def type [yamlFile.yaml]");
77 messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(10).getMessage(),
78 "WARNING: [HRR5]: Wrong value type assigned to a nested input parameter, nested resource [resource_with_resources_group_5], property name [index_boolean], nested file [yamlFile.yaml]");
80 messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(11).getMessage(),
81 "WARNING: [HRR5]: Wrong value type assigned to a nested input parameter, nested resource [resource_with_resources_group_5], property name [index_number], nested file [yamlFile.yaml]");
83 messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(12).getMessage(),
84 "WARNING: [HRR8]: OS::Heat::ResourceGroup resource with resource_def which is not pointing to nested heat file is not supported, Resource ID [resource_with_resources_group_6], resource_def type [yamlFile.yaml]");
86 messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(13).getMessage(),
87 "ERROR: [HRR1]: Wrong value assigned to a ResourceGroup index_var property (functions are not allowed but only strings), Resource ID [resource_with_resources_group_6]");
91 public void testResourceGroupWithInvalidType() {
92 Map<String, MessageContainer> messages =ValidationTestUtil.testValidator(baseValidator,
93 resourceValidator, HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource(),
94 PATH + "resource_group_invalid_type/negative_test/input");
96 Assert.assertNotNull(messages);
97 Assert.assertEquals(messages.size(), 1);
99 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 3);
101 messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
102 "WARNING: [HRR7]: OS::Heat::ResourceGroup resource with resource_def which is not pointing to nested heat file is not supported, Resource ID [resource_with_resources_group_1], resource_def type [{get_param=pcrf_vnf_id}]");
104 messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(1).getMessage(),
105 "WARNING: [HRR6]: A resource has an invalid or unsupported type - null, Resource ID [resource_with_resources_group_3]");
107 messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(2).getMessage(),
108 "WARNING: [HRR8]: OS::Heat::ResourceGroup resource with resource_def which is not pointing to nested heat file is not supported, Resource ID [resource_with_resources_group_4], resource_def type [yamlFile.yaml]");
112 public void testResourcesGroupWithNested() {
113 Map<String, MessageContainer> messages =ValidationTestUtil.testValidator(baseValidator,
114 resourceValidator, HeatResourcesTypes.RESOURCE_GROUP_RESOURCE_TYPE.getHeatResource(),
115 PATH + "resources_group_with_nested/negative_test/input");
117 Assert.assertNotNull(messages);
118 Assert.assertEquals(messages.size(), 4);
120 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 2);
122 messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
123 "WARNING: [HRR8]: OS::Heat::ResourceGroup resource with resource_def which is not pointing to nested heat file is not supported, Resource ID [resource_with_resources_group], resource_def type [nested-from-resources-group.yaml]");
125 messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(1).getMessage(),
126 "ERROR: [HRR4]: Referenced parameter not found in nested file - nested-from-resources-group.yaml, parameter name [resource_with_resources_group], Resource ID [property_not_in_nested]");
128 Assert.assertEquals(messages.get("nested-pps_v1.0.yaml").getErrorMessageList().size(), 2);
130 messages.get("nested-pps_v1.0.yaml").getErrorMessageList().get(1).getMessage(),
131 "ERROR: [HRR3]: Nested files loop - [nested-pps_v1.0.yaml -- nested-from-resources-group.yaml -- hot-nimbus-pps_v1.0.yaml -- nested-pps_v1.0.yaml]");
133 Assert.assertEquals(messages.get("nested-not-exist.yaml").getErrorMessageList().size(), 1);
135 messages.get("nested-not-exist.yaml").getErrorMessageList().get(0).getMessage(),
136 "ERROR: [HRR2]: Missing nested file - nested-not-exist.yaml");