2 * Copyright (c) 2013 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
9 package org.opendaylight.protocol.concepts;
11 import java.net.InetAddress;
12 import java.util.HashSet;
14 import java.util.TreeSet;
16 import org.junit.Before;
17 import org.junit.Test;
18 import static org.junit.Assert.*;
20 public class IPv6PrefixTest {
21 private Prefix<IPv6Address> p1, p2, p3, p4;
22 private IPv6Address addr;
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"));
34 public void testEquals() {
35 assertTrue(p2.equals(p3));
38 @Test(expected = IllegalArgumentException.class)
39 public void testNegativeLength() {
40 new IPv6Prefix(addr, -1);
43 @Test(expected = IllegalArgumentException.class)
44 public void testLongLength() throws Exception {
45 new IPv6Prefix(addr, 129);
49 public void testHashCode() {
50 final Set<Prefix<IPv6Address>> set = new HashSet<Prefix<IPv6Address>>();
53 assertEquals(1, set.size());
56 assertEquals(2, set.size());
59 assertEquals(2, set.size());
62 assertEquals(3, set.size());
66 public void testCompareTo() {
67 final Set<Prefix<IPv6Address>> set = new TreeSet<Prefix<IPv6Address>>();
70 assertEquals(1, set.size());
73 assertEquals(2, set.size());
76 assertEquals(2, set.size());
79 assertEquals(3, set.size());