Fix checkstyle in yang-parser-impl and enable enforcement
[yangtools.git] / yang / yang-parser-impl / 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.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
14
15 import java.net.URI;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.common.QNameModule;
19 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
22 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
24 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
25 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
26 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
27
28 public class YangTypes2StmtTest {
29
30     private static final StatementStreamSource TYPEFILE1 = sourceForResource("/semantic-statement-parser/types2.yang");
31     private static final StatementStreamSource TYPEFILE2 = sourceForResource("/semantic-statement-parser/types.yang");
32     private static final StatementStreamSource TYPEFILE3 = sourceForResource(
33             "/semantic-statement-parser/simple-types.yang");
34     private static final StatementStreamSource TYPEFILE4 = sourceForResource(
35             "/semantic-statement-parser/identityreftest.yang");
36
37     private static final QNameModule TYPES2_MODULE = QNameModule.create(URI.create("types2"));
38
39     private static final QName LF_DECIMAL = QName.create(TYPES2_MODULE, "lf-decimal");
40     private static final QName LF_MY_STRING = QName.create(TYPES2_MODULE, "lf-my-string");
41     private static final QName LF_INT8 = QName.create(TYPES2_MODULE, "lf-int8");
42     private static final QName LF_INT16 = QName.create(TYPES2_MODULE, "lf-int16");
43     private static final QName LF_INT32 = QName.create(TYPES2_MODULE, "lf-int32");
44     private static final QName LF_INT64 = QName.create(TYPES2_MODULE, "lf-int64");
45     private static final QName LF_UINT8 = QName.create(TYPES2_MODULE, "lf-uint8");
46     private static final QName LF_UINT16 = QName.create(TYPES2_MODULE, "lf-uint16");
47     private static final QName LF_UINT32 = QName.create(TYPES2_MODULE, "lf-uint32");
48     private static final QName LF_UINT64 = QName.create(TYPES2_MODULE, "lf-uint64");
49     private static final QName LF_BOOL = QName.create(TYPES2_MODULE, "lf-bool");
50
51     @Test
52     public void readAndParseYangFileTest() throws ReactorException {
53         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
54         reactor.addSources(TYPEFILE1, TYPEFILE2, TYPEFILE3, TYPEFILE4);
55         SchemaContext result = reactor.buildEffective();
56         assertNotNull(result);
57
58         final LeafSchemaNode lfDecimalNode = (LeafSchemaNode) result.getDataChildByName(LF_DECIMAL);
59         assertNotNull(lfDecimalNode);
60
61         assertTrue(lfDecimalNode.getType() instanceof DecimalTypeDefinition);
62         final DecimalTypeDefinition lfDecimalNodeType = (DecimalTypeDefinition) lfDecimalNode.getType();
63         assertEquals(2, lfDecimalNodeType.getFractionDigits().intValue());
64
65         final LeafSchemaNode lfInt8Node = (LeafSchemaNode) result.getDataChildByName(LF_INT8);
66         assertNotNull(lfInt8Node);
67         assertEquals(BaseTypes.int8Type().getClass(), lfInt8Node.getType().getClass());
68
69         final LeafSchemaNode lfInt16Node = (LeafSchemaNode) result.getDataChildByName(LF_INT16);
70         assertNotNull(lfInt16Node);
71         assertEquals(BaseTypes.int16Type().getClass(), lfInt16Node.getType().getClass());
72
73         final LeafSchemaNode lfInt32Node = (LeafSchemaNode) result.getDataChildByName(LF_INT32);
74         assertNotNull(lfInt32Node);
75         assertEquals(BaseTypes.int32Type().getClass(), lfInt32Node.getType().getClass());
76
77         final LeafSchemaNode lfInt64Node = (LeafSchemaNode) result.getDataChildByName(LF_INT64);
78         assertNotNull(lfInt64Node);
79         assertEquals(BaseTypes.int64Type().getClass(), lfInt64Node.getType().getClass());
80
81         final LeafSchemaNode lfUInt8Node = (LeafSchemaNode) result.getDataChildByName(LF_UINT8);
82         assertNotNull(lfUInt8Node);
83         assertEquals(BaseTypes.uint8Type().getClass(), lfUInt8Node.getType().getClass());
84
85         final LeafSchemaNode lfUInt16Node = (LeafSchemaNode) result.getDataChildByName(LF_UINT16);
86         assertNotNull(lfUInt16Node);
87         assertEquals(BaseTypes.uint16Type().getClass(), lfUInt16Node.getType().getClass());
88
89         final LeafSchemaNode lfUInt32Node = (LeafSchemaNode) result.getDataChildByName(LF_UINT32);
90         assertNotNull(lfUInt32Node);
91         assertEquals(BaseTypes.uint32Type().getClass(), lfUInt32Node.getType().getClass());
92
93         final LeafSchemaNode lfUInt64Node = (LeafSchemaNode) result.getDataChildByName(LF_UINT64);
94         assertNotNull(lfUInt64Node);
95         assertEquals(BaseTypes.uint64Type().getClass(), lfUInt64Node.getType().getClass());
96
97         final LeafSchemaNode lfBoolNode = (LeafSchemaNode) result.getDataChildByName(LF_BOOL);
98         assertNotNull(lfBoolNode);
99         assertEquals(BaseTypes.booleanType().getClass(), lfBoolNode.getType().getClass());
100     }
101 }