Address FIXME for QueuedNotificationManager
[yangtools.git] / yang / yang-data-impl / src / test / java / org / opendaylight / yangtools / yang / data / impl / codecs / Int64CodecStringTest.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.yangtools.yang.data.impl.codecs;
10
11 import static org.junit.Assert.*;
12 import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx;
13 import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec;
14
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.data.api.codec.Int64Codec;
17 import org.opendaylight.yangtools.yang.model.util.Int64;
18
19 /**
20  * Unit tests for Int64CodecString.
21  *
22  * @author Thomas Pantelis
23  */
24 public class Int64CodecStringTest {
25
26     @SuppressWarnings("unchecked")
27     @Test
28     public void testSerialize() {
29         Int64Codec<String> codec = getCodec(Int64.getInstance(), Int64Codec.class);
30
31         assertEquals("serialize", "12345", codec.serialize(Long.valueOf( 12345 )));
32         assertEquals("serialize", "", codec.serialize(null));
33     }
34
35     @SuppressWarnings("unchecked")
36     @Test
37     public void testDeserialize() {
38         final String hexa = "0X75EDC78edCBA";
39         final String negHexa = "-0X75EDC78edCBA";
40         final String octal = "+03536670743556272";
41         final String negOctal = "-03536670743556272";
42         final String integer = "+129664115727546";
43         final String negInteger = "-129664115727546";
44
45         Int64Codec<String> codec = getCodec(Int64.getInstance(), Int64Codec.class);
46
47         assertEquals("deserialize", codec.deserialize(hexa), Long.valueOf("075EDC78edCBA", 16));
48         assertEquals("deserialize", codec.deserialize(negHexa), Long.valueOf("-075EDC78edCBA", 16));
49         assertEquals("deserialize", codec.deserialize(octal), Long.valueOf(octal, 8));
50         assertEquals("deserialize", codec.deserialize(negOctal), Long.valueOf(negOctal, 8));
51         assertEquals("deserialize", codec.deserialize(integer), Long.valueOf(integer, 10));
52         assertEquals("deserialize", codec.deserialize(negInteger), Long.valueOf(negInteger, 10));
53
54         deserializeWithExpectedIllegalArgEx(codec, "1234o");
55         deserializeWithExpectedIllegalArgEx(codec, "");
56         deserializeWithExpectedIllegalArgEx(codec, null);
57     }
58 }