Initial code drop
[bgpcep.git] / concepts / src / test / java / org / opendaylight / protocol / concepts / IPv6PrefixTest.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
9 package org.opendaylight.protocol.concepts;
10
11 import java.net.InetAddress;
12 import java.util.HashSet;
13 import java.util.Set;
14 import java.util.TreeSet;
15
16 import org.junit.Before;
17 import org.junit.Test;
18 import static org.junit.Assert.*;
19
20 public class IPv6PrefixTest {
21         private Prefix<IPv6Address> p1, p2, p3, p4;
22         private IPv6Address addr;
23
24         @Before
25         public void setUp() throws Exception {
26                 p1 = new IPv6Prefix(new IPv6Address(InetAddress.getByName("2001:db8:85a3:0:0:8a2e:370:7331")), 128);
27                 p2 = new IPv6Prefix(new IPv6Address(InetAddress.getByName("2001:db8:85a3:0:0:8a2e:370:7332")), 128);
28                 p3 = new IPv6Prefix(new IPv6Address(InetAddress.getByName("2001:db8:85a3:0:0:8a2e:370:7332")), 128);
29                 p4 = new IPv6Prefix(new IPv6Address(InetAddress.getByName("2001:db8:85a3:0:0:8a2e:370:7300")), 120);
30                 addr = new IPv6Address(InetAddress.getByName("2001:db8:85a3:0:0:8a2e:370:7331"));
31         }
32
33         @Test
34         public void testEquals() {
35                 assertTrue(p2.equals(p3));
36         }
37
38         @Test(expected = IllegalArgumentException.class)
39         public void testNegativeLength() {
40                 new IPv6Prefix(addr, -1);
41         }
42
43         @Test(expected = IllegalArgumentException.class)
44         public void testLongLength() throws Exception {
45                 new IPv6Prefix(addr, 129);
46         }
47
48         @Test
49         public void testHashCode() {
50                 final Set<Prefix<IPv6Address>> set = new HashSet<Prefix<IPv6Address>>();
51
52                 set.add(p1);
53                 assertEquals(1, set.size());
54
55                 set.add(p2);
56                 assertEquals(2, set.size());
57
58                 set.add(p3);
59                 assertEquals(2, set.size());
60
61                 set.add(p4);
62                 assertEquals(3, set.size());
63         }
64
65         @Test
66         public void testCompareTo() {
67                 final Set<Prefix<IPv6Address>> set = new TreeSet<Prefix<IPv6Address>>();
68
69                 set.add(p1);
70                 assertEquals(1, set.size());
71
72                 set.add(p2);
73                 assertEquals(2, set.size());
74
75                 set.add(p3);
76                 assertEquals(2, set.size());
77
78                 set.add(p4);
79                 assertEquals(3, set.size());
80         }
81 }
82