Clean all unused and redundant imports in controller.
[controller.git] / opendaylight / sal / api / src / test / java / org / opendaylight / controller / sal / core / EdgeTest.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 /**
11  * @file   EdgeTest.java
12  *
13  * @brief  Unit Tests for Edge element
14  *
15  * Unit Tests for Edge element
16  */
17 package org.opendaylight.controller.sal.core;
18
19 import org.junit.Assert;
20 import org.junit.Test;
21
22 public class EdgeTest {
23     @Test
24     public void testEdgeEquals() {
25         try {
26             Node n0 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
27             NodeConnector c0 = new NodeConnector(
28                     NodeConnector.NodeConnectorIDType.OPENFLOW, new Short(
29                             (short) 0x4), n0);
30
31             Node n1 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
32             NodeConnector c1 = new NodeConnector(
33                     NodeConnector.NodeConnectorIDType.OPENFLOW, new Short(
34                             (short) 0x1), n1);
35
36             Node n2 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
37             NodeConnector c2 = new NodeConnector(
38                     NodeConnector.NodeConnectorIDType.OPENFLOW, new Short(
39                             (short) 0x4), n2);
40
41             Node n3 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
42             NodeConnector c3 = new NodeConnector(
43                     NodeConnector.NodeConnectorIDType.OPENFLOW, new Short(
44                             (short) 0x1), n3);
45
46             Edge e0 = new Edge(c0, c1);
47             Edge e1 = new Edge(c2, c3);
48             // e0 must be equal to e1 to pass the test
49             Assert.assertTrue(e0.equals(e1));
50         } catch (ConstructionException e) {
51             // Exception is NOT expected if raised test will fail
52             Assert.assertTrue(false);
53         }
54     }
55
56     @Test
57     public void testEdgeDifferents() {
58         Node n0, n1, n2, n3;
59         NodeConnector c0, c1, c2, c3;
60         Edge e0, e1;
61         try {
62             // Difference in the tail node
63             n0 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
64             c0 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
65                     new Short((short) 0x4), n0);
66
67             n1 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
68             c1 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
69                     new Short((short) 0x1), n1);
70
71             e0 = new Edge(c0, c1);
72
73             n2 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
74             c2 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
75                     new Short((short) 0x4), n2);
76
77             n3 = new Node(Node.NodeIDType.OPENFLOW, new Long(111L));
78             c3 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
79                     new Short((short) 0x1), n3);
80
81             e0 = new Edge(c0, c1);
82             e1 = new Edge(c2, c3);
83             // e0 must be different from e1 to pass the test
84             Assert.assertTrue(!e0.equals(e1));
85
86             // Difference in the head node
87             n0 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
88             c0 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
89                     new Short((short) 0x4), n0);
90
91             n1 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
92             c1 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
93                     new Short((short) 0x1), n1);
94
95             e0 = new Edge(c0, c1);
96
97             n2 = new Node(Node.NodeIDType.OPENFLOW, new Long(41L));
98             c2 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
99                     new Short((short) 0x4), n2);
100
101             n3 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
102             c3 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
103                     new Short((short) 0x1), n3);
104
105             e0 = new Edge(c0, c1);
106             e1 = new Edge(c2, c3);
107             // e0 must be different from e1 to pass the test
108             Assert.assertTrue(!e0.equals(e1));
109
110             // Difference in the head nodeconnetor
111             n0 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
112             c0 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
113                     new Short((short) 0x4), n0);
114
115             n1 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
116             c1 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
117                     new Short((short) 0x1), n1);
118
119             e0 = new Edge(c0, c1);
120
121             n2 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
122             c2 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
123                     new Short((short) 0x5), n2);
124
125             n3 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
126             c3 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
127                     new Short((short) 0x1), n3);
128
129             e0 = new Edge(c0, c1);
130             e1 = new Edge(c2, c3);
131             // e0 must be different from e1 to pass the test
132             Assert.assertTrue(!e0.equals(e1));
133
134             // Difference in the tail nodeconnetor
135             n0 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
136             c0 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
137                     new Short((short) 0x4), n0);
138
139             n1 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
140             c1 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
141                     new Short((short) 0x1), n1);
142
143             e0 = new Edge(c0, c1);
144
145             n2 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
146             c2 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
147                     new Short((short) 0x4), n2);
148
149             n3 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
150             c3 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
151                     new Short((short) 0x2), n3);
152
153             e0 = new Edge(c0, c1);
154             e1 = new Edge(c2, c3);
155             // e0 must be different from e1 to pass the test
156             Assert.assertTrue(!e0.equals(e1));
157
158             // Difference in the both nodeconnetor/node
159             n0 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
160             c0 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
161                     new Short((short) 0x4), n0);
162
163             n1 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
164             c1 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
165                     new Short((short) 0x1), n1);
166
167             e0 = new Edge(c0, c1);
168
169             n2 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
170             c2 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
171                     new Short((short) 0x4), n2);
172
173             n3 = new Node(Node.NodeIDType.OPENFLOW, new Long(111L));
174             c3 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
175                     new Short((short) 0x2), n3);
176
177             e0 = new Edge(c0, c1);
178             e1 = new Edge(c2, c3);
179             // e0 must be different from e1 to pass the test
180             Assert.assertTrue(!e0.equals(e1));
181         } catch (ConstructionException e) {
182             // Exception is NOT expected if raised test will fail
183             Assert.assertTrue(false);
184         }
185     }
186 }