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
9 package org.opendaylight.mdsal.model.ietf.util;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
13 import static org.junit.Assert.fail;
15 import java.util.Arrays;
16 import org.junit.Test;
18 public class AbstractIetfYangUtilTest {
19 private static final MacUtil UTIL = new MacUtil();
20 private static final byte[] BYTES = new byte[] { 1, 2, 30, 90, -5, -120 };
21 private static final String CANON = "01:02:1e:5a:fb:88";
24 public void testBytesToMac() throws Exception {
25 final MacClass mac = UTIL.macAddressFor(BYTES);
26 assertEquals(CANON, mac.getValue());
30 public void testMacToBytes() throws Exception {
31 final byte[] bytes1 = UTIL.bytesFor(new MacClass(CANON));
32 assertTrue(Arrays.equals(BYTES, bytes1));
34 final byte[] bytes2 = UTIL.bytesFor(new MacClass("01:02:1E:5a:Fb:88"));
35 assertTrue(Arrays.equals(BYTES, bytes2));
39 public void canonizeMACTest() throws Exception {
40 assertEquals(CANON, UTIL.canonizeMacAddress(new MacClass("01:02:1E:5A:FB:88")).getValue());
43 @Test(expected = IllegalArgumentException.class)
44 public void hexValueWithExceptionTest() throws Exception {
45 AbstractIetfYangUtil.hexValue(Character.highSurrogate(1000));
46 fail("Expected invalid character exception");