2 * Copyright (c) 2015 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.test;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
13 import org.opendaylight.yangtools.yang.model.util.ExtendedType;
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.util.BooleanType;
22 import org.opendaylight.yangtools.yang.model.util.Int16;
23 import org.opendaylight.yangtools.yang.model.util.Int32;
24 import org.opendaylight.yangtools.yang.model.util.Int64;
25 import org.opendaylight.yangtools.yang.model.util.Int8;
26 import org.opendaylight.yangtools.yang.model.util.Uint16;
27 import org.opendaylight.yangtools.yang.model.util.Uint32;
28 import org.opendaylight.yangtools.yang.model.util.Uint64;
29 import org.opendaylight.yangtools.yang.model.util.Uint8;
30 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
31 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
32 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
33 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
34 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
35 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
36 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
38 public class YangTypes2StmtTest {
40 private static final YangStatementSourceImpl TYPEFILE1 = new YangStatementSourceImpl(
41 "/semantic-statement-parser/types2.yang", false);
42 private static final YangStatementSourceImpl TYPEFILE2 = new YangStatementSourceImpl(
43 "/semantic-statement-parser/types.yang", false);
44 private static final YangStatementSourceImpl TYPEFILE3 = new YangStatementSourceImpl(
45 "/semantic-statement-parser/simple-types.yang", false);
46 private static final YangStatementSourceImpl TYPEFILE4 = new YangStatementSourceImpl(
47 "/semantic-statement-parser/identityreftest.yang", false);
49 private static final QNameModule types2Module = QNameModule.create(URI.create("types2"),
50 SimpleDateFormatUtil.DEFAULT_DATE_REV);
52 private static final QName lfDecimal = QName.create(types2Module, "lf-decimal");
53 private static final QName lfMyString = QName.create(types2Module, "lf-my-string");
54 private static final QName lfInt8 = QName.create(types2Module, "lf-int8");
55 private static final QName lfInt16 = QName.create(types2Module, "lf-int16");
56 private static final QName lfInt32 = QName.create(types2Module, "lf-int32");
57 private static final QName lfInt64 = QName.create(types2Module, "lf-int64");
58 private static final QName lfUInt8 = QName.create(types2Module, "lf-uint8");
59 private static final QName lfUInt16 = QName.create(types2Module, "lf-uint16");
60 private static final QName lfUInt32 = QName.create(types2Module, "lf-uint32");
61 private static final QName lfUInt64 = QName.create(types2Module, "lf-uint64");
62 private static final QName lfBool = QName.create(types2Module, "lf-bool");
65 public void readAndParseYangFileTest() throws SourceException, ReactorException {
66 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
67 addSources(reactor, TYPEFILE1, TYPEFILE2, TYPEFILE3, TYPEFILE4);
68 EffectiveSchemaContext result = reactor.buildEffective();
69 assertNotNull(result);
71 final LeafSchemaNode lfDecimalNode = (LeafSchemaNode) result.getDataChildByName(lfDecimal);
72 assertNotNull(lfDecimalNode);
73 final ExtendedType lfDecimalNodeType = (ExtendedType) lfDecimalNode.getType();
74 assertEquals(ExtendedType.class, lfDecimalNodeType.getClass());
75 assertEquals(2, lfDecimalNodeType.getFractionDigits().intValue());
77 final LeafSchemaNode lfInt8Node = (LeafSchemaNode) result.getDataChildByName(lfInt8);
78 assertNotNull(lfInt8Node);
79 assertEquals(Int8.class, lfInt8Node.getType().getClass());
81 final LeafSchemaNode lfInt16Node = (LeafSchemaNode) result.getDataChildByName(lfInt16);
82 assertNotNull(lfInt16Node);
83 assertEquals(Int16.class, lfInt16Node.getType().getClass());
85 final LeafSchemaNode lfInt32Node = (LeafSchemaNode) result.getDataChildByName(lfInt32);
86 assertNotNull(lfInt32Node);
87 assertEquals(Int32.class, lfInt32Node.getType().getClass());
89 final LeafSchemaNode lfInt64Node = (LeafSchemaNode) result.getDataChildByName(lfInt64);
90 assertNotNull(lfInt64Node);
91 assertEquals(Int64.class, lfInt64Node.getType().getClass());
93 final LeafSchemaNode lfUInt8Node = (LeafSchemaNode) result.getDataChildByName(lfUInt8);
94 assertNotNull(lfUInt8Node);
95 assertEquals(Uint8.class, lfUInt8Node.getType().getClass());
97 final LeafSchemaNode lfUInt16Node = (LeafSchemaNode) result.getDataChildByName(lfUInt16);
98 assertNotNull(lfUInt16Node);
99 assertEquals(Uint16.class, lfUInt16Node.getType().getClass());
101 final LeafSchemaNode lfUInt32Node = (LeafSchemaNode) result.getDataChildByName(lfUInt32);
102 assertNotNull(lfUInt32Node);
103 assertEquals(Uint32.class, lfUInt32Node.getType().getClass());
105 final LeafSchemaNode lfUInt64Node = (LeafSchemaNode) result.getDataChildByName(lfUInt64);
106 assertNotNull(lfUInt64Node);
107 assertEquals(Uint64.class, lfUInt64Node.getType().getClass());
109 final LeafSchemaNode lfBoolNode = (LeafSchemaNode) result.getDataChildByName(lfBool);
110 assertNotNull(lfBoolNode);
111 assertEquals(BooleanType.class, lfBoolNode.getType().getClass());
114 private void addSources(CrossSourceStatementReactor.BuildAction reactor, StatementStreamSource... sources) {
115 for (StatementStreamSource source : sources) {
116 reactor.addSource(source);