Update StmtTestUtils
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / ImportResolutionBasicTest.java
index f1003b82520d08a6138263133395c3e9ec026806..c272b4b63e4af713242d1849cce90e754e855027 100644 (file)
@@ -12,42 +12,43 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
 
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
 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.BuildAction;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
 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 ImportResolutionBasicTest {
 
-    private static final YangStatementSourceImpl ROOT_WITHOUT_IMPORT = new YangStatementSourceImpl(
-            "/semantic-statement-parser/import-arg-parsing/nature.yang", false);
-    private static final YangStatementSourceImpl IMPORT_ROOT = new YangStatementSourceImpl(
-            "/semantic-statement-parser/import-arg-parsing/mammal.yang", false);
-    private static final YangStatementSourceImpl IMPORT_DERIVED = new YangStatementSourceImpl(
-            "/semantic-statement-parser/import-arg-parsing/human.yang", false);
-    private static final YangStatementSourceImpl IMPORT_SELF = new YangStatementSourceImpl(
-            "/semantic-statement-parser/import-arg-parsing/egocentric.yang", false);
-    private static final YangStatementSourceImpl CYCLE_YIN = new YangStatementSourceImpl(
-            "/semantic-statement-parser/import-arg-parsing/cycle-yin.yang", false);
-    private static final YangStatementSourceImpl CYCLE_YANG = new YangStatementSourceImpl(
-            "/semantic-statement-parser/import-arg-parsing/cycle-yang.yang", false);
-    private static final YangStatementSourceImpl FOO = new YangStatementSourceImpl(
-            "/semantic-statement-parser/bug2649/foo.yang", false);
-    private static final YangStatementSourceImpl IMPORT = new YangStatementSourceImpl(
-            "/semantic-statement-parser/bug2649/import-module.yang", false);
+    private static final StatementStreamSource ROOT_WITHOUT_IMPORT = sourceForResource(
+            "/semantic-statement-parser/import-arg-parsing/nature.yang");
+    private static final StatementStreamSource IMPORT_ROOT = sourceForResource(
+            "/semantic-statement-parser/import-arg-parsing/mammal.yang");
+    private static final StatementStreamSource IMPORT_DERIVED = sourceForResource(
+            "/semantic-statement-parser/import-arg-parsing/human.yang");
+    private static final StatementStreamSource IMPORT_SELF = sourceForResource(
+            "/semantic-statement-parser/import-arg-parsing/egocentric.yang");
+    private static final StatementStreamSource CYCLE_YIN = sourceForResource(
+            "/semantic-statement-parser/import-arg-parsing/cycle-yin.yang");
+    private static final StatementStreamSource CYCLE_YANG = sourceForResource(
+            "/semantic-statement-parser/import-arg-parsing/cycle-yang.yang");
+    private static final StatementStreamSource FOO = sourceForResource(
+            "/semantic-statement-parser/bug2649/foo.yang");
+    private static final StatementStreamSource IMPORT = sourceForResource(
+            "/semantic-statement-parser/bug2649/import-module.yang");
 
 
     @Test
     public void inImportOrderTest() throws SourceException, ReactorException {
         BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        addSources(reactor, ROOT_WITHOUT_IMPORT, IMPORT_ROOT, IMPORT_DERIVED);
+        reactor.addSources(ROOT_WITHOUT_IMPORT, IMPORT_ROOT, IMPORT_DERIVED);
         EffectiveModelContext result = reactor.build();
         assertNotNull(result);
     }
@@ -55,7 +56,7 @@ public class ImportResolutionBasicTest {
     @Test
     public void inInverseOfImportOrderTest() throws SourceException, ReactorException {
         BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        addSources(reactor, IMPORT_DERIVED, IMPORT_ROOT, ROOT_WITHOUT_IMPORT);
+        reactor.addSources(IMPORT_DERIVED, IMPORT_ROOT, ROOT_WITHOUT_IMPORT);
         EffectiveModelContext result = reactor.build();
         assertNotNull(result);
     }
@@ -63,7 +64,7 @@ public class ImportResolutionBasicTest {
     @Test
     public void missingImportedSourceTest() throws SourceException {
         BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        addSources(reactor, IMPORT_DERIVED, ROOT_WITHOUT_IMPORT);
+        reactor.addSources(IMPORT_DERIVED, ROOT_WITHOUT_IMPORT);
         try {
             reactor.build();
             fail("reactor.process should fail due to missing imported source");
@@ -77,7 +78,7 @@ public class ImportResolutionBasicTest {
     @Test
     public void circularImportsTest() throws SourceException {
         BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        addSources(reactor, CYCLE_YIN, CYCLE_YANG);
+        reactor.addSources(CYCLE_YIN, CYCLE_YANG);
         try {
             reactor.build();
             fail("reactor.process should fail due to circular import");
@@ -90,7 +91,7 @@ public class ImportResolutionBasicTest {
     @Test
     public void selfImportTest() throws SourceException {
         BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        addSources(reactor, IMPORT_SELF, IMPORT_ROOT, ROOT_WITHOUT_IMPORT);
+        reactor.addSources(IMPORT_SELF, IMPORT_ROOT, ROOT_WITHOUT_IMPORT);
         try {
             reactor.build();
             fail("reactor.process should fail due to self import");
@@ -103,16 +104,9 @@ public class ImportResolutionBasicTest {
     @Test
     public void bug2649Test() throws SourceException, ReactorException{
         BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        addSources(reactor, FOO, IMPORT);
+        reactor.addSources(FOO, IMPORT);
 
         EffectiveSchemaContext buildEffective = reactor.buildEffective();
         assertNotNull(buildEffective);
     }
-
-    private static void addSources(final BuildAction reactor, final YangStatementSourceImpl... sources) {
-        for (YangStatementSourceImpl source : sources) {
-            reactor.addSource(source);
-        }
-    }
-
 }