de047b8feecf285670fd4683ed871722f790aaf5
[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.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 /**
28  * Created by TALIO on 2/28/2017.
29  */
30 public class NeutronPortNamingConventionValidatorTest {
31
32   NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
33   NeutronPortNamingConventionValidator resourceValidator = new
34       NeutronPortNamingConventionValidator();
35   private static final  String PATH = "/org/openecomp/validation/validators/guideLineValidator/heatPortNetworkNamingConvention/";
36   @Test
37   public void testHeatPortNetworkNamingConvention() {
38     Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
39             resourceValidator, HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
40             PATH + "positive/");
41     Assert.assertNotNull(messages);
42     Assert.assertEquals(messages.size(), 0);
43
44     messages = ValidationTestUtil.testValidator(baseValidator,
45             resourceValidator, HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
46             PATH + "negative/");
47     Assert.assertNotNull(messages);
48     Assert.assertEquals(messages.size(), 1);
49     Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 3);
50     Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
51             "WARNING: [NNP3]: Port 'Network' Parameter Name not aligned with Guidelines, Parameter Name [not_valid_network_name], Resource ID [port_resource]. As a result, VF/VFC Profile may miss this information");
52   }
53
54   @Test
55   public void testNeutronFixedIpName() {
56     Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
57             resourceValidator, HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
58             PATH + "positiveFixedIP");
59     Assert.assertNotNull(messages);
60     Assert.assertEquals(messages.size(), 0);
61
62     messages = ValidationTestUtil.testValidator(baseValidator,
63             resourceValidator, HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
64             PATH + "negativeFixedIP/");
65     Assert.assertNotNull(messages);
66     Assert.assertEquals(messages.size(), 1);
67     Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 4);
68     Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
69             "WARNING: [NNP1]: Port 'Fixed_IPS' Parameter Name not aligned with Guidelines, Parameter Name [pcrf_net_v6_ip_a], Resource ID [port_resource_0]. As a result, VF/VFC Profile may miss this information");
70     Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(1).getMessage(),
71             "WARNING: [NNP1]: Port 'Fixed_IPS' Parameter Name not aligned with Guidelines, Parameter Name [indx], Resource ID [port_resource_1]. As a result, VF/VFC Profile may miss this information");
72
73     Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(2).getMessage(),
74             "WARNING: [NNP1]: Port 'Fixed_IPS' Parameter Name not aligned with Guidelines, Parameter Name [pcrf_net_ipz], Resource ID [port_resource_2]. As a result, VF/VFC Profile may miss this information");
75
76     Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(3).getMessage(),
77             "WARNING: [NNP1]: Port 'Fixed_IPS' Parameter Name not aligned with Guidelines, Parameter Name [pcrf_net_v0_ip_3], Resource ID [port_resource_2]. As a result, VF/VFC Profile may miss this information");
78   }
79
80   @Test
81   public void testMissingParam() {
82     Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
83             resourceValidator, HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
84             PATH + "missingparam/");
85     Assert.assertNotNull(messages);
86     Assert.assertEquals(messages.size(), 1);
87     Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 1);
88     Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
89             "WARNING: [NNP2]: Missing get_param in network or network_id, Resource Id [port_resource_2]");
90   }
91 }