1 package org.opendaylight.yangtools.yang.stmt.test;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotNull;
7 import org.opendaylight.yangtools.yang.common.QName;
8 import org.opendaylight.yangtools.yang.common.QNameModule;
9 import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
10 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
11 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
12 import org.opendaylight.yangtools.yang.model.api.Module;
13 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
14 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
15 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
16 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
17 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
18 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
19 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
23 public class AugmentProcessTest {
25 private static final YangStatementSourceImpl AUGMENTED = new YangStatementSourceImpl(
26 "/stmt-test/effective-build/augmented.yang");
27 private static final YangStatementSourceImpl ROOT = new YangStatementSourceImpl(
28 "/stmt-test/effective-build/aug-root.yang");
30 private static final QNameModule AUGMENTED_QNAME_MODULE = QNameModule.create(URI.create("aug"), null);
32 QName augParent1 = QName.create(AUGMENTED_QNAME_MODULE, "aug-parent1");
33 QName augParent2 = QName.create(AUGMENTED_QNAME_MODULE, "aug-parent2");
34 QName contTarget = QName.create(AUGMENTED_QNAME_MODULE, "cont-target");
36 QName contAdded1 = QName.create(AUGMENTED_QNAME_MODULE, "cont-added1");
37 QName contAdded2 = QName.create(AUGMENTED_QNAME_MODULE, "cont-added2");
39 QName list1 = QName.create(AUGMENTED_QNAME_MODULE, "list1");
40 QName axml = QName.create(AUGMENTED_QNAME_MODULE, "axml");
42 QName contGrp = QName.create(AUGMENTED_QNAME_MODULE, "cont-grp");
43 QName axmlGrp = QName.create(AUGMENTED_QNAME_MODULE, "axml-grp");
46 public void readAndParseYangFileTest() throws SourceException, ReactorException {
48 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
49 addSources(reactor, AUGMENTED, ROOT);
51 final EffectiveSchemaContext result = reactor.buildEffective();
53 assertNotNull(result);
55 Module augmentedModule = result.findModuleByName("augmented", null);
56 assertNotNull(augmentedModule);
58 ContainerSchemaNode augParent1Node = (ContainerSchemaNode) result.getDataChildByName(augParent1);
59 ContainerSchemaNode augParent2Node = (ContainerSchemaNode) augParent1Node.getDataChildByName(augParent2);
60 ContainerSchemaNode targetContNode = (ContainerSchemaNode) augParent2Node.getDataChildByName(contTarget);
61 assertNotNull(targetContNode);
63 assertNotNull(targetContNode.getChildNodes());
64 assertEquals(3, targetContNode.getChildNodes().size());
66 ContainerSchemaNode contAdded1Node = (ContainerSchemaNode) targetContNode.getDataChildByName(contAdded1);
67 assertNotNull(contAdded1Node);
68 ListSchemaNode list1Node = (ListSchemaNode) contAdded1Node.getDataChildByName(list1);
69 assertNotNull(list1Node);
71 ContainerSchemaNode contAdded2Node = (ContainerSchemaNode) targetContNode.getDataChildByName(contAdded2);
72 assertNotNull(contAdded2Node);
73 AnyXmlSchemaNode axmlNode = (AnyXmlSchemaNode) contAdded2Node.getDataChildByName(axml);
74 assertNotNull(axmlNode);
76 ContainerSchemaNode contGrpNode = (ContainerSchemaNode) targetContNode.getDataChildByName(contGrp);
77 assertNotNull(contGrpNode);
78 AnyXmlSchemaNode axmlGrpNode = (AnyXmlSchemaNode) contGrpNode.getDataChildByName(axmlGrp);
79 assertNotNull(axmlGrpNode);
82 private void addSources(CrossSourceStatementReactor.BuildAction reactor, StatementStreamSource... sources) {
83 for (StatementStreamSource source : sources) {
84 reactor.addSource(source);