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.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.fail;
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;
19 public class CommunityTest {
20 final CommunityUtil util = new CommunityUtil(NoopReferenceCache.getInstance());
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());
31 public void testOverflows() {
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());
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());
47 public void testToString() {
48 final Community c = this.util.create(10, 222);
49 assertNotNull(c.toString());
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());