Initial opendaylight infrastructure commit!!
[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 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;
25
26 public class EdgeTest {
27     @Test
28     public void testEdgeEquals() {
29         try {
30             Node n0 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
31             NodeConnector c0 = new NodeConnector(
32                     NodeConnector.NodeConnectorIDType.OPENFLOW, new Short(
33                             (short) 0x4), n0);
34
35             Node n1 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
36             NodeConnector c1 = new NodeConnector(
37                     NodeConnector.NodeConnectorIDType.OPENFLOW, new Short(
38                             (short) 0x1), n1);
39
40             Node n2 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
41             NodeConnector c2 = new NodeConnector(
42                     NodeConnector.NodeConnectorIDType.OPENFLOW, new Short(
43                             (short) 0x4), n2);
44
45             Node n3 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
46             NodeConnector c3 = new NodeConnector(
47                     NodeConnector.NodeConnectorIDType.OPENFLOW, new Short(
48                             (short) 0x1), n3);
49
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);
57         }
58     }
59
60     @Test
61     public void testEdgeDifferents() {
62         Node n0, n1, n2, n3;
63         NodeConnector c0, c1, c2, c3;
64         Edge e0, e1;
65         try {
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);
70
71             n1 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
72             c1 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
73                     new Short((short) 0x1), n1);
74
75             e0 = new Edge(c0, c1);
76
77             n2 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
78             c2 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
79                     new Short((short) 0x4), n2);
80
81             n3 = new Node(Node.NodeIDType.OPENFLOW, new Long(111L));
82             c3 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
83                     new Short((short) 0x1), n3);
84
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));
89
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);
94
95             n1 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
96             c1 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
97                     new Short((short) 0x1), n1);
98
99             e0 = new Edge(c0, c1);
100
101             n2 = new Node(Node.NodeIDType.OPENFLOW, new Long(41L));
102             c2 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
103                     new Short((short) 0x4), n2);
104
105             n3 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
106             c3 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
107                     new Short((short) 0x1), n3);
108
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));
113
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);
118
119             n1 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
120             c1 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
121                     new Short((short) 0x1), n1);
122
123             e0 = new Edge(c0, c1);
124
125             n2 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
126             c2 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
127                     new Short((short) 0x5), n2);
128
129             n3 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
130             c3 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
131                     new Short((short) 0x1), n3);
132
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));
137
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);
142
143             n1 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
144             c1 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
145                     new Short((short) 0x1), n1);
146
147             e0 = new Edge(c0, c1);
148
149             n2 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
150             c2 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
151                     new Short((short) 0x4), n2);
152
153             n3 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
154             c3 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
155                     new Short((short) 0x2), n3);
156
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));
161
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);
166
167             n1 = new Node(Node.NodeIDType.OPENFLOW, new Long(110L));
168             c1 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
169                     new Short((short) 0x1), n1);
170
171             e0 = new Edge(c0, c1);
172
173             n2 = new Node(Node.NodeIDType.OPENFLOW, new Long(40L));
174             c2 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
175                     new Short((short) 0x4), n2);
176
177             n3 = new Node(Node.NodeIDType.OPENFLOW, new Long(111L));
178             c3 = new NodeConnector(NodeConnector.NodeConnectorIDType.OPENFLOW,
179                     new Short((short) 0x2), n3);
180
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);
188         }
189     }
190 }