Merge "Add copyright messages for java files"
[controller.git] / opendaylight / md-sal / compatibility / sal-compatibility / src / test / java / org / opendaylight / controller / sal / compatibility / test / NodeMappingTest.java
1 /**
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.sal.compatibility.test;
9
10 import org.junit.Assert;
11 import org.junit.Test;
12 import org.opendaylight.controller.sal.compatibility.NodeMapping;
13 import org.opendaylight.controller.sal.core.MacAddress;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
16
17 /**
18  * test of {@link NodeMapping} utility class
19  */
20 public class NodeMappingTest {
21
22     /**
23      * Test method for
24      * {@link org.opendaylight.controller.sal.compatibility.NodeMapping#toADMacAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId)}
25      * .
26      */
27     @Test
28     public void testToADMacAddress() {
29         NodeId[] nodeIds = new NodeId[] {
30                 // 0x0000|0000 0000002a (answer to the ultimate question of life, universe and everything)
31                 new NodeId("42"),
32                 // 0x7fff|ffff ffffffff (max long -> 2**63 - 1)
33                 new NodeId("9223372036854775807"),
34                 // 0x7fff|7fff ffffffff
35                 new NodeId("9223231299366420479"),
36                 // 0x8fff|7fff ffffffff (more than biggest positive long)
37                 new NodeId("10376152803973267455"),
38                 // 0xca13|764a e9ace65a (BUG-770)
39                 new NodeId("14561112084339025498")
40         };
41
42         byte[][] expectedMacs = new byte[][] {
43                 {0, 0, 0, 0, 0, 0x2a},
44                 {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff},
45                 {(byte) 0x7f, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff},
46                 {(byte) 0x7f, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff},
47                 {(byte) 0x76, (byte) 0x4a, (byte) 0xe9, (byte) 0xac, (byte) 0xe6, (byte) 0x5a}
48         };
49
50         Assert.assertEquals(expectedMacs.length, nodeIds.length);
51
52         for (int i = 0; i < expectedMacs.length; i++) {
53             NodeId nodeId = nodeIds[i];
54             MacAddress mac = NodeMapping.toADMacAddress(nodeId);
55             Assert.assertArrayEquals(expectedMacs[i], mac.getMacAddress());
56         }
57     }
58
59     /**
60      * Test method for
61      * {@link org.opendaylight.controller.sal.compatibility.NodeMapping#toAdNodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId)}
62      * .
63      */
64     @Test
65     public void testToAdNodeId() {
66         NodeId observed;
67         observed = NodeMapping.toAdNodeId(null);
68         Assert.assertNull(observed);
69
70         observed = NodeMapping.toAdNodeId(new NodeConnectorId("MD_SAL|openflow:5:2"));
71         Assert.assertEquals("MD_SAL|openflow:5", observed.getValue());
72     }
73
74 }