Bug 2366 - Effective statements impl for new yang parser.
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / effective / build / test / EffectiveBuildTest.java
index 83a3abdb7d065a390f54e2a9ac6e4e0b58897161..166d08b9c6f51a8344ada62abff1f40735ce16a9 100644 (file)
@@ -2,22 +2,27 @@ package org.opendaylight.yangtools.yang.stmt.effective.build.test;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
-import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
-import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.Module;
+
 import java.net.URI;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
-import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.junit.Test;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
 
 public class EffectiveBuildTest {
 
-    private static final YangFileStatementSource SIMPLE_MODULE = new YangFileStatementSource("/stmt-test/effective-build/simple-module.yang");
+    private static final YangStatementSourceImpl SIMPLE_MODULE = new YangStatementSourceImpl(
+            "/stmt-test/effective-build/simple-module.yang");
     private static final QNameModule SIMPLE_MODULE_QNAME = QNameModule.create(URI.create("simple.yang"), null);
 
     @Test
@@ -28,7 +33,7 @@ public class EffectiveBuildTest {
 
         assertNotNull(result);
 
-        Module simpleModule = result.findModuleByName("simple-module",null);
+        Module simpleModule = result.findModuleByName("simple-module", null);
         assertNotNull(simpleModule);
 
         QName q1 = QName.create(SIMPLE_MODULE_QNAME, "root-container");
@@ -39,34 +44,38 @@ public class EffectiveBuildTest {
         QName q6 = QName.create(SIMPLE_MODULE_QNAME, "sub-sub-container2");
         QName q7 = QName.create(SIMPLE_MODULE_QNAME, "grp");
 
-        ContainerSchemaNode rootCon = (ContainerSchemaNode)simpleModule.getDataChildByName(q1);
+        ContainerSchemaNode rootCon = (ContainerSchemaNode) simpleModule.getDataChildByName(q1);
         assertNotNull(rootCon);
 
-        ContainerSchemaNode subCon = (ContainerSchemaNode)rootCon.getDataChildByName(q2);
+        ContainerSchemaNode subCon = (ContainerSchemaNode) rootCon.getDataChildByName(q2);
         assertNotNull(subCon);
 
-        ContainerSchemaNode subSubCon = (ContainerSchemaNode)subCon.getDataChildByName(q3);
+        ContainerSchemaNode subSubCon = (ContainerSchemaNode) subCon.getDataChildByName(q3);
         assertNotNull(subSubCon);
 
-        ContainerSchemaNode rootCon2 = (ContainerSchemaNode)simpleModule.getDataChildByName(q4);
+        ContainerSchemaNode rootCon2 = (ContainerSchemaNode) simpleModule.getDataChildByName(q4);
         assertNotNull(rootCon2);
 
-        ContainerSchemaNode subCon2 = (ContainerSchemaNode)rootCon2.getDataChildByName(q5);
+        ContainerSchemaNode subCon2 = (ContainerSchemaNode) rootCon2.getDataChildByName(q5);
         assertNotNull(subCon2);
 
-        ContainerSchemaNode subSubCon2 = (ContainerSchemaNode)subCon2.getDataChildByName(q6);
+        ContainerSchemaNode subSubCon2 = (ContainerSchemaNode) subCon2.getDataChildByName(q6);
         assertNotNull(subSubCon2);
 
         GroupingDefinition grp = simpleModule.getGroupings().iterator().next();
         assertNotNull(grp);
-        assertEquals(q7,grp.getQName());
+        assertEquals(q7, grp.getQName());
 
         ContainerSchemaNode grpSubCon2 = (ContainerSchemaNode) grp.getDataChildByName(q5);
         assertNotNull(grpSubCon2);
 
-        ContainerSchemaNode grpSubSubCon2 = (ContainerSchemaNode)grpSubCon2.getDataChildByName(q6);
+        ContainerSchemaNode grpSubSubCon2 = (ContainerSchemaNode) grpSubCon2.getDataChildByName(q6);
         assertNotNull(grpSubSubCon2);
 
+        assertEquals(SchemaPath.create(true, q1, q2, q3), subSubCon.getPath());
+        assertEquals(SchemaPath.create(true, q4, q5, q6), subSubCon2.getPath());
+        assertEquals(SchemaPath.create(true, q7, q5, q6), grpSubSubCon2.getPath());
+
     }
 
     private void log(Throwable e, String indent) {
@@ -79,9 +88,8 @@ public class EffectiveBuildTest {
 
     }
 
-    private void addSources(BuildAction reactor,
-            YangFileStatementSource... sources) {
-        for (YangFileStatementSource source : sources) {
+    private void addSources(BuildAction reactor, YangStatementSourceImpl... sources) {
+        for (YangStatementSourceImpl source : sources) {
             reactor.addSource(source);
         }
     }