Update StmtTestUtils
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / MustAndWhenStmtTest.java
index 63d51c1afa943c93386529dcd8f376efc685f5ad..9a48f25f56b7c75c7bb2913af48503b8630fd07e 100644 (file)
@@ -14,45 +14,45 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
+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.common.QName;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.MustDefinition;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+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 MustAndWhenStmtTest {
 
-    private static final YangStatementSourceImpl MUST_MODULE = new YangStatementSourceImpl
-            ("/must-when-stmt-test/must-test.yang", false);
-    private static final YangStatementSourceImpl WHEN_MODULE = new YangStatementSourceImpl("/must-when-stmt-test/" +
-            "when-test.yang", false);
+    private static final StatementStreamSource MUST_MODULE = sourceForResource("/must-when-stmt-test/must-test.yang");
+    private static final StatementStreamSource WHEN_MODULE = sourceForResource("/must-when-stmt-test/when-test.yang");
 
     @Test
     public void mustStmtTest() throws ReactorException {
-        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        StmtTestUtils.addSources(reactor, MUST_MODULE);
+        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+        reactor.addSources(MUST_MODULE);
 
-        EffectiveSchemaContext result = reactor.buildEffective();
+        final EffectiveSchemaContext result = reactor.buildEffective();
         assertNotNull(result);
 
-        Module testModule = result.findModuleByName("must-test", null);
+        final Module testModule = result.findModuleByName("must-test", null);
         assertNotNull(testModule);
 
-        ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName("interface");
+        final ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName(QName.create(testModule.getQNameModule(), "interface"));
         assertNotNull(container);
         assertTrue(container.isPresenceContainer());
 
-        Set<MustDefinition> musts = container.getConstraints().getMustConstraints();
+        final Set<MustDefinition> musts = container.getConstraints().getMustConstraints();
         assertEquals(2, musts.size());
 
-        Iterator<MustDefinition> mustsIterator = musts.iterator();
+        final Iterator<MustDefinition> mustsIterator = musts.iterator();
         MustDefinition mustStmt = mustsIterator.next();
         assertThat(mustStmt.getXpath().toString(), anyOf(is("ifType != 'ethernet' or (ifType = 'ethernet' and " +
                 "ifMTU = 1500)"), is("ifType != 'atm' or (ifType = 'atm' and ifMTU <= 17966 and ifMTU >= 64)")));
@@ -69,16 +69,16 @@ public class MustAndWhenStmtTest {
 
     @Test
     public void whenStmtTest() throws ReactorException {
-        CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        StmtTestUtils.addSources(reactor, WHEN_MODULE);
+        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+        reactor.addSources(WHEN_MODULE);
 
-        EffectiveSchemaContext result = reactor.buildEffective();
+        final EffectiveSchemaContext result = reactor.buildEffective();
         assertNotNull(result);
 
-        Module testModule = result.findModuleByName("when-test", null);
+        final Module testModule = result.findModuleByName("when-test", null);
         assertNotNull(testModule);
 
-        ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName("test-container");
+        final ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName(QName.create(testModule.getQNameModule(), "test-container"));
         assertNotNull(container);
         assertEquals("conditional-leaf = 'autumn-leaf'", container.getConstraints().getWhenCondition().toString());
     }