BGPMessageFactory has been superseded by MessageRegistry
[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.Ignore;
15 import org.junit.Test;
16 import org.opendaylight.protocol.bgp.parser.impl.message.update.CommunityUtil;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
18
19 public class CommunityTest {
20
21         @Test
22         public void testCommunity() {
23                 CommunityUtil.create(10, 222);
24                 final Community c = CommunityUtil.create(12, 12);
25                 assertEquals(12, c.getAsNumber().getValue().intValue());
26                 assertEquals(12, c.getSemantics().intValue());
27         }
28
29         @Test
30         @Ignore
31         // FIXME: range is not implemented
32         public void testOverflows() {
33                 try {
34                         CommunityUtil.create(10, -2);
35                         fail("Semantics under range.");
36                 } catch (final IllegalArgumentException e) {
37                         assertEquals("Invalid semantics specified", e.getMessage());
38                 }
39                 try {
40                         CommunityUtil.create(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 testToString() {
49                 final Community c = CommunityUtil.create(10, 222);
50                 assertNotNull(c.toString());
51         }
52
53         @Test
54         public void testValueOf() {
55                 final Community comm = CommunityUtil.valueOf("12:50");
56                 assertEquals(12, comm.getAsNumber().getValue().intValue());
57                 assertEquals(50, comm.getSemantics().intValue());
58         }
59 }