summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/namingconvention/NovaServerNamingConventionGuideLineValidatorTest.java
blob: 26aad3cdf8ad2ced2db5b5bab9bd519239bd31b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*
 * Copyright © 2016-2018 European Support Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.openecomp.sdc.validation.impl.validators.namingconvention;

import java.io.IOException;
import java.util.Map;
import org.junit.Assert;
import org.junit.Test;
import org.openecomp.core.validation.types.MessageContainer;
import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
import org.openecomp.sdc.validation.impl.validators.NamingConventionGuideLineValidator;
import org.openecomp.sdc.validation.util.ValidationTestUtil;

/**
 * Created by TALIO on 2/28/2017.
 */
public class NovaServerNamingConventionGuideLineValidatorTest {

  NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
  NovaServerNamingConventionGuideLineValidator resourceValidator = new
      NovaServerNamingConventionGuideLineValidator();
  private static final String PATH = "/org/openecomp/validation/validators/guideLineValidator/novaserverValidation/";
  @Test
  public void testHeatNovaServerMetaDataValidation() {
    Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
            resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
            PATH + "heatNovaServerMetaDataValidation/positive/");
    Assert.assertNotNull(messages);
    Assert.assertEquals(messages.size(), 0);

    messages = ValidationTestUtil.testValidator(baseValidator,
            resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
            PATH + "heatNovaServerMetaDataValidation/negative/");
    Assert.assertNotNull(messages);
    Assert.assertEquals(messages.size(), 1);
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 1);
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
            "WARNING: [NNS1]: Missing Nova Server Metadata property, Resource ID [FSB2]");
  }

  @Test
  public void testNovaServerAvailabilityZoneName() {
    Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
            resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
            PATH + "heatNovaServerAvailabilityZoneName/positive");
    Assert.assertNotNull(messages);
    Assert.assertEquals(messages.size(), 0);

    messages = ValidationTestUtil.testValidator(baseValidator,
            resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
            PATH + "heatNovaServerAvailabilityZoneName/negative");
    Assert.assertNotNull(messages);
    Assert.assertEquals(messages.size(), 1);
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 3);
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
            "WARNING: [NNS5]: Server 'Availability Zone' Parameter Name not aligned with Guidelines, Parameter Name [availability_zone_a], Resource ID [FSB2]. As a result, VF/VFC Profile may miss this information");
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(1).getMessage(),
            "WARNING: [NNS5]: Server 'Availability Zone' Parameter Name not aligned with Guidelines, Parameter Name [availability_zone], Resource ID [FSB3]. As a result, VF/VFC Profile may miss this information");
  }

  @Test
  public void testNovaImageAndFlavorNames() {
    Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
            resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
            PATH + "heatNovaServerImageAndFlavor/positive");
    Assert.assertNotNull(messages);
    Assert.assertEquals(messages.size(), 0);

    messages = ValidationTestUtil.testValidator(baseValidator,
            resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
            PATH + "heatNovaServerImageAndFlavor/negative");
    Assert.assertNotNull(messages);
    Assert.assertEquals(messages.size(), 1);
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 2);
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
            "WARNING: [NNS13]: Server 'flavor' Parameter Name not aligned with Guidelines, Parameter Name [fsb2-flavor], Resource ID [FSB2]. As a result, VF/VFC Profile may miss this information");
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(1).getMessage(),
            "WARNING: [NNS13]: Server 'image' Parameter Name not aligned with Guidelines, Parameter Name [fsb2-image], Resource ID [FSB3]. As a result, VF/VFC Profile may miss this information");
  }

  @Test
  public void testNovaResourceNetworkUniqueRole() {
    Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
            resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
            PATH + "heatNovaNetworkUniqueRoleConvention/positive/");
    Assert.assertNotNull(messages);
    Assert.assertEquals(messages.size(), 0);
    messages = ValidationTestUtil.testValidator(baseValidator,
            resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
            PATH + "heatNovaNetworkUniqueRoleConvention/negative/");
    Assert.assertNotNull(messages);
    Assert.assertEquals(messages.size(), 1);
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 1);
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
            "WARNING: [NNS12]: A resource is connected twice to the same network role, Network Role [FSB2], Resource ID [Internal1]");
  }

  @Test
  public void testNovaServerName() {
    Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
            resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
            PATH + "heatNovaServerNameValidation/positive");
    Assert.assertNotNull(messages);
    Assert.assertEquals(messages.size(), 0);

    messages = ValidationTestUtil.testValidator(baseValidator,
            resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
            PATH + "heatNovaServerNameValidation/negative/");
    Assert.assertNotNull(messages);
    Assert.assertEquals(messages.size(), 1);
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 2);
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
            "WARNING: [NNS10]: Server 'name' Parameter Name not aligned with Guidelines, Parameter Name [pcrf_pps_server_4], Resource ID [FSB2]. As a result, VF/VFC Profile may miss this information");
  }

  @Test
  public void testVMNameSyncInNova() {
    Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
            resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
            PATH + "input");

    Assert.assertNotNull(messages);
    Assert.assertEquals(messages.size(), 1);

    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 4);
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
            "WARNING: [NNS10]: Server 'name' Parameter Name not aligned with Guidelines, Parameter Name [CE_server_name], Resource ID [FSB2_legal_2]. As a result, VF/VFC Profile may miss this information");
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(1).getMessage(),
            "WARNING: [NNS13]: Server 'flavor' Parameter Name not aligned with Guidelines, Parameter Name [fsb_flavor_names], Resource ID [FSB2_legal_3]. As a result, VF/VFC Profile may miss this information");
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(2).getMessage(),
            "WARNING: [NNS11]: Nova Server naming convention in image, flavor and name properties is not consistent, Resource ID [FSB2_illegal_1]");
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(3).getMessage(),
            "WARNING: [NNS11]: Nova Server naming convention in image, flavor and name properties is not consistent, Resource ID [FSB2_illegal_2]");
  }

  @Test
  public void testAvailabilityZoneName() throws IOException {
    Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
            resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
            PATH + "availability_zone_name/input");

    Assert.assertNotNull(messages);
    Assert.assertEquals(messages.size(), 1);

    Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 2);
    Assert.assertEquals(
            messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(),
            "WARNING: [NNS5]: Server 'Availability Zone' Parameter Name not aligned with Guidelines, Parameter Name [availability_zone_name], Resource ID [availability_zone_illegal_name_1]. As a result, VF/VFC Profile may miss this information");
    Assert.assertEquals(
            messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(1).getMessage(),
            "WARNING: [NNS5]: Server 'Availability Zone' Parameter Name not aligned with Guidelines, Parameter Name [availability_zone], Resource ID [availability_zone_illegal_name_2]. As a result, VF/VFC Profile may miss this information");
  }

  @Test
  public void testHeatNovaServerVnfIDValidation() {
    Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
            resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
            "/org/openecomp/validation/validators/guideLineValidator/novaserverValidation/heatNovaServerMetaDataValidation/negativemissingvnfid/");
    Assert.assertNotNull(messages);
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 1);
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
            "WARNING: [NNS3]: Missing VNF_ID in Metadata property, Resource ID [FSB2]");
  }

  @Test
  public void testHeatNovaServerVfModuleValidation() {
    Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
            resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
            "/org/openecomp/validation/validators/guideLineValidator/novaserverValidation/heatNovaServerMetaDataValidation/negativemisningvfmodule/");
    Assert.assertNotNull(messages);
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
            "WARNING: [NNS2]: Missing VF_MODULE_ID in Metadata property, Resource id [FSB2]");
  }

  @Test
  public void testMissingParam() {
    Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
            resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
            PATH + "heatNovaNetworkUniqueRoleConvention/missingportNetwork/");
    Assert.assertNotNull(messages);
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 4);
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
            "WARNING: [NNS4]: Missing get_param in network or network_id, Resource Id [FSB2]");
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(1).getMessage(),
            "WARNING: [NNS6]: Missing get_param in availability_zone, Resource Id [FSB2]");
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(2).getMessage(),
            "WARNING: [NNS7]: Missing get_param in nova server name, Resource Id [FSB2]");
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(3).getMessage(),
            "WARNING: [NNS8]: Missing get_param in flavor, Resource Id [FSB2]");
  }

  @Test
  public void testNovaResource() {
    Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
            resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
            PATH + "heatNovaNetworkUniqueRoleConvention/invalidresource/");
    Assert.assertNotNull(messages);
    Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
            "ERROR: [NNS14]: invalid get_resource syntax is in use - 1234 , get_resource function should get the resource id of the referenced resource");
  }

  @Test
  public void testEnvFileContent() {
    Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
            resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(),
            PATH + "heatNovaNetworkUniqueRoleConvention/input/");
    Assert.assertNotNull(messages);
    Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(1).getMessage(),
            "WARNING: [NNS9]: Server 'Name' Parameter Name not aligned with Guidelines, Parameter Name [{key=value}], Resource ID [server_1]. As a result, VF/VFC Profile may miss this information");
  }
}