BUG-45 : migrated AsNumber to generated source code.
[bgpcep.git] / bgp / concepts / src / test / java / org / opendaylight / protocol / bgp / concepts / CommunityTest.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.bgp.concepts;
9
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;
16
17 import org.junit.Test;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
19
20 public class CommunityTest {
21
22         @Test
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());
29         }
30
31         @Test
32         public void testOverflows() {
33                 try {
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());
38                 }
39                 try {
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());
44                 }
45         }
46
47         @Test
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);
51                 assertEquals(c1, c2);
52                 assertThat(c1, not(new Object()));
53         }
54
55         @Test
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());
60         }
61
62         @Test
63         public void testToString() {
64                 final Community c = new Community(new AsNumber((long) 10), 222);
65                 assertNotNull(c.toString());
66         }
67
68         @Test
69         public void testValueOf() {
70                 final Community comm = Community.valueOf("12:50");
71                 assertEquals(comm, new Community(new AsNumber((long) 12), 50));
72         }
73
74         @Test
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());
81         }
82 }