Upgrade Vulnerable Direct Dependencies [snakeyaml]
[sdc.git] / openecomp-be / lib / openecomp-sdc-validation-lib / openecomp-sdc-validation-impl / src / test / java / org / openecomp / sdc / validation / impl / validators / heatresource / VirtualMachineInterfaceValidatorTest.java
1 /*
2  * Copyright © 2016-2018 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
21 import org.junit.Assert;
22 import org.junit.Test;
23 import org.openecomp.core.validation.types.MessageContainer;
24 import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
25 import org.openecomp.sdc.validation.impl.validators.HeatResourceValidator;
26 import org.openecomp.sdc.validation.util.ValidationTestUtil;
27
28 /**
29  * @author KATYR
30  * @since January 22, 2018
31  */
32
33 public class VirtualMachineInterfaceValidatorTest {
34     private static final String PATH =
35             "/org/openecomp/validation/validators/heat_validator/vlan_resource_validation/";
36
37
38     @Test
39     public void hasSingleParentPortNegative() {
40         HeatResourceValidator baseValidator = new HeatResourceValidator();
41         VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
42         Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
43                 resourceValidator,
44                 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
45                 PATH + "vlan_multiple_parent_ports/negative_test/input");
46
47         Assert.assertNotNull(messages);
48         Assert.assertEquals(1, messages.size());
49
50         Assert.assertEquals(1, messages.get("nested.yml").getErrorMessageList().size());
51         Assert.assertEquals(
52                 messages.get("nested.yml").getErrorMessageList().get(0).getMessage(),
53                 "ERROR: [VLAN1]: More than one parent port found, " +
54                         "there should be only one parent port for a VLAN sub-interface ID [template_Vlan_2]");
55     }
56
57     @Test
58     public void hasSingleParentPortNegativeWithGetResource() {
59         HeatResourceValidator baseValidator = new HeatResourceValidator();
60         VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
61         Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
62                 resourceValidator,
63                 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
64                 PATH + "vlan_multiple_parent_ports/negative_get_resource/input");
65
66         Assert.assertNotNull(messages);
67         Assert.assertEquals(messages.size(), 0);
68     }
69
70
71     @Test
72     public void hasSingleParentPortPositive() {
73         HeatResourceValidator baseValidator = new HeatResourceValidator();
74         VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
75         Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
76                 resourceValidator,
77                 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
78                 PATH + "vlan_multiple_parent_ports/positive_test/input");
79
80         Assert.assertNotNull(messages);
81         Assert.assertEquals(0, messages.size());
82     }
83
84
85     @Test
86     public void hasBothPropertiesNegativeMissingVlanTag() {
87         HeatResourceValidator baseValidator = new HeatResourceValidator();
88         VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
89         Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
90                 resourceValidator,
91                 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
92                 PATH + "vlan_has_two_properties/negative_tag_missing/input");
93
94         Assert.assertNotNull(messages);
95         Assert.assertEquals(messages.size(), 1);
96
97         Assert.assertEquals(messages.get("nested.yml").getErrorMessageList().size(), 1);
98         Assert.assertEquals(
99                 messages.get("nested.yml").getErrorMessageList().get(0).getMessage(),
100                 "WARNING: [VLAN2]: VLAN Tag property " +
101                         "virtual_machine_interface_properties_sub_interface_vlan_tag " +
102                         "is missing in VLAN Resource ID [template_Vlan_2]");
103     }
104
105     @Test
106     public void hasBothPropertiesNegativeMissingRefs() {
107         HeatResourceValidator baseValidator = new HeatResourceValidator();
108         VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
109         Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
110                 resourceValidator,
111                 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
112                 PATH + "vlan_has_two_properties/negative_refs_missing/input");
113
114         Assert.assertNotNull(messages);
115         Assert.assertEquals(messages.size(), 1);
116
117         Assert.assertEquals(messages.get("nested.yml").getErrorMessageList().size(), 1);
118         Assert.assertEquals(
119                 messages.get("nested.yml").getErrorMessageList().get(0).getMessage(),
120                 "WARNING: [VLAN2]: Parent port property virtual_machine_interface_refs is " +
121                         "missing in VLAN Resource ID [template_Vlan_2]");
122     }
123
124     @Test
125     public void hasBothPropertiesBothMissingWhichMeansPositive() {
126         HeatResourceValidator baseValidator = new HeatResourceValidator();
127         VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
128         Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
129                 resourceValidator,
130                 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
131                 PATH + "vlan_has_two_properties/negative_both_missing/input");
132
133         Assert.assertNotNull(messages);
134         Assert.assertEquals(messages.size(), 0);
135
136     }
137
138
139     @Test
140     public void hasBothPropertiesPositive() {
141         HeatResourceValidator baseValidator = new HeatResourceValidator();
142         VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
143         Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
144                 resourceValidator,
145                 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
146                 PATH + "vlan_has_two_properties/positive_test/input");
147
148         Assert.assertNotNull(messages);
149         Assert.assertEquals(messages.size(), 0);
150     }
151 }