From 13910f9b79d958138c9b8ce50cb0ca39355ac65d Mon Sep 17 00:00:00 2001 From: Lukas Sedlak Date: Tue, 15 Jul 2014 13:57:27 +0200 Subject: [PATCH] Bug 1355: Fixed incorrect input keyword use in rpc Fixed incorrect evaluation in method flattenInput in NetconfMessageTransformUtil. Added test for testing toRpcRequest and flattenInput methods. Added test model for test. Change-Id: Id6938b39f0bd06b315f4820a6c1008fa371416d0 Signed-off-by: Lukas Sedlak --- .../util/NetconfMessageTransformUtil.java | 2 +- .../netconf/NetconfToRpcRequestTest.java | 81 +++++++++++++++++++ .../rpc-notification-subscription.yang | 38 +++++++++ 3 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 opendaylight/md-sal/sal-netconf-connector/src/test/java/org/opendaylight/controller/sal/connect/netconf/NetconfToRpcRequestTest.java create mode 100644 opendaylight/md-sal/sal-netconf-connector/src/test/resources/schemas/rpc-notification-subscription.yang diff --git a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/util/NetconfMessageTransformUtil.java b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/util/NetconfMessageTransformUtil.java index 0ea3d6a35a..6d087a9cc3 100644 --- a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/util/NetconfMessageTransformUtil.java +++ b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/util/NetconfMessageTransformUtil.java @@ -181,7 +181,7 @@ public class NetconfMessageTransformUtil { .addAll(Collections2.filter(node.getValue(), new Predicate>() { @Override public boolean apply(@Nullable final Node input) { - return input.getNodeType() != inputQName; + return !inputQName.equals(input.getNodeType()); } })) // .build(); diff --git a/opendaylight/md-sal/sal-netconf-connector/src/test/java/org/opendaylight/controller/sal/connect/netconf/NetconfToRpcRequestTest.java b/opendaylight/md-sal/sal-netconf-connector/src/test/java/org/opendaylight/controller/sal/connect/netconf/NetconfToRpcRequestTest.java new file mode 100644 index 0000000000..18a3b9f0ff --- /dev/null +++ b/opendaylight/md-sal/sal-netconf-connector/src/test/java/org/opendaylight/controller/sal/connect/netconf/NetconfToRpcRequestTest.java @@ -0,0 +1,81 @@ +package org.opendaylight.controller.sal.connect.netconf; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNotNull; +import static junit.framework.Assert.assertTrue; + +import java.io.InputStream; +import java.util.Collections; +import java.util.List; +import java.util.Set; + +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.controller.netconf.api.NetconfMessage; +import org.opendaylight.controller.sal.connect.netconf.schema.mapping.NetconfMessageTransformer; +import org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.opendaylight.yangtools.yang.data.impl.ImmutableCompositeNode; +import org.opendaylight.yangtools.yang.data.impl.util.CompositeNodeBuilder; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser; +import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; + +/** + * Test case for reported bug 1355 + * + * @author Lukas Sedlak + * @see + */ +public class NetconfToRpcRequestTest { + + private String TEST_MODEL_NAMESPACE = "urn:opendaylight:params:xml:ns:yang:controller:md:sal:rpc-test"; + private String REVISION = "2014-07-14"; + private QName INPUT_QNAME = QName.create(TEST_MODEL_NAMESPACE, REVISION, "input"); + private QName STREAM_NAME = QName.create(TEST_MODEL_NAMESPACE, REVISION, "stream-name"); + private QName RPC_NAME = QName.create(TEST_MODEL_NAMESPACE, REVISION, "subscribe"); + + NetconfMessageTransformer messageTransformer; + + @SuppressWarnings("deprecation") + @Before + public void setup() throws Exception { + final List modelsToParse = Collections + .singletonList(getClass().getResourceAsStream("/schemas/rpc-notification-subscription.yang")); + final YangContextParser parser = new YangParserImpl(); + final Set modules = parser.parseYangModelsFromStreams(modelsToParse); + assertTrue(!modules.isEmpty()); + final SchemaContext schemaContext = parser.resolveSchemaContext(modules); + assertNotNull(schemaContext); + + messageTransformer = new NetconfMessageTransformer(); + messageTransformer.onGlobalContextUpdated(schemaContext); + } + + @Test + public void test() throws Exception { + final CompositeNodeBuilder rootBuilder = ImmutableCompositeNode.builder(); + rootBuilder.setQName(RPC_NAME); + + final CompositeNodeBuilder inputBuilder = ImmutableCompositeNode.builder(); + inputBuilder.setQName(INPUT_QNAME); + inputBuilder.addLeaf(STREAM_NAME, "NETCONF"); + + rootBuilder.add(inputBuilder.toInstance()); + final ImmutableCompositeNode root = rootBuilder.toInstance(); + + final CompositeNode flattenedNode = NetconfMessageTransformUtil.flattenInput(root); + assertNotNull(flattenedNode); + assertEquals(1, flattenedNode.size()); + + final List inputNode = flattenedNode.getCompositesByName(INPUT_QNAME); + assertNotNull(inputNode); + assertTrue(inputNode.isEmpty()); + + final NetconfMessage message = messageTransformer.toRpcRequest(RPC_NAME, root); + assertNotNull(message); + } +} diff --git a/opendaylight/md-sal/sal-netconf-connector/src/test/resources/schemas/rpc-notification-subscription.yang b/opendaylight/md-sal/sal-netconf-connector/src/test/resources/schemas/rpc-notification-subscription.yang new file mode 100644 index 0000000000..b13d90f202 --- /dev/null +++ b/opendaylight/md-sal/sal-netconf-connector/src/test/resources/schemas/rpc-notification-subscription.yang @@ -0,0 +1,38 @@ +module rpc-notification-subscription { + + namespace "urn:opendaylight:params:xml:ns:yang:controller:md:sal:rpc-test"; + prefix "rpc"; + + organization + "Cisco Systems, Inc."; + + contact + "lsedlak@cisco.com"; + + description + "Test model for testing of rpc INPUT parameter during subscription call."; + + revision 2014-07-14 { + description + "Initial revision."; + } + + rpc subscribe { + description + "Test rpc to init subscription"; + + input { + leaf stream-name { + type string; + default "NETCONF"; + description + "Optional stream name param."; + } + + anyxml data { + description + "Optional additional data."; + } + } + } +} \ No newline at end of file -- 2.36.6