Adjust test suite parser update to conform with API changes
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / RpcStmtTest.java
index 85e09a6fe2c9ec2c4b3c434d53a99ab1bf7bf594..cffdeabe5276ce1be2247bdf5c981efe15387f58 100644 (file)
@@ -15,38 +15,32 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
 
-import java.text.ParseException;
 import java.util.Set;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
+import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
 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.effective.EffectiveSchemaContext;
 
 public class RpcStmtTest {
 
-    private static final StatementStreamSource RPC_MODULE = sourceForResource("/model/baz.yang");
-    private static final StatementStreamSource IMPORTED_MODULE = sourceForResource("/model/bar.yang");
-    private static final StatementStreamSource FOO_MODULE = sourceForResource("/rpc-stmt-test/foo.yang");
-
     @Test
-    public void rpcTest() throws ReactorException, ParseException {
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
-        reactor.addSources(RPC_MODULE, IMPORTED_MODULE, FOO_MODULE);
-
-        final EffectiveSchemaContext result = reactor.buildEffective();
+    public void rpcTest() throws ReactorException {
+        final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
+                .addSource(sourceForResource("/model/baz.yang"))
+                .addSource(sourceForResource("/model/bar.yang"))
+                .addSource(sourceForResource("/rpc-stmt-test/foo.yang"))
+                .buildEffective();
         assertNotNull(result);
 
-        final Module testModule = result.findModuleByName("baz", null);
-        assertNotNull(testModule);
-
+        final Module testModule = result.findModules("baz").iterator().next();
         assertEquals(1, testModule.getRpcs().size());
 
         final RpcDefinition rpc = testModule.getRpcs().iterator().next();
@@ -56,9 +50,11 @@ public class RpcStmtTest {
         assertNotNull(input);
         assertEquals(2, input.getChildNodes().size());
 
-        final ContainerSchemaNode container = (ContainerSchemaNode) input.getDataChildByName(QName.create(testModule.getQNameModule(), "source"));
+        final ContainerSchemaNode container = (ContainerSchemaNode) input.getDataChildByName(
+            QName.create(testModule.getQNameModule(), "source"));
         assertNotNull(container);
-        AnyXmlSchemaNode anyXml = (AnyXmlSchemaNode) input.getDataChildByName(QName.create(testModule.getQNameModule(), "filter"));
+        AnyXmlSchemaNode anyXml = (AnyXmlSchemaNode) input.getDataChildByName(
+            QName.create(testModule.getQNameModule(), "filter"));
         assertNotNull(anyXml);
 
         final ContainerSchemaNode output = rpc.getOutput();
@@ -68,9 +64,7 @@ public class RpcStmtTest {
         anyXml = (AnyXmlSchemaNode) output.getDataChildByName(QName.create(testModule.getQNameModule(), "data"));
         assertNotNull(anyXml);
 
-        final Module fooModule = result.findModuleByName("foo", SimpleDateFormatUtil.getRevisionFormat().parse("2016-09-23"));
-        assertNotNull(fooModule);
-
+        final Module fooModule = result.findModule("foo", Revision.of("2016-09-23")).get();
         final Set<RpcDefinition> rpcs = fooModule.getRpcs();
         assertEquals(2, rpcs.size());
 
@@ -102,4 +96,26 @@ public class RpcStmtTest {
         assertFalse(fooRpc1.getOutput().equals("str"));
         assertFalse(fooRpc1.getOutput().equals(fooRpc2.getOutput()));
     }
+
+    @Test
+    public void testImplicitInputAndOutput() throws Exception {
+        final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rpc-stmt-test/bar.yang");
+        assertNotNull(schemaContext);
+
+        final Module barModule = schemaContext.findModule("bar", Revision.of("2016-11-25")).get();
+        final Set<RpcDefinition> rpcs = barModule.getRpcs();
+        assertEquals(1, rpcs.size());
+
+        final RpcDefinition barRpc = rpcs.iterator().next();
+
+        final ContainerSchemaNode input = barRpc.getInput();
+        assertNotNull(input);
+        assertEquals(2, input.getChildNodes().size());
+        assertEquals(StatementSource.CONTEXT, ((EffectiveStatement<?, ?>) input).getDeclared().getStatementSource());
+
+        final ContainerSchemaNode output = barRpc.getOutput();
+        assertNotNull(output);
+        assertEquals(2, output.getChildNodes().size());
+        assertEquals(StatementSource.CONTEXT, ((EffectiveStatement<?, ?>) output).getDeclared().getStatementSource());
+    }
 }