1bc4a66a19feb0993a8aecd2339c4c8685cefeff
[bgpcep.git] / bgp / parser-impl / src / test / java / org / opendaylight / protocol / bgp / parser / impl / 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.parser.impl;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.fail;
13
14 import org.junit.Test;
15 import org.opendaylight.protocol.bgp.parser.impl.message.update.CommunityUtil;
16 import org.opendaylight.protocol.util.NoopReferenceCache;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Community;
18
19 public class CommunityTest {
20     final CommunityUtil util = new CommunityUtil(NoopReferenceCache.getInstance());
21
22     @Test
23     public void testCommunity() {
24         this.util.create(10, 222);
25         final Community c = this.util.create(12, 12);
26         assertEquals(12, c.getAsNumber().getValue().intValue());
27         assertEquals(12, c.getSemantics().intValue());
28     }
29
30     @Test
31     public void testOverflows() {
32         try {
33             this.util.create(10, -2);
34             fail("Semantics under range.");
35         } catch (final IllegalArgumentException e) {
36             assertEquals("Invalid range: -2, expected: [[0..65535]].", e.getMessage());
37         }
38         try {
39             this.util.create(10, 65536);
40             fail("Semantics above range.");
41         } catch (final IllegalArgumentException e) {
42             assertEquals("Invalid range: 65536, expected: [[0..65535]].", e.getMessage());
43         }
44     }
45
46     @Test
47     public void testToString() {
48         final Community c = this.util.create(10, 222);
49         assertNotNull(c.toString());
50     }
51
52     @Test
53     public void testValueOf() {
54         final Community comm = this.util.valueOf("12:50");
55         assertEquals(12, comm.getAsNumber().getValue().intValue());
56         assertEquals(50, comm.getSemantics().intValue());
57     }
58 }