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.namingconvention;
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.NamingConventionGuideLineValidator;
25 import org.openecomp.sdc.validation.util.ValidationTestUtil;
27 public class VirtualMachineInterfaceGuidelineValidatorTest {
28 private static final String PATH =
29 "/org/openecomp/validation/validators/guideLineValidator/vlan_validation/";
32 public void modeledThroughResourceGroupPositive() {
34 NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
35 VirtualMachineInterfaceGuidelineValidator resourceValidator = new
36 VirtualMachineInterfaceGuidelineValidator();
37 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
39 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
40 PATH + "modeled_through_resource_group/positive_test/input");
42 Assert.assertNotNull(messages);
43 Assert.assertEquals(messages.size(), 0);
48 public void modeledThroughResourceGroupNegativeTwoValuesInList() {
50 NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
51 VirtualMachineInterfaceGuidelineValidator resourceValidator = new
52 VirtualMachineInterfaceGuidelineValidator();
53 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
55 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
56 PATH + "modeled_through_resource_group/negative_test/input");
58 Assert.assertNotNull(messages);
59 Assert.assertEquals(messages.size(), 1);
61 Assert.assertEquals(messages.get("nested.yml").getErrorMessageList().size(), 1);
63 messages.get("nested.yml").getErrorMessageList().get(0).getMessage(),
64 "WARNING: [VlANG1]: VLAN Resource will not be translated as the VLAN Sub-interface " +
65 "[vdbe_0_subint_untr_vmi_0] is not modeled as resource group");
69 public void modeledThroughResourceGroupNegativeNonStringGetParam() {
71 NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
72 VirtualMachineInterfaceGuidelineValidator resourceValidator = new
73 VirtualMachineInterfaceGuidelineValidator();
74 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
76 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
77 PATH + "modeled_through_resource_group/negative_test_non_string/input");
79 Assert.assertNotNull(messages);
80 Assert.assertEquals(messages.size(), 1);
82 Assert.assertEquals(messages.get("nested.yml").getErrorMessageList().size(), 1);
84 messages.get("nested.yml").getErrorMessageList().get(0).getMessage(),
85 "WARNING: [VlANG1]: VLAN Resource will not be translated as the VLAN Sub-interface " +
86 "[vdbe_0_subint_untr_vmi_0] is not modeled as resource group");
90 public void modeledThroughResourceGroupNegativeResource() {
92 NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
93 VirtualMachineInterfaceGuidelineValidator resourceValidator = new
94 VirtualMachineInterfaceGuidelineValidator();
95 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
97 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
98 PATH + "modeled_through_resource_group/negative_get_resource/input");
100 Assert.assertNotNull(messages);
101 Assert.assertEquals(messages.size(), 1);
103 Assert.assertEquals(messages.get("nested.yml").getErrorMessageList().size(), 1);
105 messages.get("nested.yml").getErrorMessageList().get(0).getMessage(),
106 "WARNING: [VlANG1]: VLAN Resource will not be translated as the VLAN Sub-interface " +
107 "[vdbe_0_subint_untr_vmi_0] is not modeled as resource group");
112 public void vlanAloneInFilePositive() {
114 NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
115 VirtualMachineInterfaceGuidelineValidator resourceValidator = new
116 VirtualMachineInterfaceGuidelineValidator();
117 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
119 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
120 PATH + "single_vlan_resource/positive_test/input");
122 Assert.assertNotNull(messages);
123 Assert.assertEquals(messages.size(), 0);
128 public void vlanAloneInFileNegative_2vlans() {
130 NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
131 VirtualMachineInterfaceGuidelineValidator resourceValidator = new
132 VirtualMachineInterfaceGuidelineValidator();
133 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
135 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
136 PATH + "single_vlan_resource/negative_test/two_vlans");
138 Assert.assertNotNull(messages);
139 Assert.assertEquals(messages.size(), 1);
141 Assert.assertEquals(messages.get("nested.yml").getErrorMessageList().size(), 1);
143 messages.get("nested.yml").getErrorMessageList().get(0).getMessage(),
144 "ERROR: [VlANG2]: There should not be any Compute Server Node, Port, " +
145 "Parent Port in nested file [nested.yml]");
149 public void vlanAloneInFileNegative_vlanAndNova() {
151 NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
152 VirtualMachineInterfaceGuidelineValidator resourceValidator = new
153 VirtualMachineInterfaceGuidelineValidator();
154 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
156 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
157 PATH + "single_vlan_resource/negative_test/vlan_and_nova");
159 Assert.assertNotNull(messages);
160 Assert.assertEquals(messages.size(), 1);
162 Assert.assertEquals(messages.get("nested.yml").getErrorMessageList().size(), 1);
164 messages.get("nested.yml").getErrorMessageList().get(0).getMessage(),
165 "ERROR: [VlANG2]: There should not be any Compute Server Node, Port, " +
166 "Parent Port in nested file [nested.yml]");
170 public void namingConventionNegative(){
171 NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
172 VirtualMachineInterfaceGuidelineValidator resourceValidator = new
173 VirtualMachineInterfaceGuidelineValidator();
174 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
176 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
177 PATH + "naming_convention/negative_test/input");
179 Assert.assertNotNull(messages);
180 Assert.assertEquals(messages.size(), 1);
182 Assert.assertEquals(messages.get("nested.yml").getErrorMessageList().size(), 2);
184 messages.get("nested.yml").getErrorMessageList().get(1).getMessage(),
185 "WARNING: [VlANG3]: Network role associated with VLAN Sub-interface " +
186 "id[template_wrong_naming_Vlan_2] is not following the naming convention");
191 public void namingConventionPositive(){
192 NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
193 VirtualMachineInterfaceGuidelineValidator resourceValidator = new
194 VirtualMachineInterfaceGuidelineValidator();
195 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
197 HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
198 PATH + "naming_convention/positive_test/input");
200 Assert.assertNotNull(messages);
201 Assert.assertEquals(messages.size(), 0);