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.NamingConventionGuideLineValidator;
25 import org.openecomp.sdc.validation.util.ValidationTestUtil;
28 * Created by TALIO on 2/28/2017.
30 public class NeutronPortNamingConventionValidatorTest {
32 NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
33 NeutronPortNamingConventionValidator resourceValidator = new NeutronPortNamingConventionValidator();
34 private static final String PATH = "/org/openecomp/validation/validators/guideLineValidator/heatPortNetworkNamingConvention/";
36 public void testHeatPortNetworkNamingConvention() {
37 Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
38 resourceValidator, HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
40 Assert.assertNotNull(messages);
41 Assert.assertEquals(messages.size(), 0);
43 messages = new ValidationTestUtil().testValidator(baseValidator,
44 resourceValidator, HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
46 Assert.assertNotNull(messages);
47 Assert.assertEquals(messages.size(), 1);
48 Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 3);
49 Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
50 "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");
54 public void testNeutronFixedIpName() {
55 Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(baseValidator,
56 resourceValidator, HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
57 PATH + "positiveFixedIP");
58 Assert.assertNotNull(messages);
59 Assert.assertEquals(messages.size(), 0);
61 messages = new ValidationTestUtil().testValidator(baseValidator,
62 resourceValidator, HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
63 PATH + "negativeFixedIP/");
64 Assert.assertNotNull(messages);
65 Assert.assertEquals(messages.size(), 1);
66 Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 3);
67 Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
68 "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");
69 Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(1).getMessage(),
70 "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 Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(2).getMessage(),
73 "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");
77 public void testMissingParam() {
78 Map<String, MessageContainer> messages = new ValidationTestUtil().testValidator(new NamingConventionGuideLineValidator(),
79 new NeutronPortNamingConventionValidator(), HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
80 PATH + "missingparam/");
81 Assert.assertNotNull(messages);
82 Assert.assertEquals(1, messages.size());
83 Assert.assertEquals(1, messages.get("first.yaml").getErrorMessageList().size());
84 Assert.assertEquals("WARNING: [NNP2]: Missing get_param in network or network_id, Resource Id [port_resource_2]",
85 messages.get("first.yaml").getErrorMessageList().get(0).getMessage());