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
8 package org.opendaylight.yangtools.yang.data.impl.codecs;
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;
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;
20 * Unit tests for Uint32CodecString.
22 * @author Thomas Pantelis
24 public class Uint32CodecStringTest {
25 @SuppressWarnings("unchecked")
27 public void testSerialize() {
28 Uint32Codec<String> codec = getCodec(BaseTypes.uint32Type(), Uint32Codec.class);
29 assertEquals("10", codec.serialize(Uint32.valueOf(10)));
32 @SuppressWarnings("unchecked")
34 public void testDeserialize() {
35 final String hexa = "0x45FFFCDE";
36 final String octal = "010577776336";
37 final String integer = "1174404318";
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));
44 deserializeWithExpectedIllegalArgEx(codec, "1o");
45 deserializeWithExpectedIllegalArgEx(codec, "");