Sorted out unit-test libraries in onboarding
[sdc.git] / openecomp-be / lib / openecomp-sdc-validation-lib / openecomp-sdc-validation-impl / src / test / java / org / openecomp / sdc / validation / impl / validators / heatresource / NestedResourceValidatorTest.java
1 /*
2  * Copyright © 2016-2017 European Support Limited
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.openecomp.sdc.validation.impl.validators.heatresource;
18
19 import java.util.Map;
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;
28
29 /**
30  * Created by TALIO on 2/28/2017.
31  */
32 public class NestedResourceValidatorTest {
33
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/";
37
38   @Test
39   public void testNoLoopsNesting() {
40
41     Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
42             resourceValidator, null,
43             PATH + "no_loops_nesting/negative_test/input");
44
45     Assert.assertNotNull(messages);
46     Assert.assertEquals(messages.size(), 4);
47
48     Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 1);
49     Assert.assertEquals(
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]");
52
53     Assert.assertEquals(
54             messages.get("nested-points-to-hot-nimbus-psm.yaml").getErrorMessageList().size(), 2);
55     Assert.assertEquals(
56             messages.get("nested-points-to-hot-nimbus-psm.yaml").getErrorMessageList().get(0)
57                     .getMessage(),
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]");
59     Assert.assertEquals(
60             messages.get("nested-points-to-hot-nimbus-psm.yaml").getErrorMessageList().get(1)
61                     .getMessage(),
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]");
63
64     Assert.assertEquals(messages.get("yaml-point-to-itself.yaml").getErrorMessageList().size(), 1);
65     Assert.assertEquals(
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]");
68
69     Assert.assertEquals(messages.get("nested-psm_v1.0.yaml").getErrorMessageList().size(), 1);
70     Assert.assertEquals(
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]");
73   }
74
75   @Test
76   public void testPropertiesMatchNestedParameters() {
77     Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
78             resourceValidator, null,
79             PATH + "properties_match_nested_parameters/negative_test/input");
80
81     Assert.assertNotNull(messages);
82     Assert.assertEquals(messages.size(), 1);
83
84     Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 1);
85     Assert.assertEquals(
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]");
88   }
89
90   @Test
91   public void testWrongValueTypeAssigned() {
92     Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
93             resourceValidator, null,
94             PATH + "properties_match_nested_parameters/wrong_value_type_assigned/input");
95
96     Assert.assertNotNull(messages);
97     Assert.assertEquals(messages.size(), 1);
98
99     Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 1);
100     Assert.assertEquals(
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]");
103   }
104
105   @Test
106   public void testMissingNestedFile() {
107     final Resource resource = new Resource();
108     resource.setType("nested-pps_v1.0.yaml");
109
110     final GlobalValidationContext globalValidationContext = ValidationTestUtil.createGlobalContextFromPath(PATH + "missing_nested_file/input");
111
112     NestedResourceValidator.validateAllPropertiesMatchNestedParameters(null, null, resource, Optional.empty(), globalValidationContext);
113
114     Map<String, MessageContainer> messages = globalValidationContext.getContextMessageContainers();
115     Assert.assertNotNull(messages);
116     Assert.assertEquals(messages.size(), 1);
117
118     Assert.assertEquals(messages.get("nested-pps_v1.0.yaml").getErrorMessageList().size(), 1);
119     Assert.assertEquals(
120             messages.get("nested-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
121             "ERROR: [HNR1]: Missing nested file - nested-pps_v1.0.yaml");
122   }
123 }