BUG-6650: ep-ip/sgt, update/rename models and yangs for sxp-ise-adapter
[groupbasedpolicy.git] / sxp-mapper / src / test / java / org / opendaylight / groupbasedpolicy / sxp / mapper / impl / util / EPTemplateUtilTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.groupbasedpolicy.sxp.mapper.impl.util;
9
10 import org.apache.commons.net.util.SubnetUtils;
11 import org.junit.Assert;
12 import org.junit.Test;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
15
16 /**
17  * Test for {@link EPTemplateUtil}.
18  */
19 public class EPTemplateUtilTest {
20
21     public static final IpPrefix IP_PREFIX_24 = new IpPrefix(new Ipv4Prefix("1.2.3.0/24"));
22     public static final IpPrefix IP_PREFIX_32 = new IpPrefix(new Ipv4Prefix("1.2.3.4/32"));
23
24     @Test
25     public void testIsPlain() throws Exception {
26         Assert.assertFalse(EPTemplateUtil.isPlain(IP_PREFIX_24));
27         Assert.assertTrue(EPTemplateUtil.isPlain(IP_PREFIX_32));
28     }
29
30     @Test
31     public void testBuildSubnetInfoKey() throws Exception {
32         checkSubnetInfoBuilder(IP_PREFIX_24, "1.2.3.1", "1.2.3.254", 254);
33         checkSubnetInfoBuilder(IP_PREFIX_32, "0.0.0.0", "0.0.0.0", 0);
34     }
35
36     private void checkSubnetInfoBuilder(final IpPrefix ipPrefix, final String expectedLow, final String expectedHigh, final int expectedCount) {
37         final SubnetInfoKeyDecorator subnetInfoKey = EPTemplateUtil.buildSubnetInfoKey(ipPrefix);
38         final SubnetUtils.SubnetInfo subnetInfo = subnetInfoKey.getDelegate();
39         Assert.assertEquals(expectedLow, subnetInfo.getLowAddress());
40         Assert.assertEquals(expectedHigh, subnetInfo.getHighAddress());
41         Assert.assertEquals(expectedCount, subnetInfo.getAddressCount());
42         Assert.assertEquals(ipPrefix.getIpv4Prefix().getValue(), subnetInfo.getCidrSignature());
43     }
44 }