Bug 8307: Add the option for activating deviation statements
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / EffectiveModuleTest.java
index ceefbd3867988a21835f61861aa833efefa4c0b1..0891fcc054e9dbc06d7b56a75d92276a168339c4 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.yangtools.yang.stmt;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
 
 import java.net.URI;
 import java.text.ParseException;
@@ -37,19 +38,19 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.Status;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
 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 EffectiveModuleTest {
 
-    private static final YangStatementSourceImpl ROOT_MODULE = new YangStatementSourceImpl(
-            "/semantic-statement-parser/effective-module/root.yang", false);
-    private static final YangStatementSourceImpl IMPORTED_MODULE = new YangStatementSourceImpl(
-            "/semantic-statement-parser/effective-module/imported.yang", false);
-    private static final YangStatementSourceImpl SUBMODULE = new YangStatementSourceImpl(
-            "/semantic-statement-parser/effective-module/submod.yang", false);
+    private static final StatementStreamSource ROOT_MODULE = sourceForResource(
+            "/semantic-statement-parser/effective-module/root.yang");
+    private static final StatementStreamSource IMPORTED_MODULE = sourceForResource(
+            "/semantic-statement-parser/effective-module/imported.yang");
+    private static final StatementStreamSource SUBMODULE = sourceForResource(
+            "/semantic-statement-parser/effective-module/submod.yang");
 
     private static final QNameModule ROOT_MODULE_QNAME = QNameModule.create(URI.create("root-ns"),
             SimpleDateFormatUtil.DEFAULT_DATE_REV);
@@ -74,7 +75,7 @@ public class EffectiveModuleTest {
     @Test
     public void effectiveBuildTest() throws SourceException, ReactorException {
         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        addSources(reactor, ROOT_MODULE, IMPORTED_MODULE, SUBMODULE);
+        reactor.addSources(ROOT_MODULE, IMPORTED_MODULE, SUBMODULE);
         EffectiveSchemaContext result = reactor.buildEffective();
 
         assertNotNull(result);
@@ -118,7 +119,10 @@ public class EffectiveModuleTest {
         assertEquals(1, deviations.size());
         final Deviation deviationStmt = deviations.iterator().next();
         assertNotNull(deviationStmt);
-        assertEquals(contSchemaPath, deviationStmt.getTargetPath());
+        final QNameModule importedModuleQName = QNameModule.create(URI.create("imported"), revision);
+        final QName importedContQName = QName.create(importedModuleQName, "cont");
+        final SchemaPath importedContSchemaPath = SchemaPath.create(true, importedContQName);
+        assertEquals(importedContSchemaPath, deviationStmt.getTargetPath());
         assertEquals(DeviateKind.ADD, deviationStmt.getDeviates().iterator().next().getDeviateType());
         assertEquals("deviate reference", deviationStmt.getReference());
 
@@ -140,10 +144,4 @@ public class EffectiveModuleTest {
         assertEquals(1, extensionSchemaNodes.size());
         assertEquals("ext1", extensionSchemaNodes.iterator().next().getQName().getLocalName());
     }
-
-    private static void addSources(final CrossSourceStatementReactor.BuildAction reactor, final YangStatementSourceImpl... sources) {
-        for (YangStatementSourceImpl source : sources) {
-            reactor.addSource(source);
-        }
-    }
 }