Add NoZone support
[mdsal.git] / model / ietf / ietf-inet-types-2013-07-15 / src / test / java / org / opendaylight / yang / gen / v1 / urn / ietf / params / xml / ns / yang / ietf / inet / types / rev130715 / IpAddressBuilderTest.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
9 package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertFalse;
13 import static org.junit.Assert.assertNotNull;
14
15 import java.lang.reflect.Constructor;
16 import org.junit.Test;
17
18 public class IpAddressBuilderTest {
19
20     @Test
21     public void testGetDefaultInstance() throws Exception {
22         final Constructor<IpAddressBuilder> constructor = IpAddressBuilder.class.getDeclaredConstructor();
23         assertFalse(constructor.isAccessible());
24         constructor.setAccessible(true);
25         final IpAddressBuilder newInstance = constructor.newInstance();
26         assertNotNull(newInstance);
27
28         testIpv4("1.1.1.1");
29         testIpv4("192.168.155.100");
30         testIpv4("1.192.1.221");
31         testIpv6("ABCD:EF01:2345:6789:ABCD:EF01:2345:6789");
32         testIpv6("2001:DB8:0:0:8:800:200C:417A");
33         testIpv6("0:0:0:0:0:0:0:0");
34         testIpv6("::1.2.3.4");
35         testIpv6("ABCD:EF01:2345:6789:ABCD:EF01:2345:6789");
36         testIpv6("2001:DB8:0:0:8:800:200C:417A");
37         testIpv6("2001:DB8::8:800:200C:417A");
38         testIpv6("FF01:0:0:0:0:0:0:101");
39         testIpv6("FF01::101");
40         testIpv6("0:0:0:0:0:0:0:1");
41         testIpv6("::1");
42         testIpv6("::");
43     }
44
45     @Test(expected = IllegalArgumentException.class)
46     public void testIllegalArgumentException1() {
47         IpAddressBuilder.getDefaultInstance("badIp");
48     }
49
50     @Test(expected = IllegalArgumentException.class)
51     public void testIllegalArgumentException2() {
52         IpAddressBuilder.getDefaultInstance("2001:0DB8::CD3/60");
53     }
54
55     private static void testIpv4(final String ip) {
56         final IpAddress defaultInstance = IpAddressBuilder.getDefaultInstance(ip);
57         assertEquals(new IpAddress(new Ipv4Address(ip)), defaultInstance);
58     }
59
60     private static void testIpv6(final String ip) {
61         final IpAddress defaultInstance = IpAddressBuilder.getDefaultInstance(ip);
62         assertEquals(new IpAddress(new Ipv6Address(ip)), defaultInstance);
63     }
64 }