YANGTOOLS-706: Refactor YangInferencePipeline
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / IdentityStmtTest.java
index 8703c20c8d81523c943f5dfe37633ac4cb26895c..dacebb5c39ca4d8320b3e9e3021d7ea1241096db 100644 (file)
@@ -13,81 +13,70 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertThat;
+import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
 
 import java.util.Iterator;
 import java.util.Set;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.parser.impl.DefaultReactors;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
-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;
+import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
 
 public class IdentityStmtTest {
 
-    private static final YangStatementSourceImpl ILLEGAL_IDENTITY_MODULE = new YangStatementSourceImpl
-            ("/identity/identitytest.yang", false);
-    private static final YangStatementSourceImpl ILLEGAL_IDENTITY_MODULE2 = new YangStatementSourceImpl
-            ("/identity/prefixidentitytest.yang", false);
-    private static final YangStatementSourceImpl LEGAL_IDENTITY_MODULE = new YangStatementSourceImpl
-            ("/identity/import/dummy.yang", false);
-    private static final YangStatementSourceImpl LEGAL_IDENTITY_MODULE2 = new YangStatementSourceImpl
-            ("/identity/import/prefiximportidentitytest.yang", false);
-    private static final YangStatementSourceImpl ILLEGAL_IDENTITY_MODULE3 = new YangStatementSourceImpl
-            ("/identity/illegal-chained-identity-test.yang", false);
-    private static final YangStatementSourceImpl LEGAL_IDENTITY_MODULE3 = new YangStatementSourceImpl
-            ("/identity/legal-chained-identity-test.yang", false);
-    private static final YangStatementSourceImpl DUPLICATE_IDENTITY_MODULE = new YangStatementSourceImpl
-            ("/identity/duplicate-identity-test.yang", false);
+    private static final StatementStreamSource ILLEGAL_IDENTITY_MODULE = sourceForResource(
+        "/identity/identitytest.yang");
+    private static final StatementStreamSource ILLEGAL_IDENTITY_MODULE2 = sourceForResource(
+        "/identity/prefixidentitytest.yang");
+    private static final StatementStreamSource LEGAL_IDENTITY_MODULE = sourceForResource(
+        "/identity/import/dummy.yang");
+    private static final StatementStreamSource LEGAL_IDENTITY_MODULE2 = sourceForResource(
+        "/identity/import/prefiximportidentitytest.yang");
+    private static final StatementStreamSource ILLEGAL_IDENTITY_MODULE3 = sourceForResource(
+        "/identity/illegal-chained-identity-test.yang");
+    private static final StatementStreamSource LEGAL_IDENTITY_MODULE3 = sourceForResource(
+        "/identity/legal-chained-identity-test.yang");
+    private static final StatementStreamSource DUPLICATE_IDENTITY_MODULE = sourceForResource(
+        "/identity/duplicate-identity-test.yang");
 
     @Test(expected = SomeModifiersUnresolvedException.class)
     public void selfReferencingIdentityTest() throws ReactorException {
-        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        StmtTestUtils.addSources(reactor, ILLEGAL_IDENTITY_MODULE);
-
-        EffectiveSchemaContext result = reactor.buildEffective();
-        assertNotNull(result);
+        DefaultReactors.defaultReactor().newBuild().addSource(ILLEGAL_IDENTITY_MODULE).buildEffective();
     }
 
     @Test(expected = SomeModifiersUnresolvedException.class)
     public void selfReferencingIdentityWithPrefixTest() throws ReactorException {
-        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        StmtTestUtils.addSources(reactor, ILLEGAL_IDENTITY_MODULE2);
-
-        EffectiveSchemaContext result = reactor.buildEffective();
-        assertNotNull(result);
+        DefaultReactors.defaultReactor().newBuild().addSource(ILLEGAL_IDENTITY_MODULE2).buildEffective();
     }
 
     @Test
     public void importedIdentityTest() throws ReactorException {
-        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        StmtTestUtils.addSources(reactor, LEGAL_IDENTITY_MODULE, LEGAL_IDENTITY_MODULE2);
-
-        EffectiveSchemaContext result = reactor.buildEffective();
+        SchemaContext result = DefaultReactors.defaultReactor().newBuild()
+                .addSources(LEGAL_IDENTITY_MODULE, LEGAL_IDENTITY_MODULE2)
+                .buildEffective();
         assertNotNull(result);
     }
 
     @Test(expected = SomeModifiersUnresolvedException.class)
     public void selfReferencingIdentityThroughChaining() throws ReactorException {
-        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        StmtTestUtils.addSources(reactor, ILLEGAL_IDENTITY_MODULE3);
-
-        EffectiveSchemaContext result = reactor.buildEffective();
+        SchemaContext result = DefaultReactors.defaultReactor().newBuild()
+                .addSource(ILLEGAL_IDENTITY_MODULE3)
+                .buildEffective();
         assertNotNull(result);
     }
 
     @Test
     public void chainedIdentityTest() throws ReactorException {
-        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        StmtTestUtils.addSources(reactor, LEGAL_IDENTITY_MODULE3);
-
-        EffectiveSchemaContext result = reactor.buildEffective();
+        SchemaContext result = DefaultReactors.defaultReactor().newBuild()
+                .addSource(LEGAL_IDENTITY_MODULE3)
+                .buildEffective();
         assertNotNull(result);
 
-        Module testModule = result.findModuleByName("legal-chained-identity-test", null);
+        Module testModule = result.findModules("legal-chained-identity-test").iterator().next();
         assertNotNull(testModule);
 
         Set<IdentitySchemaNode> identities = testModule.getIdentities();
@@ -95,31 +84,30 @@ public class IdentityStmtTest {
 
         Iterator<IdentitySchemaNode> identitiesIterator = identities.iterator();
         IdentitySchemaNode identity = identitiesIterator.next();
-        assertThat(identity.getQName().getLocalName(), anyOf(is("first-identity"), is("second-identity"), is
-                ("third-identity"), is("fourth-identity")));
+        assertThat(identity.getQName().getLocalName(), anyOf(is("first-identity"), is("second-identity"),
+            is("third-identity"), is("fourth-identity")));
 
         identity = identitiesIterator.next();
-        assertThat(identity.getQName().getLocalName(), anyOf(is("first-identity"), is("second-identity"), is
-                ("third-identity"), is("fourth-identity")));
+        assertThat(identity.getQName().getLocalName(), anyOf(is("first-identity"), is("second-identity"),
+            is("third-identity"), is("fourth-identity")));
 
         identity = identitiesIterator.next();
-        assertThat(identity.getQName().getLocalName(), anyOf(is("first-identity"), is("second-identity"), is
-                ("third-identity"), is("fourth-identity")));
+        assertThat(identity.getQName().getLocalName(), anyOf(is("first-identity"), is("second-identity"),
+            is("third-identity"), is("fourth-identity")));
 
         identity = identitiesIterator.next();
-        assertThat(identity.getQName().getLocalName(), anyOf(is("first-identity"), is("second-identity"), is
-                ("third-identity"), is("fourth-identity")));
+        assertThat(identity.getQName().getLocalName(), anyOf(is("first-identity"), is("second-identity"),
+            is("third-identity"), is("fourth-identity")));
     }
 
     @Test
     public void duplicateIdentityTest() throws ReactorException {
-        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        StmtTestUtils.addSources(reactor, DUPLICATE_IDENTITY_MODULE);
-
-        EffectiveSchemaContext result = reactor.buildEffective();
+        SchemaContext result = DefaultReactors.defaultReactor().newBuild()
+                .addSource(DUPLICATE_IDENTITY_MODULE)
+                .buildEffective();
         assertNotNull(result);
 
-        Module testModule = result.findModuleByName("duplicate-identity-test", null);
+        Module testModule = result.findModules("duplicate-identity-test").iterator().next();
         Set<IdentitySchemaNode> identities = testModule.getIdentities();
         assertEquals(1, identities.size());
     }