Initial code drop
[bgpcep.git] / bgp / concepts / src / test / java / org / opendaylight / protocol / bgp / concepts / TableTypeTest.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.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotSame;
13 import static org.junit.Assert.assertNull;
14 import static org.junit.Assert.fail;
15
16 import org.junit.Test;
17 import org.opendaylight.protocol.bgp.concepts.BGPAddressFamily;
18 import org.opendaylight.protocol.bgp.concepts.BGPOrigin;
19 import org.opendaylight.protocol.bgp.concepts.BGPSubsequentAddressFamily;
20 import org.opendaylight.protocol.bgp.concepts.BGPTableType;
21 import org.opendaylight.protocol.bgp.concepts.BaseBGPObjectState;
22
23 import org.opendaylight.protocol.concepts.IPv6;
24
25 public class TableTypeTest {
26
27         @Test
28         public void testTableTypes() {
29                 final BGPTableType tt1 = new BGPTableType(BGPAddressFamily.IPv4, BGPSubsequentAddressFamily.MPLSLabeledVPN);
30                 final BGPTableType tt2 = new BGPTableType(BGPAddressFamily.IPv6, BGPSubsequentAddressFamily.valueOf("MPLSLabeledVPN"));
31                 final BGPTableType tt3 = new BGPTableType(BGPAddressFamily.IPv6, BGPSubsequentAddressFamily.Unicast);
32
33                 assertEquals(IPv6.FAMILY, BGPAddressFamily.IPv6.getAddressFamily());
34                 assertNull(BGPAddressFamily.LinkState.getAddressFamily());
35
36                 try {
37                         new BGPTableType(null, BGPSubsequentAddressFamily.MPLSLabeledVPN);
38                         fail("Null AFI!");
39                 } catch (final NullPointerException e) {
40                         assertEquals("Address family may not be null", e.getMessage());
41                 }
42
43                 try {
44                         new BGPTableType(BGPAddressFamily.valueOf("IPv6"), null);
45                         fail("Null SAFI!");
46                 } catch (final NullPointerException e) {
47                         assertEquals("Subsequent address family may not be null", e.getMessage());
48                 }
49
50                 assertFalse(tt1.equals(tt2));
51                 assertNotSame(tt1.hashCode(), tt2.hashCode());
52                 assertEquals(1, tt2.compareTo(tt1));
53                 assertEquals(1, tt2.compareTo(tt3));
54                 assertEquals(tt1.toString(), tt1.toString());
55                 assertNotSame(tt1.getAddressFamily(), tt2.getAddressFamily());
56                 assertEquals(tt1.getSubsequentAddressFamily(), tt2.getSubsequentAddressFamily());
57         }
58
59         @Test
60         public void testOrigin() {
61                 final BGPOrigin or = BGPOrigin.EGP;
62                 assertEquals(or.name(), "EGP");
63         }
64
65         @Test
66         public void testBaseBGPObjectState() {
67                 final BaseBGPObjectState state = new BaseBGPObjectState(BGPOrigin.INCOMPLETE, null);
68                 final BaseBGPObjectState state1 = new BaseBGPObjectState(BGPOrigin.INCOMPLETE, null);
69                 assertNull(state.getAggregator());
70                 assertEquals(BGPOrigin.INCOMPLETE, state.getOrigin());
71                 assertEquals(state.toString(), state1.toString());
72
73                 final BaseBGPObjectState s = new BaseBGPObjectState(state);
74                 assertEquals(state, s);
75                 assertEquals(state.hashCode(), s.hashCode());
76
77                 assertEquals(s, s.newInstance());
78         }
79 }