import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.toId;
import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.toPath;
-import com.google.common.collect.Lists;
-import java.io.InputStream;
-import java.util.Collections;
-import java.util.List;
import java.util.Set;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.opendaylight.controller.config.util.xml.XmlUtil;
import org.opendaylight.netconf.api.NetconfMessage;
+import org.opendaylight.netconf.api.xml.XmlUtil;
import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-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.test.util.YangParserTestUtils;
import org.w3c.dom.Document;
public class NetconfToRpcRequestTest {
- private final static String TEST_MODEL_NAMESPACE = "urn:opendaylight:params:xml:ns:yang:controller:md:sal:rpc-test";
- private final static String REVISION = "2014-07-14";
- private final static QName INPUT_QNAME = QName.create(TEST_MODEL_NAMESPACE, REVISION, "input");
- private final static QName STREAM_NAME = QName.create(TEST_MODEL_NAMESPACE, REVISION, "stream-name");
- private final static QName SUBSCRIBE_RPC_NAME = QName.create(TEST_MODEL_NAMESPACE, REVISION, "subscribe");
-
- private final static String CONFIG_TEST_NAMESPACE = "urn:opendaylight:params:xml:ns:yang:controller:md:sal:test:rpc:config:defs";
- private final static String CONFIG_TEST_REVISION = "2014-07-21";
- private final static QName EDIT_CONFIG_QNAME = QName.create(CONFIG_TEST_NAMESPACE, CONFIG_TEST_REVISION, "edit-config");
- private final static QName GET_QNAME = QName.create(CONFIG_TEST_NAMESPACE, CONFIG_TEST_REVISION, "get");
- private final static QName GET_CONFIG_QNAME = QName.create(CONFIG_TEST_NAMESPACE, CONFIG_TEST_REVISION, "get-config");
+ private static final String TEST_MODEL_NAMESPACE = "urn:opendaylight:params:xml:ns:yang:controller:md:sal:rpc-test";
+ private static final String REVISION = "2014-07-14";
+ private static final QName INPUT_QNAME = QName.create(TEST_MODEL_NAMESPACE, REVISION, "input");
+ private static final QName STREAM_NAME = QName.create(TEST_MODEL_NAMESPACE, REVISION, "stream-name");
+ private static final QName SUBSCRIBE_RPC_NAME = QName.create(TEST_MODEL_NAMESPACE, REVISION, "subscribe");
+
+ private static final String CONFIG_TEST_NAMESPACE =
+ "urn:opendaylight:params:xml:ns:yang:controller:md:sal:test:rpc:config:defs";
+ private static final String CONFIG_TEST_REVISION = "2014-07-21";
+ private static final QName EDIT_CONFIG_QNAME =
+ QName.create(CONFIG_TEST_NAMESPACE, CONFIG_TEST_REVISION, "edit-config");
+ private static final QName GET_QNAME = QName.create(CONFIG_TEST_NAMESPACE, CONFIG_TEST_REVISION, "get");
+ private static final QName GET_CONFIG_QNAME =
+ QName.create(CONFIG_TEST_NAMESPACE, CONFIG_TEST_REVISION, "get-config");
static SchemaContext cfgCtx;
static NetconfMessageTransformer messageTransformer;
@BeforeClass
- public static void setup() throws Exception {
- List<InputStream> modelsToParse = Collections
- .singletonList(NetconfToRpcRequestTest.class.getResourceAsStream("/schemas/rpc-notification-subscription.yang"));
- final Set<Module> notifModules = parseYangStreams(modelsToParse).getModules();
+ public static void setup() {
+ final Set<Module> notifModules = YangParserTestUtils.parseYangResource(
+ "/schemas/rpc-notification-subscription.yang").getModules();
assertTrue(!notifModules.isEmpty());
- modelsToParse = Lists.newArrayList(
- NetconfToRpcRequestTest.class.getResourceAsStream("/schemas/config-test-rpc.yang"),
- NetconfToRpcRequestTest.class.getResourceAsStream("/schemas/rpc-notification-subscription.yang"));
- cfgCtx = parseYangStreams(modelsToParse);
+ cfgCtx = YangParserTestUtils.parseYangResources(NetconfToRpcRequestTest.class,
+ "/schemas/config-test-rpc.yang", "/schemas/rpc-notification-subscription.yang");
messageTransformer = new NetconfMessageTransformer(cfgCtx, true);
}
- private static SchemaContext parseYangStreams(final List<InputStream> streams) {
- CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
- .newBuild();
- final SchemaContext schemaContext;
- try {
- schemaContext = reactor.buildEffective(streams);
- } catch (ReactorException e) {
- throw new RuntimeException("Unable to build schema context from " + streams, e);
- }
- return schemaContext;
- }
-
private static LeafNode<Object> buildLeaf(final QName running, final Object value) {
return Builders.leafBuilder().withNodeIdentifier(toId(running)).withValue(value).build();
}
@Test
public void testUserDefinedRpcCall() throws Exception {
- final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> rootBuilder = Builders.containerBuilder();
+ final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> rootBuilder =
+ Builders.containerBuilder();
rootBuilder.withNodeIdentifier(toId(SUBSCRIBE_RPC_NAME));
rootBuilder.withChild(buildLeaf(STREAM_NAME, "NETCONF"));
@Test(expected = IllegalArgumentException.class)
public void testRpcResponse() throws Exception {
final NetconfMessage response = new NetconfMessage(XmlUtil.readXmlToDocument(
- "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"m-5\">\n" +
- "<data xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">" +
- "module schema" +
- "</data>\n" +
- "</rpc-reply>\n"
+ "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"m-5\">\n"
+ + "<data xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">"
+ + "module schema"
+ + "</data>\n"
+ + "</rpc-reply>\n"
));
messageTransformer.toRpcResult(response, toPath(EDIT_CONFIG_QNAME));