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.HeatResourceValidator;
25 import org.openecomp.sdc.validation.util.ValidationTestUtil;
28 * Created by TALIO on 2/28/2017.
30 public class ContrailServiceTemplateNamingConventionValidatorTest {
32 HeatResourceValidator baseValidator = new HeatResourceValidator();
33 ContrailServiceTemplateNamingConventionValidator resourceValidator = new
34 ContrailServiceTemplateNamingConventionValidator();
35 private static final String PATH="/org/openecomp/validation/validators/guideLineValidator/heatcontrailservicetemplateimageandflavor/";
38 public void testContrailServiceTemplateImageAndFlavorNamesAlignedWithNamingConventionButDifferentVmType() {
39 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
40 resourceValidator, HeatResourcesTypes.CONTRAIL_SERVICE_TEMPLATE.getHeatResource(),
41 PATH + "imageandflavordifferentvmtype");
42 Assert.assertNotNull(messages);
43 Assert.assertEquals(messages.size(), 1);
45 messages.get(messages.keySet().iterator().next()).getErrorMessageList().size(), 1);
46 Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
47 "WARNING: [NST1]: Service Template naming convention in Image and Flavor properties is not consistent in Resource, Resource ID service_template");
51 public void testContrailServiceTemplateImageAndFlavorNamesNotAlignedWithNamingConvention() {
52 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
53 resourceValidator, HeatResourcesTypes.CONTRAIL_SERVICE_TEMPLATE.getHeatResource(),
54 PATH + "/notaligned");
55 Assert.assertNotNull(messages);
56 Assert.assertEquals(messages.size(), 1);
57 Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 2);
58 Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
59 "WARNING: [NST3]: Service Template 'image_name' Parameter Name not aligned with Guidelines, Parameter Name [st_imaage_name], Resource ID [service_template]. As a result, VF/VFC Profile may miss this information");
60 Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(1).getMessage(),
61 "WARNING: [NST3]: Service Template 'flavor' Parameter Name not aligned with Guidelines, Parameter Name [st_flavaor_name], Resource ID [service_template]. As a result, VF/VFC Profile may miss this information");
65 public void testContrailServiceTemplateImageAndFlavorNamesAlignedWithNamingConvention() {
66 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
67 resourceValidator, HeatResourcesTypes.CONTRAIL_SERVICE_TEMPLATE.getHeatResource(),
69 Assert.assertNotNull(messages);
70 Assert.assertEquals(messages.size(), 0);
74 public void testContrailServiceTemplateMissingParam() {
75 Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
76 resourceValidator, HeatResourcesTypes.CONTRAIL_SERVICE_TEMPLATE.getHeatResource(),
77 PATH + "missingparam");
78 Assert.assertNotNull(messages);
79 Assert.assertEquals(messages.size(), 1);
81 messages.get(messages.keySet().iterator().next()).getErrorMessageList().size(), 1);
82 Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
83 "WARNING: [NST2]: Missing get_param in image_name, Resource Id [service_template]");