Fix warnings in EffectiveSchemaContextTest
[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.common.SimpleDateFormatUtil;
20 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
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.SourceException;
25 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
26 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
27 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
28 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
29
30 public class YangTypes2StmtTest {
31
32     private static final StatementStreamSource TYPEFILE1 = sourceForResource("/semantic-statement-parser/types2.yang");
33     private static final StatementStreamSource TYPEFILE2 = sourceForResource("/semantic-statement-parser/types.yang");
34     private static final StatementStreamSource TYPEFILE3 = sourceForResource(
35             "/semantic-statement-parser/simple-types.yang");
36     private static final StatementStreamSource TYPEFILE4 = sourceForResource(
37             "/semantic-statement-parser/identityreftest.yang");
38
39     private static final QNameModule types2Module = QNameModule.create(URI.create("types2"),
40             SimpleDateFormatUtil.DEFAULT_DATE_REV);
41
42     private static final QName lfDecimal = QName.create(types2Module, "lf-decimal");
43     private static final QName lfMyString = QName.create(types2Module, "lf-my-string");
44     private static final QName lfInt8 = QName.create(types2Module, "lf-int8");
45     private static final QName lfInt16 = QName.create(types2Module, "lf-int16");
46     private static final QName lfInt32 = QName.create(types2Module, "lf-int32");
47     private static final QName lfInt64 = QName.create(types2Module, "lf-int64");
48     private static final QName lfUInt8 = QName.create(types2Module, "lf-uint8");
49     private static final QName lfUInt16 = QName.create(types2Module, "lf-uint16");
50     private static final QName lfUInt32 = QName.create(types2Module, "lf-uint32");
51     private static final QName lfUInt64 = QName.create(types2Module, "lf-uint64");
52     private static final QName lfBool = QName.create(types2Module, "lf-bool");
53
54     @Test
55     public void readAndParseYangFileTest() throws SourceException, ReactorException {
56         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
57         addSources(reactor, TYPEFILE1, TYPEFILE2, TYPEFILE3, TYPEFILE4);
58         EffectiveSchemaContext result = reactor.buildEffective();
59         assertNotNull(result);
60
61         final LeafSchemaNode lfDecimalNode = (LeafSchemaNode) result.getDataChildByName(lfDecimal);
62         assertNotNull(lfDecimalNode);
63
64         assertTrue(lfDecimalNode.getType() instanceof DecimalTypeDefinition);
65         final DecimalTypeDefinition lfDecimalNodeType = (DecimalTypeDefinition) lfDecimalNode.getType();
66         assertEquals(2, lfDecimalNodeType.getFractionDigits().intValue());
67
68         final LeafSchemaNode lfInt8Node = (LeafSchemaNode) result.getDataChildByName(lfInt8);
69         assertNotNull(lfInt8Node);
70         assertEquals(BaseTypes.int8Type().getClass(), lfInt8Node.getType().getClass());
71
72         final LeafSchemaNode lfInt16Node = (LeafSchemaNode) result.getDataChildByName(lfInt16);
73         assertNotNull(lfInt16Node);
74         assertEquals(BaseTypes.int16Type().getClass(), lfInt16Node.getType().getClass());
75
76         final LeafSchemaNode lfInt32Node = (LeafSchemaNode) result.getDataChildByName(lfInt32);
77         assertNotNull(lfInt32Node);
78         assertEquals(BaseTypes.int32Type().getClass(), lfInt32Node.getType().getClass());
79
80         final LeafSchemaNode lfInt64Node = (LeafSchemaNode) result.getDataChildByName(lfInt64);
81         assertNotNull(lfInt64Node);
82         assertEquals(BaseTypes.int64Type().getClass(), lfInt64Node.getType().getClass());
83
84         final LeafSchemaNode lfUInt8Node = (LeafSchemaNode) result.getDataChildByName(lfUInt8);
85         assertNotNull(lfUInt8Node);
86         assertEquals(BaseTypes.uint8Type().getClass(), lfUInt8Node.getType().getClass());
87
88         final LeafSchemaNode lfUInt16Node = (LeafSchemaNode) result.getDataChildByName(lfUInt16);
89         assertNotNull(lfUInt16Node);
90         assertEquals(BaseTypes.uint16Type().getClass(), lfUInt16Node.getType().getClass());
91
92         final LeafSchemaNode lfUInt32Node = (LeafSchemaNode) result.getDataChildByName(lfUInt32);
93         assertNotNull(lfUInt32Node);
94         assertEquals(BaseTypes.uint32Type().getClass(), lfUInt32Node.getType().getClass());
95
96         final LeafSchemaNode lfUInt64Node = (LeafSchemaNode) result.getDataChildByName(lfUInt64);
97         assertNotNull(lfUInt64Node);
98         assertEquals(BaseTypes.uint64Type().getClass(), lfUInt64Node.getType().getClass());
99
100         final LeafSchemaNode lfBoolNode = (LeafSchemaNode) result.getDataChildByName(lfBool);
101         assertNotNull(lfBoolNode);
102         assertEquals(BaseTypes.booleanType().getClass(), lfBoolNode.getType().getClass());
103     }
104
105     private static  void addSources(final CrossSourceStatementReactor.BuildAction reactor, final StatementStreamSource... sources) {
106         for (StatementStreamSource source : sources) {
107             reactor.addSource(source);
108         }
109     }
110 }