Make sure invokeOperation is set once
[controller.git] / opendaylight / adsal / 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             @SuppressWarnings("unused")
20             NodeTable of1 = new NodeTable(NodeTable.NodeTableIDType.OPENFLOW, "name", node);
21
22             // If we reach this point the exception was not raised
23             // which should have been the case
24             Assert.assertTrue(false);
25         } catch (ConstructionException e) {
26             // If we reach this point the exception has been raised
27             // and so test passed
28             System.out.println("Got exception as expected!:" + e);
29             Assert.assertTrue(true);
30         }
31     }
32
33     @Test
34     public void testNodeTableOpenFlowOfCorrectType() {
35         try {
36             Node node = NodeCreator.createOFNode((long) 20);
37             NodeTable of1 = new NodeTable(NodeTable.NodeTableIDType.OPENFLOW, Byte.valueOf("10"), node);
38
39             // If we reach this point the exception has not been
40             // raised so we passed the test
41             System.out.println("Got node table:" + of1);
42             Assert.assertTrue(true);
43         } catch (ConstructionException e) {
44             // If we reach this point the exception was raised
45             // which is not expected
46             Assert.assertTrue(false);
47         }
48     }
49
50     @Test
51     public void testTwoOpenFlowNodeTableEquals() {
52         try {
53             Node node1 = NodeCreator.createOFNode((long) 20);
54             NodeTable of1 = new NodeTable(NodeTable.NodeTableIDType.OPENFLOW, Byte.valueOf("10"), node1);
55             NodeTable of2 = new NodeTable(NodeTable.NodeTableIDType.OPENFLOW, Byte.valueOf("10"), node1);
56
57             Assert.assertTrue(of1.equals(of2));
58         } catch (ConstructionException e) {
59             // If we reach this point the exception was raised
60             // which is not expected
61             Assert.assertTrue(false);
62         }
63     }
64
65     @Test
66     public void testTwoOpenFlowNodeTableDifferents() {
67         try {
68             Node node1 = NodeCreator.createOFNode((long) 20);
69             NodeTable of1 = new NodeTable(NodeTable.NodeTableIDType.OPENFLOW, Byte.valueOf("10"), node1);
70             Node node2 = NodeCreator.createOFNode((long) 40);
71             NodeTable of2 = new NodeTable(NodeTable.NodeTableIDType.OPENFLOW, Byte.valueOf("20"), node2);
72
73             Assert.assertTrue(!of1.equals(of2));
74         } catch (ConstructionException e) {
75             // If we reach this point the exception was raised
76             // which is not expected
77             Assert.assertTrue(false);
78         }
79     }
80 }