2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.yangtools.yang.stmt.test;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
16 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.Module;
18 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
20 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
21 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
22 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
23 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
25 public class RpcStmtTest {
27 private static final YangStatementSourceImpl RPC_MODULE = new YangStatementSourceImpl("/model/baz.yang", false);
28 private static final YangStatementSourceImpl IMPORTED_MODULE = new YangStatementSourceImpl("/model/bar.yang",
32 public void rpcTest() throws ReactorException {
33 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
34 StmtTestUtils.addSources(reactor, RPC_MODULE, IMPORTED_MODULE);
36 EffectiveSchemaContext result = reactor.buildEffective();
37 assertNotNull(result);
39 Module testModule = result.findModuleByName("baz", null);
40 assertNotNull(testModule);
42 assertEquals(1, testModule.getRpcs().size());
44 RpcDefinition rpc = testModule.getRpcs().iterator().next();
45 assertEquals("get-config", rpc.getQName().getLocalName());
47 ContainerSchemaNode input = rpc.getInput();
49 assertEquals(2, input.getChildNodes().size());
51 ContainerSchemaNode container = (ContainerSchemaNode) input.getDataChildByName("source");
52 assertNotNull(container);
53 AnyXmlSchemaNode anyXml = (AnyXmlSchemaNode) input.getDataChildByName("filter");
54 assertNotNull(anyXml);
56 ContainerSchemaNode output = rpc.getOutput();
57 assertNotNull(output);
58 assertEquals(1, output.getChildNodes().size());
60 anyXml = (AnyXmlSchemaNode) output.getDataChildByName("data");
61 assertNotNull(anyXml);