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