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