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;
19 import org.openecomp.core.validation.types.MessageContainer;
20 import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
21 import org.openecomp.sdc.validation.impl.validators.HeatResourceValidator;
22 import org.openecomp.sdc.validation.util.ValidationTestUtil;
23 import org.testng.Assert;
24 import org.testng.annotations.Test;
30 * @since January 22, 2018
33 public class VirtualMachineInterfaceValidatorTest {
34 private static final String PATH =
35 "/org/openecomp/validation/validators/heat_validator/vlan_resource_validation/";
39 public void hasSingleParentPortNegative() {
40 HeatResourceValidator baseValidator = new HeatResourceValidator();
41 VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
42 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
44 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
45 PATH + "vlan_multiple_parent_ports/negative_test/input");
47 Assert.assertNotNull(messages);
48 Assert.assertEquals(messages.size(), 1);
50 Assert.assertEquals(messages.get("nested.yml").getErrorMessageList().size(), 1);
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]");
58 public void hasSingleParentPortNegativeWithGetResource() {
59 HeatResourceValidator baseValidator = new HeatResourceValidator();
60 VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
61 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
63 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
64 PATH + "vlan_multiple_parent_ports/negative_get_resource/input");
66 Assert.assertNotNull(messages);
67 Assert.assertEquals(messages.size(), 0);
72 public void hasSingleParentPortPositive() {
73 HeatResourceValidator baseValidator = new HeatResourceValidator();
74 VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
75 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
77 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
78 PATH + "vlan_multiple_parent_ports/positive_test/input");
80 Assert.assertNotNull(messages);
81 Assert.assertEquals(messages.size(), 0);
88 public void hasBothPropertiesNegativeMissingVlanTag() {
89 HeatResourceValidator baseValidator = new HeatResourceValidator();
90 VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
91 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
93 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
94 PATH + "vlan_has_two_properties/negative_tag_missing/input");
96 Assert.assertNotNull(messages);
97 Assert.assertEquals(messages.size(), 1);
99 Assert.assertEquals(messages.get("nested.yml").getErrorMessageList().size(), 1);
101 messages.get("nested.yml").getErrorMessageList().get(0).getMessage(),
102 "WARNING: [VLAN2]: VLAN Tag property " +
103 "virtual_machine_interface_properties_sub_interface_vlan_tag " +
104 "is missing in VLAN Resource ID [template_Vlan_2]");
108 public void hasBothPropertiesNegativeMissingRefs() {
109 HeatResourceValidator baseValidator = new HeatResourceValidator();
110 VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
111 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
113 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
114 PATH + "vlan_has_two_properties/negative_refs_missing/input");
116 Assert.assertNotNull(messages);
117 Assert.assertEquals(messages.size(), 1);
119 Assert.assertEquals(messages.get("nested.yml").getErrorMessageList().size(), 1);
121 messages.get("nested.yml").getErrorMessageList().get(0).getMessage(),
122 "WARNING: [VLAN2]: Parent port property virtual_machine_interface_refs is " +
123 "missing in VLAN Resource ID [template_Vlan_2]");
127 public void hasBothPropertiesBothMissingWhichMeansPositive() {
128 HeatResourceValidator baseValidator = new HeatResourceValidator();
129 VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
130 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
132 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
133 PATH + "vlan_has_two_properties/negative_both_missing/input");
135 Assert.assertNotNull(messages);
136 Assert.assertEquals(messages.size(), 0);
142 public void hasBothPropertiesPositive() {
143 HeatResourceValidator baseValidator = new HeatResourceValidator();
144 VirtualMachineInterfaceValidator resourceValidator = new VirtualMachineInterfaceValidator();
145 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
147 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
148 PATH + "vlan_has_two_properties/positive_test/input");
150 Assert.assertNotNull(messages);
151 Assert.assertEquals(messages.size(), 0);