2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertSame;
15 import java.lang.reflect.Constructor;
16 import org.junit.Test;
18 public class IetfInetUtilTest {
21 public void testIetfInetUtilConstructor() throws Exception {
22 final Constructor<IetfInetUtil> constructor = IetfInetUtil.class.getDeclaredConstructor();
23 assertFalse(constructor.isAccessible());
24 constructor.setAccessible(true);
26 final IetfInetUtil newInstance = constructor.newInstance();
27 assertNotNull(newInstance);
31 public void testIpv4Address() {
32 final Ipv4AddressNoZone ipv4Address = new Ipv4AddressNoZone("192.168.1.1");
33 final Ipv4Prefix ipv4Prefix = new Ipv4Prefix("192.0.2.1/24");
34 final IpAddress ipAddress = IetfInetUtil.INSTANCE.ipv4Address(ipv4Address);
35 final String ipv4AddressString = IetfInetUtil.INSTANCE.ipv4AddressString(ipv4Address);
36 final Ipv4Address maybeIpv4Address = IetfInetUtil.INSTANCE.maybeIpv4Address(new IpAddress(ipv4Address));
37 final IpPrefix ipPrefix = IetfInetUtil.INSTANCE.ipv4Prefix(ipv4Prefix);
38 final String ipv4PrefixString = IetfInetUtil.INSTANCE.ipv4PrefixString(ipv4Prefix);
40 assertEquals(ipv4PrefixString, ipPrefix.getIpv4Prefix().getValue());
41 assertNotNull(maybeIpv4Address);
42 assertEquals(ipv4AddressString, maybeIpv4Address.getValue());
43 assertEquals(ipAddress, new IpAddress(ipv4Address));
47 public void testIpv6Address() {
48 final Ipv6AddressNoZone ipv6Address = new Ipv6AddressNoZone("ABCD:EF01:2345:6789:ABCD:EF01:2345:6789");
49 final Ipv6Prefix ipv6Prefix = new Ipv6Prefix("ff00::/8");
50 final IpAddress ipAddress = IetfInetUtil.INSTANCE.ipv6Address(ipv6Address);
51 final String ipv6AddressString = IetfInetUtil.INSTANCE.ipv6AddressString(ipv6Address);
52 final Ipv6Address maybeIpv6Address = IetfInetUtil.INSTANCE.maybeIpv6Address(new IpAddress(ipv6Address));
53 final IpPrefix ipPrefix = IetfInetUtil.INSTANCE.ipv6Prefix(ipv6Prefix);
54 final String ipv6PrefixString = IetfInetUtil.INSTANCE.ipv6PrefixString(ipv6Prefix);
56 assertEquals(ipv6PrefixString, ipPrefix.getIpv6Prefix().getValue());
57 assertNotNull(maybeIpv6Address);
58 assertEquals(ipv6AddressString, maybeIpv6Address.getValue());
59 assertEquals(ipAddress, new IpAddress(ipv6Address));
63 public void testAddressToString() {
64 assertEquals(new Ipv4Prefix("1.2.3.4/8"), IetfInetUtil.INSTANCE.ipv4PrefixFor(new Ipv4Address("1.2.3.4%1"), 8));
65 assertEquals(new Ipv6Prefix("ff00::/8"), IetfInetUtil.INSTANCE.ipv6PrefixFor(new Ipv6Address("ff00::%bar"), 8));
69 public void testIpv4ZoneStripping() {
70 final Ipv4AddressNoZone noZone = new Ipv4AddressNoZone("1.2.3.4");
71 assertSame(noZone, IetfInetUtil.INSTANCE.ipv4AddressNoZoneFor(noZone));
73 final Ipv4Address withoutZone = new Ipv4Address(noZone);
74 final Ipv4AddressNoZone stripped = IetfInetUtil.INSTANCE.ipv4AddressNoZoneFor(withoutZone);
75 assertSame(withoutZone.getValue(), stripped.getValue());
77 assertEquals(noZone, IetfInetUtil.INSTANCE.ipv4AddressNoZoneFor(new Ipv4Address("1.2.3.4%1")));
81 public void testIpv6ZoneStripping() {
82 final Ipv6AddressNoZone noZone = new Ipv6AddressNoZone("ff00::");
83 assertSame(noZone, IetfInetUtil.INSTANCE.ipv6AddressNoZoneFor(noZone));
85 final Ipv6Address withoutZone = new Ipv6Address(noZone);
86 final Ipv6AddressNoZone stripped = IetfInetUtil.INSTANCE.ipv6AddressNoZoneFor(withoutZone);
87 assertSame(withoutZone.getValue(), stripped.getValue());
89 assertEquals(noZone, IetfInetUtil.INSTANCE.ipv6AddressNoZoneFor(new Ipv6Address("ff00::%1")));