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 java.util.Optional;
21 import org.junit.Assert;
22 import org.junit.Test;
23 import org.openecomp.core.validation.types.GlobalValidationContext;
24 import org.openecomp.core.validation.types.MessageContainer;
25 import org.openecomp.sdc.heat.datatypes.model.Resource;
26 import org.openecomp.sdc.validation.impl.validators.HeatResourceValidator;
27 import org.openecomp.sdc.validation.util.ValidationTestUtil;
30 * Created by TALIO on 2/28/2017.
32 public class NestedResourceValidatorTest {
34 private final HeatResourceValidator baseValidator = new HeatResourceValidator();
35 private final NestedResourceValidator resourceValidator = new NestedResourceValidator();
36 private static final String PATH = "/org/openecomp/validation/validators/heat_validator/";
39 public void testNoLoopsNesting() {
41 Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
42 resourceValidator, null,
43 PATH + "no_loops_nesting/negative_test/input");
45 Assert.assertNotNull(messages);
46 Assert.assertEquals(messages.size(), 4);
48 Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 1);
50 messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
51 "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]");
54 messages.get("nested-points-to-hot-nimbus-psm.yaml").getErrorMessageList().size(), 2);
56 messages.get("nested-points-to-hot-nimbus-psm.yaml").getErrorMessageList().get(0)
58 "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]");
60 messages.get("nested-points-to-hot-nimbus-psm.yaml").getErrorMessageList().get(1)
62 "ERROR: [HNR2]: Nested files loop - [nested-points-to-hot-nimbus-psm.yaml -- nested-psm_v1.0.yaml -- nested-points-to-hot-nimbus-psm.yaml]");
64 Assert.assertEquals(messages.get("yaml-point-to-itself.yaml").getErrorMessageList().size(), 1);
66 messages.get("yaml-point-to-itself.yaml").getErrorMessageList().get(0).getMessage(),
67 "ERROR: [HNR2]: Nested files loop - [yaml-point-to-itself.yaml -- yaml-point-to-itself.yaml]");
69 Assert.assertEquals(messages.get("nested-psm_v1.0.yaml").getErrorMessageList().size(), 1);
71 messages.get("nested-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
72 "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]");
76 public void testPropertiesMatchNestedParameters() {
77 Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
78 resourceValidator, null,
79 PATH + "properties_match_nested_parameters/negative_test/input");
81 Assert.assertNotNull(messages);
82 Assert.assertEquals(messages.size(), 1);
84 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 1);
86 messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
87 "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]");
91 public void testWrongValueTypeAssigned() {
92 Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
93 resourceValidator, null,
94 PATH + "properties_match_nested_parameters/wrong_value_type_assigned/input");
96 Assert.assertNotNull(messages);
97 Assert.assertEquals(messages.size(), 1);
99 Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 1);
101 messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
102 "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]");
106 public void testMissingNestedFile() {
107 final Resource resource = new Resource();
108 resource.setType("nested-pps_v1.0.yaml");
110 final GlobalValidationContext globalValidationContext = new ValidationTestUtil().createGlobalContextFromPath(PATH + "missing_nested_file/input");
112 NestedResourceValidator.validateAllPropertiesMatchNestedParameters(null, null, resource, Optional.empty(), globalValidationContext);
114 Map<String, MessageContainer> messages = globalValidationContext.getContextMessageContainers();
115 Assert.assertNotNull(messages);
116 Assert.assertEquals(messages.size(), 1);
118 Assert.assertEquals(messages.get("nested-pps_v1.0.yaml").getErrorMessageList().size(), 1);
120 messages.get("nested-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
121 "ERROR: [HNR1]: Missing nested file - nested-pps_v1.0.yaml");