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.codec;
10 import static org.junit.Assert.assertEquals;
12 import org.junit.Test;
13 import org.opendaylight.yangtools.yang.common.Uint64;
14 import org.opendaylight.yangtools.yang.data.api.codec.Uint64Codec;
15 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
18 * Unit tests for Uint64CodecString.
20 * @author Thomas Pantelis
22 public class Uint64CodecStringTest {
23 @SuppressWarnings("unchecked")
25 public void testSerialize() {
26 Uint64Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.uint64Type(),
28 assertEquals("123456789", codec.serialize(Uint64.valueOf(123456789)));
31 @SuppressWarnings("unchecked")
33 public void testDeserialize() {
34 final String hexa = "0X75EDC78edCBA";
35 final String octal = "03536670743556272";
36 final String integer = "129664115727546";
38 Uint64Codec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.uint64Type(),
41 assertEquals(Uint64.valueOf("75EDC78edCBA", 16), codec.deserialize(hexa));
42 assertEquals(Uint64.valueOf(octal, 8), codec.deserialize(octal));
43 assertEquals(Uint64.valueOf(integer, 10), codec.deserialize(integer));
45 TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "12345o");
46 TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "");