Merge "Optimizations, Monitoring and Logging"
[controller.git] / opendaylight / commons / liblldp / src / test / java / org / opendaylight / controller / sal / packet / address / EthernetAddressTest.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   EthernetAddressTest.java
12  *
13  * @brief  Unit Tests for EthernetAddress class
14  *
15  * Unit Tests for EthernetAddress class
16  */
17 package org.opendaylight.controller.sal.packet.address;
18
19 import org.junit.Assert;
20 import org.junit.Test;
21 import org.opendaylight.controller.liblldp.ConstructionException;
22 import org.opendaylight.controller.liblldp.EthernetAddress;
23
24 public class EthernetAddressTest {
25     @Test
26     public void testNonValidConstructor() {
27         @SuppressWarnings("unused")
28         EthernetAddress ea1;
29         // Null input array
30         try {
31             ea1 = new EthernetAddress((byte[]) null);
32
33             // Exception is expected if NOT raised test will fail
34             Assert.assertTrue(false);
35         } catch (ConstructionException e) {
36         }
37
38         // Array too short
39         try {
40             ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0 });
41
42             // Exception is expected if NOT raised test will fail
43             Assert.assertTrue(false);
44         } catch (ConstructionException e) {
45         }
46
47         // Array too long
48         try {
49             ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
50                     (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0,
51                     (byte) 0x0 });
52
53             // Exception is expected if NOT raised test will fail
54             Assert.assertTrue(false);
55         } catch (ConstructionException e) {
56         }
57     }
58
59     @Test
60     public void testEquality() {
61         EthernetAddress ea1;
62         EthernetAddress ea2;
63         try {
64             ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
65                     (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 });
66
67             ea2 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
68                     (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 });
69             Assert.assertTrue(ea1.equals(ea2));
70         } catch (ConstructionException e) {
71             // Exception is NOT expected if raised test will fail
72             Assert.assertTrue(false);
73         }
74
75         try {
76             ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
77                     (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 });
78
79             ea2 = ea1.clone();
80             Assert.assertTrue(ea1.equals(ea2));
81         } catch (ConstructionException e) {
82             // Exception is NOT expected if raised test will fail
83             Assert.assertTrue(false);
84         }
85
86         // Check for well knowns
87         try {
88             ea1 = EthernetAddress.BROADCASTMAC;
89             ea2 = new EthernetAddress(new byte[] { (byte) 0xff, (byte) 0xff,
90                     (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff });
91             Assert.assertTrue(ea1.equals(ea2));
92         } catch (ConstructionException e) {
93             // Exception is NOT expected if raised test will fail
94             Assert.assertTrue(false);
95         }
96     }
97
98     @Test
99     public void testUnEquality() {
100         EthernetAddress ea1;
101         EthernetAddress ea2;
102         try {
103             ea1 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
104                     (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x2 });
105
106             ea2 = new EthernetAddress(new byte[] { (byte) 0x0, (byte) 0x0,
107                     (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1 });
108             Assert.assertTrue(!ea1.equals(ea2));
109         } catch (ConstructionException e) {
110             // Exception is NOT expected if raised test will fail
111             Assert.assertTrue(false);
112         }
113     }
114 }