Bug 5947: additional tests for mdsal project #10
[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.assertFalse;
13 import static org.junit.Assert.assertTrue;
14 import static org.junit.Assert.fail;
15
16 import java.util.Arrays;
17 import org.junit.Test;
18
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";
23
24     @Test
25     public void testBytesToMac() throws Exception {
26         final MacClass mac = UTIL.macAddressFor(BYTES);
27         assertEquals(CANON, mac.getValue());
28     }
29
30     @Test
31     public void testMacToBytes() throws Exception {
32         final byte[] bytes1 = UTIL.bytesFor(new MacClass(CANON));
33         assertTrue(Arrays.equals(BYTES, bytes1));
34
35         final byte[] bytes2 = UTIL.bytesFor(new MacClass("01:02:1E:5a:Fb:88"));
36         assertTrue(Arrays.equals(BYTES, bytes2));
37     }
38
39     @Test
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()));
43     }
44
45     @Test(expected = IllegalArgumentException.class)
46     public void hexValueWithExceptionTest() throws Exception {
47         AbstractIetfYangUtil.hexValue(Character.highSurrogate(1000));
48         fail("Expected invalid character exception");
49     }
50 }