Merge branch 'blueprint' from controller
[mdsal.git] / model / ietf / ietf-type-util / src / test / java / org / opendaylight / mdsal / model / ietf / util / AbstractIetfYangUtilTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.mdsal.model.ietf.util;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
13 import static org.junit.Assert.fail;
14
15 import java.util.Arrays;
16 import org.junit.Test;
17
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";
22
23     @Test
24     public void testBytesToMac() throws Exception {
25         final MacClass mac = UTIL.macAddressFor(BYTES);
26         assertEquals(CANON, mac.getValue());
27     }
28
29     @Test
30     public void testMacToBytes() throws Exception {
31         final byte[] bytes1 = UTIL.bytesFor(new MacClass(CANON));
32         assertTrue(Arrays.equals(BYTES, bytes1));
33
34         final byte[] bytes2 = UTIL.bytesFor(new MacClass("01:02:1E:5a:Fb:88"));
35         assertTrue(Arrays.equals(BYTES, bytes2));
36     }
37
38     @Test
39     public void canonizeMACTest() throws Exception {
40         assertEquals(CANON, UTIL.canonizeMacAddress(new MacClass("01:02:1E:5A:FB:88")).getValue());
41     }
42
43     @Test(expected = IllegalArgumentException.class)
44     public void hexValueWithExceptionTest() throws Exception {
45         AbstractIetfYangUtil.hexValue(Character.highSurrogate(1000));
46         fail("Expected invalid character exception");
47     }
48 }