Adjust test suite parser update to conform with API changes
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / MustAndWhenStmtTest.java
index f6094cb8a4f39a1d41df652977252d0a03bab5ae..aef2927745a9fb38f610d66be8fc973b00bb773b 100644 (file)
@@ -14,73 +14,70 @@ 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.Collection;
 import java.util.Iterator;
-import java.util.Set;
+import java.util.Optional;
 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.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-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);
-
     @Test
     public void mustStmtTest() throws ReactorException {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        StmtTestUtils.addSources(reactor, MUST_MODULE);
-
-        final EffectiveSchemaContext result = reactor.buildEffective();
+        final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
+                .addSource(sourceForResource("/must-when-stmt-test/must-test.yang"))
+                .buildEffective();
         assertNotNull(result);
 
-        final Module testModule = result.findModuleByName("must-test", null);
+        final Module testModule = result.findModules("must-test").iterator().next();
         assertNotNull(testModule);
 
-        final ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName(QName.create(testModule.getQNameModule(), "interface"));
+        final ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName(
+            QName.create(testModule.getQNameModule(), "interface"));
         assertNotNull(container);
         assertTrue(container.isPresenceContainer());
 
-        final Set<MustDefinition> musts = container.getConstraints().getMustConstraints();
+        final Collection<MustDefinition> musts = container.getMustConstraints();
         assertEquals(2, musts.size());
 
         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)")));
-        assertThat(mustStmt.getErrorMessage(), anyOf(is("An ethernet MTU must be 1500"), is("An atm MTU must be 64 " +
-                ".. 17966")));
-        assertThat(mustStmt.getErrorAppTag(), anyOf(is("An ethernet error"), is("An atm error")));
+        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)")));
+        assertThat(mustStmt.getErrorMessage(), anyOf(is(Optional.of("An ethernet MTU must be 1500")),
+            is(Optional.of("An atm MTU must be 64 .. 17966"))));
+        assertThat(mustStmt.getErrorAppTag(), anyOf(is(Optional.of("An ethernet error")),
+            is(Optional.of("An atm error"))));
         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)")));
-        assertThat(mustStmt.getErrorMessage(), anyOf(is("An ethernet MTU must be 1500"), is("An atm MTU must be 64 " +
-                ".. 17966")));
-        assertThat(mustStmt.getErrorAppTag(), anyOf(is("An ethernet error"), is("An atm error")));
+        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)")));
+        assertThat(mustStmt.getErrorMessage(), anyOf(is(Optional.of("An ethernet MTU must be 1500")),
+            is(Optional.of("An atm MTU must be 64 .. 17966"))));
+        assertThat(mustStmt.getErrorAppTag(), anyOf(is(Optional.of("An ethernet error")),
+            is(Optional.of("An atm error"))));
     }
 
     @Test
     public void whenStmtTest() throws ReactorException {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        StmtTestUtils.addSources(reactor, WHEN_MODULE);
-
-        final EffectiveSchemaContext result = reactor.buildEffective();
+        final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
+                .addSource(sourceForResource("/must-when-stmt-test/when-test.yang"))
+                .buildEffective();
         assertNotNull(result);
 
-        final Module testModule = result.findModuleByName("when-test", null);
+        final Module testModule = result.findModules("when-test").iterator().next();
         assertNotNull(testModule);
 
-        final ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName(QName.create(testModule.getQNameModule(), "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());
+        assertEquals("conditional-leaf = 'autumn-leaf'", container.getWhenCondition().get().toString());
     }
 }