Added oparent to sdc main
[sdc.git] / openecomp-be / lib / openecomp-sdc-validation-lib / openecomp-sdc-validation-impl / src / test / java / org / openecomp / sdc / validation / impl / validators / namingconvention / VirtualMachineInterfaceGuidelineValidatorTest.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.namingconvention;
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.NamingConventionGuideLineValidator;
25 import org.openecomp.sdc.validation.util.ValidationTestUtil;
26
27 public class VirtualMachineInterfaceGuidelineValidatorTest {
28   private static final String PATH =
29       "/org/openecomp/validation/validators/guideLineValidator/vlan_validation/";
30
31   @Test
32   public void modeledThroughResourceGroupPositive() {
33
34     NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
35     VirtualMachineInterfaceGuidelineValidator resourceValidator = new
36         VirtualMachineInterfaceGuidelineValidator();
37     Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
38         resourceValidator,
39         HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
40         PATH + "modeled_through_resource_group/positive_test/input");
41
42     Assert.assertNotNull(messages);
43     Assert.assertEquals(messages.size(), 0);
44
45   }
46
47   @Test
48   public void modeledThroughResourceGroupNegativeTwoValuesInList() {
49
50     NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
51     VirtualMachineInterfaceGuidelineValidator resourceValidator = new
52         VirtualMachineInterfaceGuidelineValidator();
53     Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
54         resourceValidator,
55         HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
56         PATH + "modeled_through_resource_group/negative_test/input");
57
58     Assert.assertNotNull(messages);
59     Assert.assertEquals(messages.size(), 1);
60
61     Assert.assertEquals(messages.get("nested.yml").getErrorMessageList().size(), 1);
62     Assert.assertEquals(
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");
66   }
67
68   @Test
69   public void modeledThroughResourceGroupNegativeNonStringGetParam() {
70
71     NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
72     VirtualMachineInterfaceGuidelineValidator resourceValidator = new
73         VirtualMachineInterfaceGuidelineValidator();
74     Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
75         resourceValidator,
76         HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
77         PATH + "modeled_through_resource_group/negative_test_non_string/input");
78
79     Assert.assertNotNull(messages);
80     Assert.assertEquals(messages.size(), 1);
81
82     Assert.assertEquals(messages.get("nested.yml").getErrorMessageList().size(), 1);
83     Assert.assertEquals(
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");
87   }
88
89   @Test
90   public void modeledThroughResourceGroupNegativeResource() {
91
92     NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
93     VirtualMachineInterfaceGuidelineValidator resourceValidator = new
94         VirtualMachineInterfaceGuidelineValidator();
95     Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
96         resourceValidator,
97         HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
98         PATH + "modeled_through_resource_group/negative_get_resource/input");
99
100     Assert.assertNotNull(messages);
101     Assert.assertEquals(messages.size(), 1);
102
103     Assert.assertEquals(messages.get("nested.yml").getErrorMessageList().size(), 1);
104     Assert.assertEquals(
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");
108   }
109
110
111   @Test
112   public void vlanAloneInFilePositive() {
113
114     NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
115     VirtualMachineInterfaceGuidelineValidator resourceValidator = new
116         VirtualMachineInterfaceGuidelineValidator();
117     Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
118         resourceValidator,
119         HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
120         PATH + "single_vlan_resource/positive_test/input");
121
122     Assert.assertNotNull(messages);
123     Assert.assertEquals(messages.size(), 0);
124
125   }
126
127   @Test
128   public void vlanAloneInFileNegative_2vlans() {
129
130     NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
131     VirtualMachineInterfaceGuidelineValidator resourceValidator = new
132         VirtualMachineInterfaceGuidelineValidator();
133     Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
134         resourceValidator,
135         HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
136         PATH + "single_vlan_resource/negative_test/two_vlans");
137
138     Assert.assertNotNull(messages);
139     Assert.assertEquals(messages.size(), 1);
140
141     Assert.assertEquals(messages.get("nested.yml").getErrorMessageList().size(), 1);
142     Assert.assertEquals(
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]");
146   }
147
148   @Test
149   public void vlanAloneInFileNegative_vlanAndNova() {
150
151     NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
152     VirtualMachineInterfaceGuidelineValidator resourceValidator = new
153         VirtualMachineInterfaceGuidelineValidator();
154     Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
155         resourceValidator,
156         HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
157         PATH + "single_vlan_resource/negative_test/vlan_and_nova");
158
159     Assert.assertNotNull(messages);
160     Assert.assertEquals(messages.size(), 1);
161
162     Assert.assertEquals(messages.get("nested.yml").getErrorMessageList().size(), 1);
163     Assert.assertEquals(
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]");
167   }
168
169   @Test
170   public void namingConventionNegative(){
171     NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
172     VirtualMachineInterfaceGuidelineValidator resourceValidator = new
173         VirtualMachineInterfaceGuidelineValidator();
174     Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
175         resourceValidator,
176         HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
177         PATH + "naming_convention/negative_test/input");
178
179     Assert.assertNotNull(messages);
180     Assert.assertEquals(messages.size(), 1);
181
182     Assert.assertEquals(messages.get("nested.yml").getErrorMessageList().size(), 2);
183     Assert.assertEquals(
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");
187
188   }
189
190   @Test
191   public void namingConventionPositive(){
192     NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
193     VirtualMachineInterfaceGuidelineValidator resourceValidator = new
194         VirtualMachineInterfaceGuidelineValidator();
195     Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
196         resourceValidator,
197         HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource(),
198         PATH + "naming_convention/positive_test/input");
199
200     Assert.assertNotNull(messages);
201     Assert.assertEquals(messages.size(), 0);
202   }
203
204 }