Add HexString/DottedQuad/Uuid support to IetfYangUtil
[mdsal.git] / model / ietf / ietf-type-util / src / test / java / org / opendaylight / mdsal / model / ietf / util / AbstractIetfYangUtilTest.java
index 7b3780aab588a31c495cce370e9a7fa4ceab2524..2b44c9d040422f246acf10ecb68af4d6878f5631 100644 (file)
@@ -5,14 +5,13 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.mdsal.model.ietf.util;
 
+import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
-import java.util.Arrays;
+import java.util.UUID;
 import org.junit.Test;
 
 public class AbstractIetfYangUtilTest {
@@ -21,23 +20,72 @@ public class AbstractIetfYangUtilTest {
     private static final String CANON = "01:02:1e:5a:fb:88";
 
     @Test
-    public void testBytesToMac() {
+    public void testBytesToMac() throws Exception {
         final MacClass mac = UTIL.macAddressFor(BYTES);
-        assertEquals(CANON, mac._value);
+        assertEquals(CANON, mac.getValue());
+    }
+
+    @Test
+    public void testMacToBytes() throws Exception {
+        final byte[] bytes1 = UTIL.macAddressBytes(new MacClass(CANON));
+        assertArrayEquals(BYTES, bytes1);
+
+        final byte[] bytes2 = UTIL.macAddressBytes(new MacClass("01:02:1E:5a:Fb:88"));
+        assertArrayEquals(BYTES, bytes2);
+    }
+
+    @Test
+    public void testBytesToHex() {
+        final HexClass hex = UTIL.hexStringFor(BYTES);
+        assertEquals(CANON, hex.getValue());
+    }
+
+    @Test
+    public void testHexToBytes() {
+        final byte[] bytes1 = UTIL.hexStringBytes(new HexClass(CANON));
+        assertArrayEquals(BYTES, bytes1);
+
+        final byte[] bytes2 = UTIL.hexStringBytes(new HexClass("01:02:1E:5a:Fb:88"));
+        assertArrayEquals(BYTES, bytes2);
     }
 
     @Test
-    public void testMacToBytes() {
-        final byte[] bytes1 = UTIL.bytesFor(new MacClass(CANON));
-        assertTrue(Arrays.equals(BYTES, bytes1));
+    public void testPhysToBytes() {
+        final byte[] bytes1 = UTIL.physAddressBytes(new PhysClass(CANON));
+        assertArrayEquals(BYTES, bytes1);
 
-        final byte[] bytes2 = UTIL.bytesFor(new MacClass("01:02:1E:5a:Fb:88"));
-        assertTrue(Arrays.equals(BYTES, bytes2));
+        final byte[] bytes2 = UTIL.physAddressBytes(new PhysClass("01:02:1E:5a:Fb:88"));
+        assertArrayEquals(BYTES, bytes2);
+
+        assertArrayEquals(new byte[0], UTIL.physAddressBytes(new PhysClass("")));
+        assertArrayEquals(new byte[] { (byte) 0xaa }, UTIL.physAddressBytes(new PhysClass("aa")));
+        assertArrayEquals(new byte[] { (byte) 0xaa, (byte) 0xbb }, UTIL.physAddressBytes(new PhysClass("aa:bb")));
+    }
+
+    @Test
+    public void testQuadBytes() {
+        assertArrayEquals(new byte[] { 1, 2, 3, 4 }, UTIL.dottedQuadBytes(new QuadClass("1.2.3.4")));
+    }
+
+    @Test
+    public void testQuadFor() {
+        assertEquals("1.2.3.4", UTIL.dottedQuadFor(new byte[] { 1, 2, 3, 4 }).getValue());
+    }
+
+    @Test
+    public void testUuidFor() {
+        final UUID uuid = UUID.fromString("f81d4fae-7dec-11d0-a765-00a0c91e6bf6");
+        assertEquals("f81d4fae-7dec-11d0-a765-00a0c91e6bf6", UTIL.uuidFor(uuid).getValue());
     }
 
     @Test
     public void canonizeMACTest() throws Exception {
-        assertFalse(UTIL.canonizeMacAddress(new MacClass("01:02:1E:5A:FB:88"))._value
-                .equals(UTIL.canonizeMacAddress(new MacClass(CANON))._value));
+        assertEquals(CANON, UTIL.canonizeMacAddress(new MacClass("01:02:1E:5A:FB:88")).getValue());
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void hexValueWithExceptionTest() throws Exception {
+        AbstractIetfYangUtil.hexValue(Character.highSurrogate(1000));
+        fail("Expected invalid character exception");
     }
 }