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.parser.impl;
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.protocol.bgp.concepts.ExtendedCommunity;
19 import org.opendaylight.protocol.bgp.concepts.OpaqueExtendedCommunity;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
23 public class CommunityTest {
26 public void testCommunity() {
27 CommunityUtil.create(10, 222);
28 final Community c = CommunityUtil.create(12, 12);
29 assertEquals(12, c.getAsNumber().getValue().intValue());
30 assertEquals(12, c.getSemantics().intValue());
34 public void testOverflows() {
36 CommunityUtil.create(10, -2);
37 fail("Semantics under range.");
38 } catch (final IllegalArgumentException e) {
39 assertEquals("Invalid semantics specified", e.getMessage());
42 CommunityUtil.create(10, 65536);
43 fail("Semantics above range.");
44 } catch (final IllegalArgumentException e) {
45 assertEquals("Invalid semantics specified", e.getMessage());
50 public void testEquals() {
51 final Community c1 = CommunityUtil.create(10, 222);
52 final Community c2 = CommunityUtil.create(10, 222);
54 assertThat(c1, not(new Object()));
58 public void testHashCode() {
59 final Community c1 = CommunityUtil.create(10, 222);
60 final Community c2 = CommunityUtil.create(10, 222);
61 assertEquals(c1.hashCode(), c2.hashCode());
65 public void testToString() {
66 final Community c = CommunityUtil.create(10, 222);
67 assertNotNull(c.toString());
71 public void testValueOf() {
72 final Community comm = CommunityUtil.valueOf("12:50");
73 assertEquals(comm, CommunityUtil.create(12, 50));
77 public void testExtendedCommunity() {
78 final ExtendedCommunity ec = new OpaqueExtendedCommunity(false, 5, new byte[] { 1, 2, 3, 4, 5, 6 });
79 final Object ec2 = new RouteOriginCommunity(new AsNumber((long) 84), new byte[] { 1, 2, 3, 4 });
80 assertNotSame(ec, ec2);
81 assertEquals(ec, new OpaqueExtendedCommunity(false, 5, new byte[] { 1, 2, 3, 4, 5, 6 }));
82 assertEquals(ec.hashCode(), (new OpaqueExtendedCommunity(false, 5, new byte[] { 1, 2, 3, 4, 5, 6 })).hashCode());