Merge branch 'master' of ../controller
[yangtools.git] / yang / yang-data-impl / src / test / java / org / opendaylight / yangtools / yang / data / impl / codecs / Uint32CodecStringTest.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 package org.opendaylight.yangtools.yang.data.impl.codecs;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx;
12 import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec;
13
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.common.Uint32;
16 import org.opendaylight.yangtools.yang.data.api.codec.Uint32Codec;
17 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
18
19 /**
20  * Unit tests for Uint32CodecString.
21  *
22  * @author Thomas Pantelis
23  */
24 public class Uint32CodecStringTest {
25     @SuppressWarnings("unchecked")
26     @Test
27     public void testSerialize() {
28         Uint32Codec<String> codec = getCodec(BaseTypes.uint32Type(), Uint32Codec.class);
29         assertEquals("10", codec.serialize(Uint32.valueOf(10)));
30     }
31
32     @SuppressWarnings("unchecked")
33     @Test
34     public void testDeserialize() {
35         final String hexa = "0x45FFFCDE";
36         final String octal = "010577776336";
37         final String integer = "1174404318";
38
39         Uint32Codec<String> codec = getCodec(BaseTypes.uint32Type(), Uint32Codec.class);
40         assertEquals(Uint32.valueOf("45FFFCDE", 16), codec.deserialize(hexa));
41         assertEquals(Uint32.valueOf(octal, 8), codec.deserialize(octal));
42         assertEquals(Uint32.valueOf(integer, 10), codec.deserialize(integer));
43
44         deserializeWithExpectedIllegalArgEx(codec, "1o");
45         deserializeWithExpectedIllegalArgEx(codec, "");
46     }
47 }