2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.stmt;
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;
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.impl.DefaultReactors;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
25 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
27 public class YangTypes2StmtTest {
29 private static final StatementStreamSource TYPEFILE1 = sourceForResource("/semantic-statement-parser/types2.yang");
30 private static final StatementStreamSource TYPEFILE2 = sourceForResource("/semantic-statement-parser/types.yang");
31 private static final StatementStreamSource TYPEFILE3 = sourceForResource(
32 "/semantic-statement-parser/simple-types.yang");
33 private static final StatementStreamSource TYPEFILE4 = sourceForResource(
34 "/semantic-statement-parser/identityreftest.yang");
36 private static final QNameModule TYPES2_MODULE = QNameModule.create(URI.create("types2"));
38 private static final QName LF_DECIMAL = QName.create(TYPES2_MODULE, "lf-decimal");
39 private static final QName LF_MY_STRING = QName.create(TYPES2_MODULE, "lf-my-string");
40 private static final QName LF_INT8 = QName.create(TYPES2_MODULE, "lf-int8");
41 private static final QName LF_INT16 = QName.create(TYPES2_MODULE, "lf-int16");
42 private static final QName LF_INT32 = QName.create(TYPES2_MODULE, "lf-int32");
43 private static final QName LF_INT64 = QName.create(TYPES2_MODULE, "lf-int64");
44 private static final QName LF_UINT8 = QName.create(TYPES2_MODULE, "lf-uint8");
45 private static final QName LF_UINT16 = QName.create(TYPES2_MODULE, "lf-uint16");
46 private static final QName LF_UINT32 = QName.create(TYPES2_MODULE, "lf-uint32");
47 private static final QName LF_UINT64 = QName.create(TYPES2_MODULE, "lf-uint64");
48 private static final QName LF_BOOL = QName.create(TYPES2_MODULE, "lf-bool");
51 public void readAndParseYangFileTest() throws ReactorException {
52 SchemaContext result = DefaultReactors.defaultReactor().newBuild()
53 .addSources(TYPEFILE1, TYPEFILE2, TYPEFILE3, TYPEFILE4)
55 assertNotNull(result);
57 final LeafSchemaNode lfDecimalNode = (LeafSchemaNode) result.getDataChildByName(LF_DECIMAL);
58 assertNotNull(lfDecimalNode);
60 assertTrue(lfDecimalNode.getType() instanceof DecimalTypeDefinition);
61 final DecimalTypeDefinition lfDecimalNodeType = (DecimalTypeDefinition) lfDecimalNode.getType();
62 assertEquals(2, lfDecimalNodeType.getFractionDigits());
64 final LeafSchemaNode lfInt8Node = (LeafSchemaNode) result.getDataChildByName(LF_INT8);
65 assertNotNull(lfInt8Node);
66 assertEquals(BaseTypes.int8Type().getClass(), lfInt8Node.getType().getClass());
68 final LeafSchemaNode lfInt16Node = (LeafSchemaNode) result.getDataChildByName(LF_INT16);
69 assertNotNull(lfInt16Node);
70 assertEquals(BaseTypes.int16Type().getClass(), lfInt16Node.getType().getClass());
72 final LeafSchemaNode lfInt32Node = (LeafSchemaNode) result.getDataChildByName(LF_INT32);
73 assertNotNull(lfInt32Node);
74 assertEquals(BaseTypes.int32Type().getClass(), lfInt32Node.getType().getClass());
76 final LeafSchemaNode lfInt64Node = (LeafSchemaNode) result.getDataChildByName(LF_INT64);
77 assertNotNull(lfInt64Node);
78 assertEquals(BaseTypes.int64Type().getClass(), lfInt64Node.getType().getClass());
80 final LeafSchemaNode lfUInt8Node = (LeafSchemaNode) result.getDataChildByName(LF_UINT8);
81 assertNotNull(lfUInt8Node);
82 assertEquals(BaseTypes.uint8Type().getClass(), lfUInt8Node.getType().getClass());
84 final LeafSchemaNode lfUInt16Node = (LeafSchemaNode) result.getDataChildByName(LF_UINT16);
85 assertNotNull(lfUInt16Node);
86 assertEquals(BaseTypes.uint16Type().getClass(), lfUInt16Node.getType().getClass());
88 final LeafSchemaNode lfUInt32Node = (LeafSchemaNode) result.getDataChildByName(LF_UINT32);
89 assertNotNull(lfUInt32Node);
90 assertEquals(BaseTypes.uint32Type().getClass(), lfUInt32Node.getType().getClass());
92 final LeafSchemaNode lfUInt64Node = (LeafSchemaNode) result.getDataChildByName(LF_UINT64);
93 assertNotNull(lfUInt64Node);
94 assertEquals(BaseTypes.uint64Type().getClass(), lfUInt64Node.getType().getClass());
96 final LeafSchemaNode lfBoolNode = (LeafSchemaNode) result.getDataChildByName(LF_BOOL);
97 assertNotNull(lfBoolNode);
98 assertEquals(BaseTypes.booleanType().getClass(), lfBoolNode.getType().getClass());