3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
13 * @brief Unit Tests for Edge element
15 * Unit Tests for Edge element
17 package org.opendaylight.controller.sal.core;
19 import org.junit.Assert;
20 import org.junit.Test;
22 public class EdgeTest {
24 public void testEdgeEquals() {
26 Node n0 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
27 NodeConnector c0 = new NodeConnector(
28 NodeConnector.NodeConnectorIDType.OPENFLOW, new Short(
31 Node n1 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
32 NodeConnector c1 = new NodeConnector(
33 NodeConnector.NodeConnectorIDType.OPENFLOW, new Short(
36 Node n2 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
37 NodeConnector c2 = new NodeConnector(
38 NodeConnector.NodeConnectorIDType.OPENFLOW, new Short(
41 Node n3 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
42 NodeConnector c3 = new NodeConnector(
43 NodeConnector.NodeConnectorIDType.OPENFLOW, new Short(
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);
57 public void testEdgeDifferents() {
59 NodeConnector c0, c1, c2, c3;
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);
67 n1 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
68 c1 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
69 new Short((short) 0x1), n1);
71 e0 = new Edge(c0, c1);
73 n2 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
74 c2 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
75 new Short((short) 0x4), n2);
77 n3 = new Node(Node.NodeIDType.OPENFLOW, new Long(111L));
78 c3 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
79 new Short((short) 0x1), n3);
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));
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);
91 n1 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
92 c1 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
93 new Short((short) 0x1), n1);
95 e0 = new Edge(c0, c1);
97 n2 = new Node(Node.NodeIDType.OPENFLOW, new Long(41L));
98 c2 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
99 new Short((short) 0x4), n2);
101 n3 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
102 c3 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
103 new Short((short) 0x1), n3);
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));
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);
115 n1 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
116 c1 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
117 new Short((short) 0x1), n1);
119 e0 = new Edge(c0, c1);
121 n2 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
122 c2 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
123 new Short((short) 0x5), n2);
125 n3 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
126 c3 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
127 new Short((short) 0x1), n3);
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));
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);
139 n1 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
140 c1 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
141 new Short((short) 0x1), n1);
143 e0 = new Edge(c0, c1);
145 n2 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
146 c2 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
147 new Short((short) 0x4), n2);
149 n3 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
150 c3 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
151 new Short((short) 0x2), n3);
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));
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);
163 n1 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
164 c1 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
165 new Short((short) 0x1), n1);
167 e0 = new Edge(c0, c1);
169 n2 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
170 c2 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
171 new Short((short) 0x4), n2);
173 n3 = new Node(Node.NodeIDType.OPENFLOW, new Long(111L));
174 c3 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
175 new Short((short) 0x2), n3);
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);