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;
21 import org.opendaylight.controller.sal.core.ConstructionException;
22 import org.opendaylight.controller.sal.core.Edge;
23 import org.opendaylight.controller.sal.core.Node;
24 import org.opendaylight.controller.sal.core.NodeConnector;
26 public class EdgeTest {
28 public void testEdgeEquals() {
30 Node n0 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
31 NodeConnector c0 = new NodeConnector(
32 NodeConnector.NodeConnectorIDType.OPENFLOW, new Short(
35 Node n1 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
36 NodeConnector c1 = new NodeConnector(
37 NodeConnector.NodeConnectorIDType.OPENFLOW, new Short(
40 Node n2 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
41 NodeConnector c2 = new NodeConnector(
42 NodeConnector.NodeConnectorIDType.OPENFLOW, new Short(
45 Node n3 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
46 NodeConnector c3 = new NodeConnector(
47 NodeConnector.NodeConnectorIDType.OPENFLOW, new Short(
50 Edge e0 = new Edge(c0, c1);
51 Edge e1 = new Edge(c2, c3);
52 // e0 must be equal to e1 to pass the test
53 Assert.assertTrue(e0.equals(e1));
54 } catch (ConstructionException e) {
55 // Exception is NOT expected if raised test will fail
56 Assert.assertTrue(false);
61 public void testEdgeDifferents() {
63 NodeConnector c0, c1, c2, c3;
66 // Difference in the tail node
67 n0 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
68 c0 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
69 new Short((short) 0x4), n0);
71 n1 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
72 c1 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
73 new Short((short) 0x1), n1);
75 e0 = new Edge(c0, c1);
77 n2 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
78 c2 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
79 new Short((short) 0x4), n2);
81 n3 = new Node(Node.NodeIDType.OPENFLOW, new Long(111L));
82 c3 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
83 new Short((short) 0x1), n3);
85 e0 = new Edge(c0, c1);
86 e1 = new Edge(c2, c3);
87 // e0 must be different from e1 to pass the test
88 Assert.assertTrue(!e0.equals(e1));
90 // Difference in the head node
91 n0 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
92 c0 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
93 new Short((short) 0x4), n0);
95 n1 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
96 c1 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
97 new Short((short) 0x1), n1);
99 e0 = new Edge(c0, c1);
101 n2 = new Node(Node.NodeIDType.OPENFLOW, new Long(41L));
102 c2 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
103 new Short((short) 0x4), n2);
105 n3 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
106 c3 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
107 new Short((short) 0x1), n3);
109 e0 = new Edge(c0, c1);
110 e1 = new Edge(c2, c3);
111 // e0 must be different from e1 to pass the test
112 Assert.assertTrue(!e0.equals(e1));
114 // Difference in the head nodeconnetor
115 n0 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
116 c0 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
117 new Short((short) 0x4), n0);
119 n1 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
120 c1 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
121 new Short((short) 0x1), n1);
123 e0 = new Edge(c0, c1);
125 n2 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
126 c2 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
127 new Short((short) 0x5), n2);
129 n3 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
130 c3 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
131 new Short((short) 0x1), n3);
133 e0 = new Edge(c0, c1);
134 e1 = new Edge(c2, c3);
135 // e0 must be different from e1 to pass the test
136 Assert.assertTrue(!e0.equals(e1));
138 // Difference in the tail nodeconnetor
139 n0 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
140 c0 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
141 new Short((short) 0x4), n0);
143 n1 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
144 c1 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
145 new Short((short) 0x1), n1);
147 e0 = new Edge(c0, c1);
149 n2 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
150 c2 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
151 new Short((short) 0x4), n2);
153 n3 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
154 c3 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
155 new Short((short) 0x2), n3);
157 e0 = new Edge(c0, c1);
158 e1 = new Edge(c2, c3);
159 // e0 must be different from e1 to pass the test
160 Assert.assertTrue(!e0.equals(e1));
162 // Difference in the both nodeconnetor/node
163 n0 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
164 c0 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
165 new Short((short) 0x4), n0);
167 n1 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
168 c1 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
169 new Short((short) 0x1), n1);
171 e0 = new Edge(c0, c1);
173 n2 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
174 c2 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
175 new Short((short) 0x4), n2);
177 n3 = new Node(Node.NodeIDType.OPENFLOW, new Long(111L));
178 c3 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
179 new Short((short) 0x2), n3);
181 e0 = new Edge(c0, c1);
182 e1 = new Edge(c2, c3);
183 // e0 must be different from e1 to pass the test
184 Assert.assertTrue(!e0.equals(e1));
185 } catch (ConstructionException e) {
186 // Exception is NOT expected if raised test will fail
187 Assert.assertTrue(false);