Merge "BUG-2329 Add test for anyxmls inside rpc resonse for netcfon-connector"
[controller.git] / opendaylight / adsal / sal / api / src / test / java / org / opendaylight / controller / sal / utils / HexEncodeTest.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.sal.utils;
11
12 import org.junit.Assert;
13 import org.junit.Test;
14
15 public class HexEncodeTest {
16
17         @Test
18         public void testbytesToHexString() {
19                 byte[] bytes1 = {(byte)0x01, (byte)0x02, (byte)0x03};
20                 String str1 = HexEncode.bytesToHexString(bytes1);
21                 Assert.assertTrue(str1.equals("010203"));
22
23                 byte[] bytes2 = {(byte)0x11, (byte)0x22, (byte)0x33};
24                 String str2 = HexEncode.bytesToHexString(bytes2);
25                 Assert.assertFalse(str2.equals("010203"));
26
27         }
28
29         @Test
30         public void testLongToHexString() {
31                 long value1 = 12345678L;
32                 String str1 = HexEncode.longToHexString(value1);
33                 Assert.assertTrue(str1.equals("00:00:00:00:00:bc:61:4e"));
34
35                 long value2 = 98765432L;
36                 String str2 = HexEncode.longToHexString(value2);
37                 Assert.assertFalse(str2.equals("00:44:33:22:11:bc:61:4e"));
38
39         }
40
41         @Test
42         public void testBytesFromHexString() {
43                 String byteStr1 = "00:11:22:33:44:55";
44                 byte byteArray1[] = new byte[(byteStr1.length() + 1)/3];
45                 byteArray1 = HexEncode.bytesFromHexString(byteStr1);
46
47                 Assert.assertTrue(byteArray1[0] == (byte)0x0);
48                 Assert.assertTrue(byteArray1[1] == (byte)0x11);
49                 Assert.assertTrue(byteArray1[2] == (byte)0x22);
50                 Assert.assertTrue(byteArray1[3] == (byte)0x33);
51                 Assert.assertTrue(byteArray1[4] == (byte)0x44);
52                 Assert.assertTrue(byteArray1[5] == (byte)0x55);
53
54                 String byteStr2 = "00:11:22:33:44:55";
55                 byte byteArray2[] = new byte[(byteStr2.length() + 1)/3];
56                 byteArray2 = HexEncode.bytesFromHexString(byteStr2);
57
58                 Assert.assertFalse(byteArray2[0] == (byte)0x55);
59                 Assert.assertFalse(byteArray2[1] == (byte)0x44);
60                 Assert.assertFalse(byteArray2[2] == (byte)0x33);
61                 Assert.assertFalse(byteArray2[3] == (byte)0x22);
62                 Assert.assertFalse(byteArray2[4] == (byte)0x11);
63                 Assert.assertFalse(byteArray2[5] == (byte)0x0);
64
65         }
66
67 }