1 package org.opendaylight.yangtools.yang.stmt.effective.build.test;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotNull;
9 import org.opendaylight.yangtools.yang.common.QName;
10 import org.opendaylight.yangtools.yang.common.QNameModule;
11 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
12 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
13 import org.opendaylight.yangtools.yang.model.api.Module;
14 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
15 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
16 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
17 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
18 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
19 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
20 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
22 public class EffectiveBuildTest {
24 private static final YangStatementSourceImpl SIMPLE_MODULE = new YangStatementSourceImpl(
25 "/stmt-test/effective-build/simple-module.yang");
26 private static final QNameModule SIMPLE_MODULE_QNAME = QNameModule.create(URI.create("simple.yang"), null);
29 public void effectiveBuildTest() throws SourceException, ReactorException {
30 BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
31 addSources(reactor, SIMPLE_MODULE);
32 EffectiveSchemaContext result = reactor.buildEffective();
34 assertNotNull(result);
36 Module simpleModule = result.findModuleByName("simple-module", null);
37 assertNotNull(simpleModule);
39 QName q1 = QName.create(SIMPLE_MODULE_QNAME, "root-container");
40 QName q2 = QName.create(SIMPLE_MODULE_QNAME, "sub-container");
41 QName q3 = QName.create(SIMPLE_MODULE_QNAME, "sub-sub-container");
42 QName q4 = QName.create(SIMPLE_MODULE_QNAME, "root-container2");
43 QName q5 = QName.create(SIMPLE_MODULE_QNAME, "sub-container2");
44 QName q6 = QName.create(SIMPLE_MODULE_QNAME, "sub-sub-container2");
45 QName q7 = QName.create(SIMPLE_MODULE_QNAME, "grp");
47 ContainerSchemaNode rootCon = (ContainerSchemaNode) simpleModule.getDataChildByName(q1);
48 assertNotNull(rootCon);
50 ContainerSchemaNode subCon = (ContainerSchemaNode) rootCon.getDataChildByName(q2);
51 assertNotNull(subCon);
53 ContainerSchemaNode subSubCon = (ContainerSchemaNode) subCon.getDataChildByName(q3);
54 assertNotNull(subSubCon);
56 ContainerSchemaNode rootCon2 = (ContainerSchemaNode) simpleModule.getDataChildByName(q4);
57 assertNotNull(rootCon2);
59 ContainerSchemaNode subCon2 = (ContainerSchemaNode) rootCon2.getDataChildByName(q5);
60 assertNotNull(subCon2);
62 ContainerSchemaNode subSubCon2 = (ContainerSchemaNode) subCon2.getDataChildByName(q6);
63 assertNotNull(subSubCon2);
65 GroupingDefinition grp = simpleModule.getGroupings().iterator().next();
67 assertEquals(q7, grp.getQName());
69 ContainerSchemaNode grpSubCon2 = (ContainerSchemaNode) grp.getDataChildByName(q5);
70 assertNotNull(grpSubCon2);
72 ContainerSchemaNode grpSubSubCon2 = (ContainerSchemaNode) grpSubCon2.getDataChildByName(q6);
73 assertNotNull(grpSubSubCon2);
75 assertEquals(SchemaPath.create(true, q1, q2, q3), subSubCon.getPath());
76 assertEquals(SchemaPath.create(true, q4, q5, q6), subSubCon2.getPath());
77 assertEquals(SchemaPath.create(true, q7, q5, q6), grpSubSubCon2.getPath());
81 private void log(Throwable e, String indent) {
82 System.out.println(indent + e.getMessage());
84 Throwable[] suppressed = e.getSuppressed();
85 for (Throwable throwable : suppressed) {
86 log(throwable, indent + " ");
91 private void addSources(BuildAction reactor, YangStatementSourceImpl... sources) {
92 for (YangStatementSourceImpl source : sources) {
93 reactor.addSource(source);