Do not generate union builders
[mdsal.git] / model / ietf / rfc6991-ietf-inet-types / src / test / java / org / opendaylight / yang / gen / v1 / urn / ietf / params / xml / ns / yang / ietf / inet / types / rev130715 / HostBuilderTest.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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertThrows;
12
13 import org.junit.Test;
14
15 public class HostBuilderTest {
16     @Test
17     public void testGetDefaultInstance() throws Exception {
18         testIpv4("1.1.1.1");
19         testIpv4("192.168.155.100");
20         testIpv4("1.192.1.221");
21         testIpv6("ABCD:EF01:2345:6789:ABCD:EF01:2345:6789");
22         testIpv6("2001:DB8:0:0:8:800:200C:417A");
23         testIpv6("0:0:0:0:0:0:0:0");
24         testIpv6("::1.2.3.4");
25         testIpv6("ABCD:EF01:2345:6789:ABCD:EF01:2345:6789");
26         testIpv6("2001:DB8:0:0:8:800:200C:417A");
27         testIpv6("2001:DB8::8:800:200C:417A");
28         testIpv6("FF01:0:0:0:0:0:0:101");
29         testIpv6("FF01::101");
30         testIpv6("0:0:0:0:0:0:0:1");
31         testIpv6("::1");
32         testIpv6("::");
33         testDomain("test.domainName.org");
34         testDomain("domainName.test");
35         testDomain("test");
36     }
37
38     @Test
39     public void testIllegalArgumentException1() {
40         assertThrows(IllegalArgumentException.class, () -> IetfInetUtil.hostFor("2001:0DB8::CD3/60"));
41     }
42
43     @Test(expected = IllegalArgumentException.class)
44     public void testIllegalArgumentException2() {
45         testDomain("test.invalid.domain.name?");
46     }
47
48     private static void testIpv4(final String ip) {
49         final Host defaultInstance = IetfInetUtil.hostFor(ip);
50         assertEquals(new Host(new IpAddress(new Ipv4Address(ip))), defaultInstance);
51     }
52
53     private static void testIpv6(final String ip) {
54         final Host defaultInstance = IetfInetUtil.hostFor(ip);
55         assertEquals(new Host(new IpAddress(new Ipv6Address(ip))), defaultInstance);
56     }
57
58     private static void testDomain(final String ip) {
59         final Host defaultInstance = IetfInetUtil.hostFor(ip);
60         assertEquals(new Host(new DomainName(ip)), defaultInstance);
61     }
62 }