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