Allow fluent use of BuildAction
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / ImportResolutionBasicTest.java
index f1003b82520d08a6138263133395c3e9ec026806..2e832f03eda066b968a1f871ca3c9c36c7a4db88 100644 (file)
@@ -12,58 +12,58 @@ 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.model.api.SchemaContext;
 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);
-        EffectiveModelContext result = reactor.build();
+    public void inImportOrderTest() throws ReactorException {
+        EffectiveModelContext result = YangInferencePipeline.RFC6020_REACTOR.newBuild()
+                .addSources(ROOT_WITHOUT_IMPORT, IMPORT_ROOT, IMPORT_DERIVED)
+                .build();
         assertNotNull(result);
     }
 
     @Test
-    public void inInverseOfImportOrderTest() throws SourceException, ReactorException {
-        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        addSources(reactor, IMPORT_DERIVED, IMPORT_ROOT, ROOT_WITHOUT_IMPORT);
-        EffectiveModelContext result = reactor.build();
+    public void inInverseOfImportOrderTest() throws ReactorException {
+        EffectiveModelContext result = YangInferencePipeline.RFC6020_REACTOR.newBuild()
+                .addSources(IMPORT_DERIVED, IMPORT_ROOT, ROOT_WITHOUT_IMPORT)
+                .build();
         assertNotNull(result);
     }
 
     @Test
-    public void missingImportedSourceTest() throws SourceException {
-        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        addSources(reactor, IMPORT_DERIVED, ROOT_WITHOUT_IMPORT);
+    public void missingImportedSourceTest() {
+        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild()
+                .addSources(IMPORT_DERIVED, ROOT_WITHOUT_IMPORT);
         try {
             reactor.build();
             fail("reactor.process should fail due to missing imported source");
@@ -75,9 +75,9 @@ public class ImportResolutionBasicTest {
     }
 
     @Test
-    public void circularImportsTest() throws SourceException {
-        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        addSources(reactor, CYCLE_YIN, CYCLE_YANG);
+    public void circularImportsTest() {
+        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild()
+                .addSources(CYCLE_YIN, CYCLE_YANG);
         try {
             reactor.build();
             fail("reactor.process should fail due to circular import");
@@ -88,9 +88,9 @@ public class ImportResolutionBasicTest {
     }
 
     @Test
-    public void selfImportTest() throws SourceException {
-        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        addSources(reactor, IMPORT_SELF, IMPORT_ROOT, ROOT_WITHOUT_IMPORT);
+    public void selfImportTest() {
+        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild()
+                .addSources(IMPORT_SELF, IMPORT_ROOT, ROOT_WITHOUT_IMPORT);
         try {
             reactor.build();
             fail("reactor.process should fail due to self import");
@@ -101,18 +101,10 @@ public class ImportResolutionBasicTest {
     }
 
     @Test
-    public void bug2649Test() throws SourceException, ReactorException{
-        BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        addSources(reactor, FOO, IMPORT);
-
-        EffectiveSchemaContext buildEffective = reactor.buildEffective();
+    public void bug2649Test() throws ReactorException {
+        SchemaContext buildEffective = YangInferencePipeline.RFC6020_REACTOR.newBuild()
+                .addSources(FOO, IMPORT)
+                .buildEffective();
         assertNotNull(buildEffective);
     }
-
-    private static void addSources(final BuildAction reactor, final YangStatementSourceImpl... sources) {
-        for (YangStatementSourceImpl source : sources) {
-            reactor.addSource(source);
-        }
-    }
-
 }