2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.model.ietf.util;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.fail;
14 import org.junit.Test;
16 public class AbstractIetfYangUtilTest {
17 private static final MacUtil UTIL = new MacUtil();
18 private static final byte[] BYTES = new byte[] { 1, 2, 30, 90, -5, -120 };
19 private static final String CANON = "01:02:1e:5a:fb:88";
22 public void testBytesToMac() throws Exception {
23 final MacClass mac = UTIL.macAddressFor(BYTES);
24 assertEquals(CANON, mac.getValue());
28 public void testMacToBytes() throws Exception {
29 final byte[] bytes1 = UTIL.macAddressBytes(new MacClass(CANON));
30 assertArrayEquals(BYTES, bytes1);
32 final byte[] bytes2 = UTIL.macAddressBytes(new MacClass("01:02:1E:5a:Fb:88"));
33 assertArrayEquals(BYTES, bytes2);
37 public void testPhysToBytes() throws Exception {
38 final byte[] bytes1 = UTIL.physAddressBytes(new PhysClass(CANON));
39 assertArrayEquals(BYTES, bytes1);
41 final byte[] bytes2 = UTIL.physAddressBytes(new PhysClass("01:02:1E:5a:Fb:88"));
42 assertArrayEquals(BYTES, bytes2);
44 assertArrayEquals(new byte[0], UTIL.physAddressBytes(new PhysClass("")));
45 assertArrayEquals(new byte[] { (byte) 0xaa }, UTIL.physAddressBytes(new PhysClass("aa")));
46 assertArrayEquals(new byte[] { (byte) 0xaa, (byte) 0xbb }, UTIL.physAddressBytes(new PhysClass("aa:bb")));
50 public void canonizeMACTest() throws Exception {
51 assertEquals(CANON, UTIL.canonizeMacAddress(new MacClass("01:02:1E:5A:FB:88")).getValue());
54 @Test(expected = IllegalArgumentException.class)
55 public void hexValueWithExceptionTest() throws Exception {
56 AbstractIetfYangUtil.hexValue(Character.highSurrogate(1000));
57 fail("Expected invalid character exception");