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.assertFalse;
13 import static org.junit.Assert.assertTrue;
14 import static org.junit.Assert.fail;
16 import java.util.Arrays;
17 import org.junit.Test;
19 public class AbstractIetfYangUtilTest {
20 private static final MacUtil UTIL = new MacUtil();
21 private static final byte[] BYTES = new byte[] { 1, 2, 30, 90, -5, -120 };
22 private static final String CANON = "01:02:1e:5a:fb:88";
25 public void testBytesToMac() throws Exception {
26 final MacClass mac = UTIL.macAddressFor(BYTES);
27 assertEquals(CANON, mac.getValue());
31 public void testMacToBytes() throws Exception {
32 final byte[] bytes1 = UTIL.bytesFor(new MacClass(CANON));
33 assertTrue(Arrays.equals(BYTES, bytes1));
35 final byte[] bytes2 = UTIL.bytesFor(new MacClass("01:02:1E:5a:Fb:88"));
36 assertTrue(Arrays.equals(BYTES, bytes2));
40 public void canonizeMACTest() throws Exception {
41 assertFalse(UTIL.canonizeMacAddress(new MacClass("01:02:1E:5A:FB:88")).getValue()
42 .equals(UTIL.canonizeMacAddress(new MacClass(CANON)).getValue()));
45 @Test(expected = IllegalArgumentException.class)
46 public void hexValueWithExceptionTest() throws Exception {
47 AbstractIetfYangUtil.hexValue(Character.highSurrogate(1000));
48 fail("Expected invalid character exception");