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();
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();
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());
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());
+ }
}