2 * Copyright © 2016-2018 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 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;
29 * @since January 22, 2018
32 public class VirtualMachineInterfaceValidatorTest {
33 private static final String PATH =
34 "/org/openecomp/validation/validators/heat_validator/vlan_resource_validation/";
38 public void hasSingleParentPortNegative() {
39 HeatResourceValidator baseValidator = new HeatResourceValidator();
40 VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
41 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
43 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
44 PATH + "vlan_multiple_parent_ports/negative_test/input");
46 Assert.assertNotNull(messages);
47 Assert.assertEquals(messages.size(), 1);
49 Assert.assertEquals(messages.get("nested.yml").getErrorMessageList().size(), 1);
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]");
57 public void hasSingleParentPortNegativeWithGetResource() {
58 HeatResourceValidator baseValidator = new HeatResourceValidator();
59 VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
60 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
62 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
63 PATH + "vlan_multiple_parent_ports/negative_get_resource/input");
65 Assert.assertNotNull(messages);
66 Assert.assertEquals(messages.size(), 0);
71 public void hasSingleParentPortPositive() {
72 HeatResourceValidator baseValidator = new HeatResourceValidator();
73 VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
74 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
76 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
77 PATH + "vlan_multiple_parent_ports/positive_test/input");
79 Assert.assertNotNull(messages);
80 Assert.assertEquals(messages.size(), 0);
87 public void hasBothPropertiesNegativeMissingVlanTag() {
88 HeatResourceValidator baseValidator = new HeatResourceValidator();
89 VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
90 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
92 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
93 PATH + "vlan_has_two_properties/negative_tag_missing/input");
95 Assert.assertNotNull(messages);
96 Assert.assertEquals(messages.size(), 1);
98 Assert.assertEquals(messages.get("nested.yml").getErrorMessageList().size(), 1);
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]");
107 public void hasBothPropertiesNegativeMissingRefs() {
108 HeatResourceValidator baseValidator = new HeatResourceValidator();
109 VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
110 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
112 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
113 PATH + "vlan_has_two_properties/negative_refs_missing/input");
115 Assert.assertNotNull(messages);
116 Assert.assertEquals(messages.size(), 1);
118 Assert.assertEquals(messages.get("nested.yml").getErrorMessageList().size(), 1);
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]");
126 public void hasBothPropertiesBothMissingWhichMeansPositive() {
127 HeatResourceValidator baseValidator = new HeatResourceValidator();
128 VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
129 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
131 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
132 PATH + "vlan_has_two_properties/negative_both_missing/input");
134 Assert.assertNotNull(messages);
135 Assert.assertEquals(messages.size(), 0);
141 public void hasBothPropertiesPositive() {
142 HeatResourceValidator baseValidator = new HeatResourceValidator();
143 VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
144 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
146 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
147 PATH + "vlan_has_two_properties/positive_test/input");
149 Assert.assertNotNull(messages);
150 Assert.assertEquals(messages.size(), 0);