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;
19 import org.openecomp.core.validation.types.GlobalValidationContext;
20 import org.openecomp.core.validation.types.MessageContainer;
21 import org.openecomp.sdc.heat.datatypes.model.Resource;
22 import org.openecomp.sdc.validation.impl.validators.HeatResourceValidator;
23 import org.openecomp.sdc.validation.util.ValidationTestUtil;
24 import org.testng.Assert;
25 import org.testng.annotations.Test;
28 import java.util.Optional;
31 * Created by TALIO on 2/28/2017.
33 public class NestedResourceValidatorTest {
35 private final HeatResourceValidator baseValidator = new HeatResourceValidator();
36 private final NestedResourceValidator resourceValidator = new NestedResourceValidator();
37 private static final String PATH = "/org/openecomp/validation/validators/heat_validator/";
40 public void testNoLoopsNesting() {
42 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
43 resourceValidator, null,
44 PATH + "no_loops_nesting/negative_test/input");
46 Assert.assertNotNull(messages);
47 Assert.assertEquals(messages.size(), 4);
49 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 1);
51 messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
52 "ERROR: [HNR2]: Nested files loop - [hot-nimbus-psm_v1.0.yaml -- nested-psm_v1.0.yaml -- nested-points-to-hot-nimbus-psm.yaml -- hot-nimbus-psm_v1.0.yaml]");
55 messages.get("nested-points-to-hot-nimbus-psm.yaml").getErrorMessageList().size(), 2);
57 messages.get("nested-points-to-hot-nimbus-psm.yaml").getErrorMessageList().get(0)
59 "ERROR: [HNR2]: Nested files loop - [nested-points-to-hot-nimbus-psm.yaml -- hot-nimbus-psm_v1.0.yaml -- nested-psm_v1.0.yaml -- nested-points-to-hot-nimbus-psm.yaml]");
61 messages.get("nested-points-to-hot-nimbus-psm.yaml").getErrorMessageList().get(1)
63 "ERROR: [HNR2]: Nested files loop - [nested-points-to-hot-nimbus-psm.yaml -- nested-psm_v1.0.yaml -- nested-points-to-hot-nimbus-psm.yaml]");
65 Assert.assertEquals(messages.get("yaml-point-to-itself.yaml").getErrorMessageList().size(), 1);
67 messages.get("yaml-point-to-itself.yaml").getErrorMessageList().get(0).getMessage(),
68 "ERROR: [HNR2]: Nested files loop - [yaml-point-to-itself.yaml -- yaml-point-to-itself.yaml]");
70 Assert.assertEquals(messages.get("nested-psm_v1.0.yaml").getErrorMessageList().size(), 1);
72 messages.get("nested-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
73 "ERROR: [HNR2]: Nested files loop - [nested-psm_v1.0.yaml -- nested-points-to-hot-nimbus-psm.yaml -- hot-nimbus-psm_v1.0.yaml -- nested-psm_v1.0.yaml]");
77 public void testPropertiesMatchNestedParameters() {
78 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
79 resourceValidator, null,
80 PATH + "properties_match_nested_parameters/negative_test/input");
82 Assert.assertNotNull(messages);
83 Assert.assertEquals(messages.size(), 1);
85 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 1);
87 messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
88 "ERROR: [HNR3]: Referenced parameter not found in nested file - nested-pps_v1.0.yaml, parameter name [server_pcrf_pps_001], Resource ID [parameter_not_existing_in_nested]");
92 public void testWrongValueTypeAssigned() {
93 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
94 resourceValidator, null,
95 PATH + "properties_match_nested_parameters/wrong_value_type_assigned/input");
97 Assert.assertNotNull(messages);
98 Assert.assertEquals(messages.size(), 1);
100 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 1);
102 messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
103 "WARNING: [HNR4]: Wrong value type assigned to a nested input parameter, nested resource [server_pcrf_pps_001], property name [index_integer], nested file [nested-pps_v1.0.yaml]");
107 public void testMissingNestedFile() {
108 final Resource resource = new Resource();
109 resource.setType("nested-pps_v1.0.yaml");
111 final GlobalValidationContext globalValidationContext = ValidationTestUtil.createGlobalContextFromPath(PATH + "missing_nested_file/input");
113 NestedResourceValidator.validateAllPropertiesMatchNestedParameters(null, null, resource, Optional.empty(), globalValidationContext);
115 Map<String, MessageContainer> messages = globalValidationContext.getContextMessageContainers();
116 Assert.assertNotNull(messages);
117 Assert.assertEquals(messages.size(), 1);
119 Assert.assertEquals(messages.get("nested-pps_v1.0.yaml").getErrorMessageList().size(), 1);
121 messages.get("nested-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
122 "ERROR: [HNR1]: Missing nested file - nested-pps_v1.0.yaml");