Deprecate simple DataTreeFactory.create()
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / YangTypes2StmtTest.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.stmt;
9
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
12 import static org.junit.jupiter.api.Assertions.assertNotNull;
13
14 import org.junit.jupiter.api.Test;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.common.QNameModule;
17 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
19 import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes;
20
21 class YangTypes2StmtTest extends AbstractYangTest {
22     private static final QNameModule TYPES2_MODULE = QNameModule.of("types2");
23
24     private static final QName LF_DECIMAL = QName.create(TYPES2_MODULE, "lf-decimal");
25     private static final QName LF_MY_STRING = QName.create(TYPES2_MODULE, "lf-my-string");
26     private static final QName LF_INT8 = QName.create(TYPES2_MODULE, "lf-int8");
27     private static final QName LF_INT16 = QName.create(TYPES2_MODULE, "lf-int16");
28     private static final QName LF_INT32 = QName.create(TYPES2_MODULE, "lf-int32");
29     private static final QName LF_INT64 = QName.create(TYPES2_MODULE, "lf-int64");
30     private static final QName LF_UINT8 = QName.create(TYPES2_MODULE, "lf-uint8");
31     private static final QName LF_UINT16 = QName.create(TYPES2_MODULE, "lf-uint16");
32     private static final QName LF_UINT32 = QName.create(TYPES2_MODULE, "lf-uint32");
33     private static final QName LF_UINT64 = QName.create(TYPES2_MODULE, "lf-uint64");
34     private static final QName LF_BOOL = QName.create(TYPES2_MODULE, "lf-bool");
35
36     @Test
37     void readAndParseYangFileTest() {
38         final var result = assertEffectiveModel(
39             "/semantic-statement-parser/types2.yang", "/semantic-statement-parser/types.yang",
40             "/semantic-statement-parser/simple-types.yang", "/semantic-statement-parser/identityreftest.yang");
41
42         final LeafSchemaNode lfDecimalNode = (LeafSchemaNode) result.getDataChildByName(LF_DECIMAL);
43         assertNotNull(lfDecimalNode);
44
45         final DecimalTypeDefinition lfDecimalNodeType =
46             assertInstanceOf(DecimalTypeDefinition.class, lfDecimalNode.getType());
47         assertEquals(2, lfDecimalNodeType.getFractionDigits());
48
49         final LeafSchemaNode lfInt8Node = (LeafSchemaNode) result.getDataChildByName(LF_INT8);
50         assertNotNull(lfInt8Node);
51         assertEquals(BaseTypes.int8Type().getClass(), lfInt8Node.getType().getClass());
52
53         final LeafSchemaNode lfInt16Node = (LeafSchemaNode) result.getDataChildByName(LF_INT16);
54         assertNotNull(lfInt16Node);
55         assertEquals(BaseTypes.int16Type().getClass(), lfInt16Node.getType().getClass());
56
57         final LeafSchemaNode lfInt32Node = (LeafSchemaNode) result.getDataChildByName(LF_INT32);
58         assertNotNull(lfInt32Node);
59         assertEquals(BaseTypes.int32Type().getClass(), lfInt32Node.getType().getClass());
60
61         final LeafSchemaNode lfInt64Node = (LeafSchemaNode) result.getDataChildByName(LF_INT64);
62         assertNotNull(lfInt64Node);
63         assertEquals(BaseTypes.int64Type().getClass(), lfInt64Node.getType().getClass());
64
65         final LeafSchemaNode lfUInt8Node = (LeafSchemaNode) result.getDataChildByName(LF_UINT8);
66         assertNotNull(lfUInt8Node);
67         assertEquals(BaseTypes.uint8Type().getClass(), lfUInt8Node.getType().getClass());
68
69         final LeafSchemaNode lfUInt16Node = (LeafSchemaNode) result.getDataChildByName(LF_UINT16);
70         assertNotNull(lfUInt16Node);
71         assertEquals(BaseTypes.uint16Type().getClass(), lfUInt16Node.getType().getClass());
72
73         final LeafSchemaNode lfUInt32Node = (LeafSchemaNode) result.getDataChildByName(LF_UINT32);
74         assertNotNull(lfUInt32Node);
75         assertEquals(BaseTypes.uint32Type().getClass(), lfUInt32Node.getType().getClass());
76
77         final LeafSchemaNode lfUInt64Node = (LeafSchemaNode) result.getDataChildByName(LF_UINT64);
78         assertNotNull(lfUInt64Node);
79         assertEquals(BaseTypes.uint64Type().getClass(), lfUInt64Node.getType().getClass());
80
81         final LeafSchemaNode lfBoolNode = (LeafSchemaNode) result.getDataChildByName(LF_BOOL);
82         assertNotNull(lfBoolNode);
83         assertEquals(BaseTypes.booleanType().getClass(), lfBoolNode.getType().getClass());
84     }
85 }