Add checkstyle rule UpperEll and fix all code accordingly.
[controller.git] / opendaylight / samples / simpleforwarding / src / test / java / org / opendaylight / controller / samples / simpleforwarding / internal / HostSwitchTest.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 package org.opendaylight.controller.samples.simpleforwarding.internal;
11
12 import java.net.InetAddress;
13 import java.net.UnknownHostException;
14 import java.util.HashMap;
15 import org.junit.Test;
16 import org.junit.Assert;
17
18 import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector;
19 import org.opendaylight.controller.sal.core.ConstructionException;
20 import org.opendaylight.controller.sal.utils.NodeCreator;
21 import org.opendaylight.controller.samples.simpleforwarding.HostNodePair;
22
23
24 public class HostSwitchTest {
25     @Test
26     public void TestEquality() {
27         HostNodeConnector h1 = null;
28         HostNodeConnector h2 = null;
29
30         InetAddress ip1 = null;
31         try {
32             ip1 = InetAddress.getByName("10.0.0.1");
33         } catch (UnknownHostException e) {
34             return;
35         }
36         InetAddress ip2 = null;
37         try {
38             ip2 = InetAddress.getByName("10.0.0.1");
39         } catch (UnknownHostException e) {
40             return;
41         }
42         try {
43             h1 = new HostNodeConnector(ip1);
44         } catch (ConstructionException e) {
45             return;
46         }
47         try {
48             h2 = new HostNodeConnector(ip2);
49         } catch (ConstructionException e) {
50             return;
51         }
52         HostNodePair hsw1 = new HostNodePair(h1, NodeCreator.createOFNode(1L));
53         HostNodePair hsw2 = new HostNodePair(h2, NodeCreator.createOFNode(1L));
54         Assert.assertTrue(hsw1.equals(hsw2));
55     }
56
57     @Test
58     public void TestDiversityHost() {
59         HostNodeConnector h1 = null;
60         HostNodeConnector h2 = null;
61         InetAddress ip1 = null;
62         try {
63             ip1 = InetAddress.getByName("10.0.0.1");
64         } catch (UnknownHostException e) {
65             return;
66         }
67         InetAddress ip2 = null;
68         try {
69             ip2 = InetAddress.getByName("10.0.0.2");
70         } catch (UnknownHostException e) {
71             return;
72         }
73         try {
74             h1 = new HostNodeConnector(ip1);
75         } catch (ConstructionException e) {
76             return;
77         }
78         try {
79             h2 = new HostNodeConnector(ip2);
80         } catch (ConstructionException e) {
81             return;
82         }
83
84         HostNodePair hsw1 = new HostNodePair(h1, NodeCreator.createOFNode(1L));
85         HostNodePair hsw2 = new HostNodePair(h2, NodeCreator.createOFNode(1L));
86         Assert.assertTrue(!hsw1.equals(hsw2));
87     }
88
89     @Test
90     public void TestDiversitySwitch() {
91         HostNodeConnector h1 = null;
92         HostNodeConnector h2 = null;
93         InetAddress ip1 = null;
94         try {
95             ip1 = InetAddress.getByName("10.0.0.1");
96         } catch (UnknownHostException e) {
97             return;
98         }
99         InetAddress ip2 = null;
100         try {
101             ip2 = InetAddress.getByName("10.0.0.1");
102         } catch (UnknownHostException e) {
103             return;
104         }
105         try {
106             h1 = new HostNodeConnector(ip1);
107         } catch (ConstructionException e) {
108             return;
109         }
110         try {
111             h2 = new HostNodeConnector(ip2);
112         } catch (ConstructionException e) {
113             return;
114         }
115
116         HostNodePair hsw1 = new HostNodePair(h1, NodeCreator.createOFNode(1L));
117         HostNodePair hsw2 = new HostNodePair(h2, NodeCreator.createOFNode(2L));
118         Assert.assertTrue(!hsw1.equals(hsw2));
119     }
120
121     @Test
122     public void TestDiversityAll() {
123         HostNodeConnector h1 = null;
124         HostNodeConnector h2 = null;
125         InetAddress ip1 = null;
126         try {
127             ip1 = InetAddress.getByName("10.0.0.1");
128         } catch (UnknownHostException e) {
129             return;
130         }
131         InetAddress ip2 = null;
132         try {
133             ip2 = InetAddress.getByName("10.0.0.2");
134         } catch (UnknownHostException e) {
135             return;
136         }
137         try {
138             h1 = new HostNodeConnector(ip1);
139         } catch (ConstructionException e) {
140             return;
141         }
142         try {
143             h2 = new HostNodeConnector(ip2);
144         } catch (ConstructionException e) {
145             return;
146         }
147
148         HostNodePair hsw1 = new HostNodePair(h1, NodeCreator.createOFNode(1L));
149         HostNodePair hsw2 = new HostNodePair(h2, NodeCreator.createOFNode(2L));
150         Assert.assertTrue(!hsw1.equals(hsw2));
151     }
152
153     @Test
154     public void TestEqualHashCode1() {
155         HostNodeConnector h1 = null;
156         HostNodeConnector h2 = null;
157         InetAddress ip1 = null;
158         try {
159             ip1 = InetAddress.getByName("10.0.0.1");
160         } catch (UnknownHostException e) {
161             return;
162         }
163         InetAddress ip2 = null;
164         try {
165             ip2 = InetAddress.getByName("10.0.0.1");
166         } catch (UnknownHostException e) {
167             return;
168         }
169         try {
170             h1 = new HostNodeConnector(ip1);
171         } catch (ConstructionException e) {
172             return;
173         }
174         try {
175             h2 = new HostNodeConnector(ip2);
176         } catch (ConstructionException e) {
177             return;
178         }
179         HostNodePair hsw1 = new HostNodePair(h1, NodeCreator.createOFNode(1L));
180         HostNodePair hsw2 = new HostNodePair(h2, NodeCreator.createOFNode(1L));
181         Assert.assertTrue(hsw1.hashCode() == hsw2.hashCode());
182     }
183
184     @Test
185     public void TestEqualHashCode2() {
186         HostNodeConnector h1 = null;
187         HostNodeConnector h2 = null;
188         InetAddress ip1 = null;
189         try {
190             ip1 = InetAddress.getByName("10.0.0.2");
191         } catch (UnknownHostException e) {
192             return;
193         }
194         InetAddress ip2 = null;
195         try {
196             ip2 = InetAddress.getByName("10.0.0.2");
197         } catch (UnknownHostException e) {
198             return;
199         }
200         try {
201             h1 = new HostNodeConnector(ip1);
202         } catch (ConstructionException e) {
203             return;
204         }
205         try {
206             h2 = new HostNodeConnector(ip2);
207         } catch (ConstructionException e) {
208             return;
209         }
210
211         HostNodePair hsw1 = new HostNodePair(h1, NodeCreator.createOFNode(1L));
212         HostNodePair hsw2 = new HostNodePair(h2, NodeCreator.createOFNode(1L));
213         Assert.assertTrue(hsw1.hashCode() == hsw2.hashCode());
214     }
215
216     @Test
217     public void TestDiverseHashCodeHost() {
218         HostNodeConnector h1 = null;
219         HostNodeConnector h2 = null;
220         InetAddress ip1 = null;
221         try {
222             ip1 = InetAddress.getByName("10.0.0.1");
223         } catch (UnknownHostException e) {
224             return;
225         }
226         InetAddress ip2 = null;
227         try {
228             ip2 = InetAddress.getByName("10.0.0.2");
229         } catch (UnknownHostException e) {
230             return;
231         }
232         try {
233             h1 = new HostNodeConnector(ip1);
234         } catch (ConstructionException e) {
235             return;
236         }
237         try {
238             h2 = new HostNodeConnector(ip2);
239         } catch (ConstructionException e) {
240             return;
241         }
242         HostNodePair hsw1 = new HostNodePair(h1, NodeCreator.createOFNode(1L));
243         HostNodePair hsw2 = new HostNodePair(h2, NodeCreator.createOFNode(1L));
244         Assert.assertTrue(hsw1.hashCode() != hsw2.hashCode());
245     }
246
247     @Test
248     public void TestDiverseHashCodeSwitch() {
249         HostNodeConnector h1 = null;
250         HostNodeConnector h2 = null;
251         InetAddress ip1 = null;
252         try {
253             ip1 = InetAddress.getByName("10.0.0.1");
254         } catch (UnknownHostException e) {
255             return;
256         }
257         InetAddress ip2 = null;
258         try {
259             ip2 = InetAddress.getByName("10.0.0.1");
260         } catch (UnknownHostException e) {
261             return;
262         }
263         try {
264             h1 = new HostNodeConnector(ip1);
265         } catch (ConstructionException e) {
266             return;
267         }
268         try {
269             h2 = new HostNodeConnector(ip2);
270         } catch (ConstructionException e) {
271             return;
272         }
273
274         HostNodePair hsw1 = new HostNodePair(h1, NodeCreator.createOFNode(1L));
275         HostNodePair hsw2 = new HostNodePair(h2, NodeCreator.createOFNode(2L));
276         Assert.assertTrue(hsw1.hashCode() != hsw2.hashCode());
277     }
278
279     @Test
280     public void TestDiverseHashCodeAll() {
281         HostNodeConnector h1 = null;
282         HostNodeConnector h2 = null;
283         InetAddress ip1 = null;
284         try {
285             ip1 = InetAddress.getByName("10.0.0.1");
286         } catch (UnknownHostException e) {
287             return;
288         }
289         InetAddress ip2 = null;
290         try {
291             ip2 = InetAddress.getByName("10.0.0.3");
292         } catch (UnknownHostException e) {
293             return;
294         }
295         try {
296             h1 = new HostNodeConnector(ip1);
297         } catch (ConstructionException e) {
298             return;
299         }
300         try {
301             h2 = new HostNodeConnector(ip2);
302         } catch (ConstructionException e) {
303             return;
304         }
305
306         HostNodePair hsw1 = new HostNodePair(h1, NodeCreator.createOFNode(1L));
307         HostNodePair hsw2 = new HostNodePair(h2, NodeCreator.createOFNode(2L));
308         Assert.assertTrue(hsw1.hashCode() != hsw2.hashCode());
309     }
310
311     @Test
312     public void TestUsageAsKey() {
313         HostNodeConnector h1 = null;
314         HostNodeConnector h2 = null;
315         InetAddress ip1 = null;
316         try {
317             ip1 = InetAddress.getByName("10.0.0.1");
318         } catch (UnknownHostException e) {
319             return;
320         }
321         InetAddress ip2 = null;
322         try {
323             ip2 = InetAddress.getByName("10.0.0.1");
324         } catch (UnknownHostException e) {
325             return;
326         }
327         try {
328             h1 = new HostNodeConnector(ip1);
329         } catch (ConstructionException e) {
330             return;
331         }
332         try {
333             h2 = new HostNodeConnector(ip2);
334         } catch (ConstructionException e) {
335             return;
336         }
337
338         HostNodePair hsw1 = new HostNodePair(h1, NodeCreator.createOFNode(1L));
339         HostNodePair hsw2 = new HostNodePair(h2, NodeCreator.createOFNode(1L));
340         HashMap<HostNodePair, Long> hm = new HashMap<HostNodePair, Long>();
341         hm.put(hsw1, new Long(10));
342         Assert.assertTrue(hm.get(hsw2) != null);
343         Assert.assertTrue(hm.get(hsw2).equals(new Long(10)));
344     }
345
346     @Test
347     public void TestUsageAsKeyChangingField() {
348         HostNodeConnector h1 = null;
349         HostNodeConnector h2 = null;
350         InetAddress ip1 = null;
351         try {
352             ip1 = InetAddress.getByName("10.0.0.1");
353         } catch (UnknownHostException e) {
354             return;
355         }
356         InetAddress ip2 = null;
357         try {
358             ip2 = InetAddress.getByName("10.0.0.1");
359         } catch (UnknownHostException e) {
360             return;
361         }
362         try {
363             h1 = new HostNodeConnector(ip1);
364         } catch (ConstructionException e) {
365             return;
366         }
367         try {
368             h2 = new HostNodeConnector(ip2);
369         } catch (ConstructionException e) {
370             return;
371         }
372         HostNodePair hsw1 = new HostNodePair(h1, null);
373         HostNodePair hsw2 = new HostNodePair(h2, NodeCreator.createOFNode(1L));
374         hsw1.setNode(NodeCreator.createOFNode(1L));
375         HashMap<HostNodePair, Long> hm = new HashMap<HostNodePair, Long>();
376         hm.put(hsw1, new Long(10));
377         Assert.assertTrue(hm.get(hsw2) != null);
378         Assert.assertTrue(hm.get(hsw2).equals(new Long(10)));
379     }
380 }