Move AbstractIetfYangUtil
[mdsal.git] / model / ietf / rfc6991-ietf-yang-types / src / test / java / org / opendaylight / yang / gen / v1 / urn / ietf / params / xml / ns / yang / ietf / yang / types / rev130715 / IetfYangUtilTest.java
1 /*
2  * Copyright (c) 2019 PANTHEON.tech, s.r.o. 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 package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715;
9
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12 import static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.IetfYangUtil.INSTANCE;
13
14 import java.util.UUID;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.junit.Test;
17
18 public class IetfYangUtilTest {
19     private static final byte @NonNull [] BYTES = new byte[] { 1, 2, 30, 90, -5, -120 };
20     private static final String CANON = "01:02:1e:5a:fb:88";
21
22     @Test
23     public void testBytesToMac() {
24         final var mac = INSTANCE.macAddressFor(BYTES);
25         assertEquals(CANON, mac.getValue());
26     }
27
28     @Test
29     public void testMacToBytes() {
30         final byte[] bytes1 = INSTANCE.macAddressBytes(new MacAddress(CANON));
31         assertArrayEquals(BYTES, bytes1);
32
33         final byte[] bytes2 = INSTANCE.macAddressBytes(new MacAddress("01:02:1E:5a:Fb:88"));
34         assertArrayEquals(BYTES, bytes2);
35     }
36
37     @Test
38     public void testBytesToHex() {
39         final HexString hex = INSTANCE.hexStringFor(BYTES);
40         assertEquals(CANON, hex.getValue());
41     }
42
43     @Test
44     public void testHexToBytes() {
45         final byte[] bytes1 = INSTANCE.hexStringBytes(new HexString(CANON));
46         assertArrayEquals(BYTES, bytes1);
47
48         final byte[] bytes2 = INSTANCE.hexStringBytes(new HexString("01:02:1E:5a:Fb:88"));
49         assertArrayEquals(BYTES, bytes2);
50     }
51
52     @Test
53     public void testPhysToBytes() {
54         final byte[] bytes1 = INSTANCE.physAddressBytes(new PhysAddress(CANON));
55         assertArrayEquals(BYTES, bytes1);
56
57         final byte[] bytes2 = INSTANCE.physAddressBytes(new PhysAddress("01:02:1E:5a:Fb:88"));
58         assertArrayEquals(BYTES, bytes2);
59
60         assertArrayEquals(new byte[0], INSTANCE.physAddressBytes(new PhysAddress("")));
61         assertArrayEquals(new byte[] { (byte) 0xaa }, INSTANCE.physAddressBytes(new PhysAddress("aa")));
62         assertArrayEquals(new byte[] { (byte) 0xaa, (byte) 0xbb }, INSTANCE.physAddressBytes(new PhysAddress("aa:bb")));
63     }
64
65     @Test
66     public void testQuadBits() {
67         assertEquals(0x01020304, INSTANCE.dottedQuadBits(new DottedQuad("1.2.3.4")));
68         assertEquals(0xFFFFFFFF, INSTANCE.dottedQuadBits(new DottedQuad("255.255.255.255")));
69     }
70
71     @Test
72     public void testQuadBytes() {
73         assertArrayEquals(new byte[] { 1, 2, 3, 4 }, INSTANCE.dottedQuadBytes(new DottedQuad("1.2.3.4")));
74     }
75
76     @Test
77     public void testQuadForBits() {
78         assertEquals("1.2.3.4", INSTANCE.dottedQuadFor(0x01020304).getValue());
79         assertEquals("255.255.255.255", INSTANCE.dottedQuadFor(0xFFFFFFFF).getValue());
80     }
81
82     @Test
83     public void testQuadForBytes() {
84         assertEquals("1.2.3.4", INSTANCE.dottedQuadFor(new byte[] { 1, 2, 3, 4 }).getValue());
85     }
86
87     @Test
88     public void testUuidFor() {
89         final UUID uuid = UUID.fromString("f81d4fae-7dec-11d0-a765-00a0c91e6bf6");
90         assertEquals("f81d4fae-7dec-11d0-a765-00a0c91e6bf6", INSTANCE.uuidFor(uuid).getValue());
91     }
92
93     @Test
94     public void canonizeMACTest() {
95         assertEquals(CANON, INSTANCE.canonizeMacAddress(new MacAddress("01:02:1E:5A:FB:88")).getValue());
96     }
97
98     @Test
99     public void testDottedQuad() {
100         assertArrayEquals(new byte[] { 1, 2, 3, 4 }, INSTANCE.dottedQuadBytes(new DottedQuad("1.2.3.4")));
101         assertEquals(new DottedQuad("1.2.3.4"), INSTANCE.dottedQuadFor(new byte[] { 1, 2, 3, 4 }));
102     }
103
104     @Test
105     public void testHexString() {
106         assertArrayEquals(new byte[] { 0, 1 }, INSTANCE.hexStringBytes(new HexString("00:01")));
107         assertEquals(new HexString("00:01"), INSTANCE.hexStringFor(new byte[] { 0, 1 }));
108     }
109
110     @Test
111     public void testPhysAddress() {
112         assertArrayEquals(new byte[] { 0, 1} , INSTANCE.physAddressBytes(new PhysAddress("00:01")));
113         assertEquals(new PhysAddress("00:01"), INSTANCE.physAddressFor(new byte[] { 0, 1 }));
114     }
115
116     @Test
117     public void testMacAddress() {
118         assertArrayEquals(new byte[] { 0, 1, 2, 3, 4, 5 },
119             INSTANCE.macAddressBytes(new MacAddress("00:01:02:03:04:05")));
120         assertEquals(new MacAddress("00:01:02:03:04:05"), INSTANCE.macAddressFor(new byte[] { 0, 1, 2, 3, 4, 5 }));
121     }
122
123     @Test
124     public void testUuid() {
125         final UUID java = UUID.randomUUID();
126         assertEquals(new Uuid(java.toString()), INSTANCE.uuidFor(java));
127     }
128 }