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
8 package org.opendaylight.protocol.bgp.concepts;
10 import static org.hamcrest.core.IsNot.not;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertNotSame;
14 import static org.junit.Assert.assertThat;
15 import static org.junit.Assert.fail;
17 import org.junit.Test;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
20 public class CommunityTest {
23 public void testCommunity() {
24 new Community(new AsNumber((long) 10), 222);
25 final AsNumber as = new AsNumber((long) 12);
26 final Community c = new Community(as, 12);
27 assertEquals(as, c.getAs());
28 assertEquals(12, c.getSemantics());
32 public void testOverflows() {
34 new Community(new AsNumber((long) 10), -2);
35 fail("Semantics under range.");
36 } catch (final IllegalArgumentException e) {
37 assertEquals("Invalid semantics specified", e.getMessage());
40 new Community(new AsNumber((long) 10), 65536);
41 fail("Semantics above range.");
42 } catch (final IllegalArgumentException e) {
43 assertEquals("Invalid semantics specified", e.getMessage());
48 public void testEquals() {
49 final Community c1 = new Community(new AsNumber((long) 10), 222);
50 final Community c2 = new Community(new AsNumber((long) 10), 222);
52 assertThat(c1, not(new Object()));
56 public void testHashCode() {
57 final Community c1 = new Community(new AsNumber((long) 10), 222);
58 final Community c2 = new Community(new AsNumber((long) 10), 222);
59 assertEquals(c1.hashCode(), c2.hashCode());
63 public void testToString() {
64 final Community c = new Community(new AsNumber((long) 10), 222);
65 assertNotNull(c.toString());
69 public void testValueOf() {
70 final Community comm = Community.valueOf("12:50");
71 assertEquals(comm, new Community(new AsNumber((long) 12), 50));
75 public void testExtendedCommunity() {
76 final ExtendedCommunity ec = new OpaqueExtendedCommunity(false, 5, new byte[] { 1, 2, 3, 4, 5, 6 });
77 final Object ec2 = new RouteOriginCommunity(new AsNumber((long) 84), new byte[] { 1, 2, 3, 4 });
78 assertNotSame(ec, ec2);
79 assertEquals(ec, new OpaqueExtendedCommunity(false, 5, new byte[] { 1, 2, 3, 4, 5, 6 }));
80 assertEquals(ec.hashCode(), (new OpaqueExtendedCommunity(false, 5, new byte[] { 1, 2, 3, 4, 5, 6 })).hashCode());