Add 'TableStatistics' to SAL and Northbound Statistics API.
[controller.git] / opendaylight / sal / api / src / test / java / org / opendaylight / controller / sal / core / NodeTableTest.java
1 /*
2  * Copyright (c) 2013 Big Switch Networks, Inc.  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.controller.sal.core;
9
10 import org.junit.Assert;
11 import org.junit.Test;
12 import org.opendaylight.controller.sal.utils.NodeCreator;
13
14 public class NodeTableTest {
15     @Test
16     public void testNodeTableOpenFlowOfWrongType() {
17         try {
18             Node node = NodeCreator.createOFNode((long) 20);
19             NodeTable of1 = new NodeTable(NodeTable.NodeTableIDType.OPENFLOW, "name", node);
20
21             // If we reach this point the exception was not raised
22             // which should have been the case
23             Assert.assertTrue(false);
24         } catch (ConstructionException e) {
25             // If we reach this point the exception has been raised
26             // and so test passed
27             System.out.println("Got exception as expected!:" + e);
28             Assert.assertTrue(true);
29         }
30     }
31
32     @Test
33     public void testNodeTableOpenFlowOfCorrectType() {
34         try {
35             Node node = NodeCreator.createOFNode((long) 20);
36             NodeTable of1 = new NodeTable(NodeTable.NodeTableIDType.OPENFLOW, Byte.valueOf("10"), node);
37
38             // If we reach this point the exception has not been
39             // raised so we passed the test
40             System.out.println("Got node table:" + of1);
41             Assert.assertTrue(true);
42         } catch (ConstructionException e) {
43             // If we reach this point the exception was raised
44             // which is not expected
45             Assert.assertTrue(false);
46         }
47     }
48
49     @Test
50     public void testTwoOpenFlowNodeTableEquals() {
51         try {
52             Node node1 = NodeCreator.createOFNode((long) 20);
53             NodeTable of1 = new NodeTable(NodeTable.NodeTableIDType.OPENFLOW, Byte.valueOf("10"), node1);
54             NodeTable of2 = new NodeTable(NodeTable.NodeTableIDType.OPENFLOW, Byte.valueOf("10"), node1);
55
56             Assert.assertTrue(of1.equals(of2));
57         } catch (ConstructionException e) {
58             // If we reach this point the exception was raised
59             // which is not expected
60             Assert.assertTrue(false);
61         }
62     }
63
64     @Test
65     public void testTwoOpenFlowNodeTableDifferents() {
66         try {
67             Node node1 = NodeCreator.createOFNode((long) 20);
68             NodeTable of1 = new NodeTable(NodeTable.NodeTableIDType.OPENFLOW, Byte.valueOf("10"), node1);
69             Node node2 = NodeCreator.createOFNode((long) 40);
70             NodeTable of2 = new NodeTable(NodeTable.NodeTableIDType.OPENFLOW, Byte.valueOf("20"), node2);
71
72             Assert.assertTrue(!of1.equals(of2));
73         } catch (ConstructionException e) {
74             // If we reach this point the exception was raised
75             // which is not expected
76             Assert.assertTrue(false);
77         }
78     }
79 }