Merge "Fixed getPath in SchemaContextImpl."
[yangtools.git] / yang / yang-model-util / src / test / java / org / opendaylight / yangtools / yang / model / util / Decimal64Test.java
1 /*
2  * Copyright (c) 2013 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.model.util;
9
10 import org.junit.Test;
11 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
12 import org.opendaylight.yangtools.yang.model.api.Status;
13
14 import java.util.Collections;
15
16 import static org.junit.Assert.assertEquals;
17 import static org.junit.Assert.assertNotEquals;
18 import static org.junit.Assert.assertTrue;
19 import static org.junit.Assert.assertFalse;
20
21 public class Decimal64Test {
22
23     @Test
24     public void canCreateDecimal64() {
25         Integer fractionDig = 2;
26         Decimal64 decimal64 = Decimal64.create(SchemaPath.ROOT, fractionDig);
27
28         assertEquals("Status should be CURRENT", Status.CURRENT, decimal64.getStatus());
29
30         assertEquals("Default value should be null", null, decimal64.getDefaultValue());
31
32         assertEquals("Should be empty list", Collections.EMPTY_LIST, decimal64.getUnknownSchemaNodes());
33
34         assertEquals("Should be null", null, decimal64.getBaseType());
35
36         assertNotEquals("Description is not null", null, decimal64.getDescription());
37
38         assertNotEquals("Reference is not null", null, decimal64.getReference());
39
40         assertEquals("Should be empty string", "", decimal64.getUnits());
41
42         assertTrue("Should contain factionDigits=2", decimal64.toString().contains("fractionDigits="+fractionDig));
43
44         assertEquals("Should get farctionDig", fractionDig, decimal64.getFractionDigits());
45
46         assertEquals("Should be empty list",
47                 Collections.EMPTY_LIST, decimal64.getPath().getPathFromRoot());
48
49         assertEquals("Should be DECIMAL64_QNAME", BaseTypes.DECIMAL64_QNAME, decimal64.getQName());
50
51         assertTrue("Should contain max", decimal64.getRangeConstraints().toString().contains("max=922337203685477580.7"));
52         assertTrue("Should contain min", decimal64.getRangeConstraints().toString().contains("min=-922337203685477580.8"));
53
54         Decimal64 decimal641 = decimal64;
55         assertTrue("Hash code of decimal64 and decimal641 should be equal",
56                     decimal64.hashCode() == decimal641.hashCode());
57
58         assertFalse("Decimal64 shouldn't equal to null", decimal64.equals(null));
59         assertEquals("Decimal64 should equals to itself", decimal64, decimal64);
60         assertFalse("Decimal64 shouldn't equal to object of other type", decimal64.equals("str"));
61     }
62 }