Initial code drop
[bgpcep.git] / concepts / src / test / java / org / opendaylight / protocol / concepts / IPAddressesAndPrefixesTest.java
1 /*
2  * Copyright (c) 2013 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.protocol.concepts;
9
10 import static org.junit.Assert.assertTrue;
11
12 import java.net.InetAddress;
13 import java.net.UnknownHostException;
14
15 import org.junit.Test;
16
17 import org.opendaylight.protocol.concepts.IPv4;
18 import org.opendaylight.protocol.concepts.IPv4Address;
19 import org.opendaylight.protocol.concepts.IPv6;
20 import org.opendaylight.protocol.concepts.IPv6Address;
21
22 public class IPAddressesAndPrefixesTest {
23
24         @Test
25         public void test1(){
26                 assertTrue(IPAddresses.parseNetworkAddress("123.123.123.123") instanceof IPv4Address);
27                 assertTrue(IPAddresses.parseNetworkAddress("2001::1") instanceof IPv6Address);
28         }
29
30         @Test(expected = IllegalArgumentException.class)
31         public void test2(){
32                 IPAddresses.parseNetworkAddress("256.125.126.256");
33         }
34
35         @Test
36         public void test3() {
37                 assertTrue("123.123.123.123".equals(IPv4.FAMILY.addressForString("123.123.123.123").toString()));
38                 assertTrue("2001:0:0:0:0:0:0:1".equals(IPv6.FAMILY.addressForString("2001::1").toString()));
39         }
40
41         @Test
42         public void test4() throws UnknownHostException{
43                 assertTrue(IPAddresses.createNetworkAddress(InetAddress.getByName("123.123.123.123")) instanceof IPv4Address);
44                 assertTrue(IPAddresses.createNetworkAddress(InetAddress.getByName("2001::1")) instanceof IPv6Address);
45         }
46
47         @Test
48         public void test5() {
49                 assertTrue("123.123.123.0/24".equals(IPv4.FAMILY.addressForString("123.123.123.123").asPrefix(24).toString()));
50                 assertTrue("123.123.123.0/24".equals(IPv4.FAMILY.prefixForString("123.123.123.123/24").toString()));
51                 assertTrue("2001:0:0:0:0:0:0:0/120".equals(IPv6.FAMILY.addressForString("2001::1").asPrefix(120).toString()));
52                 assertTrue("2001:0:0:0:0:0:0:0/120".equals(IPv6.FAMILY.prefixForString("2001::1/120").toString()));
53         }
54 }