Fix xml->CompositeNode transformation for rpc replies for rpcs with no output 90/10690/2
authorMaros Marsalek <mmarsale@cisco.com>
Wed, 3 Sep 2014 12:47:52 +0000 (14:47 +0200)
committerMaros Marsalek <mmarsale@cisco.com>
Wed, 3 Sep 2014 14:59:20 +0000 (16:59 +0200)
Change-Id: I9bcc884306478d974aa0547056cb70d4258c786e
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlDocumentUtils.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlDocumentUtilsTest.java

index f0d82c33b9829ee97e85d063c2fcff0b40a27a94..68fc432e96952789b42d8164e7e25d39b347b138 100644 (file)
@@ -432,14 +432,15 @@ public class XmlDocumentUtils {
         if (rpcDefinition.isPresent()) {
             RpcDefinition rpc = rpcDefinition.get();
 
-            final Collection<DataSchemaNode> outputNode = rpc.getOutput().getChildNodes();
+            final Collection<DataSchemaNode> outputNode = rpc.getOutput() != null ? rpc.getOutput().getChildNodes() : null;
             final Element rpcReplyElement = document.getDocumentElement();
             final QName partialQName = qNameFromElement(rpcReplyElement);
 
             if (RPC_REPLY_QNAME.equals(partialQName)) {
                 final List<Node<?>> domNodes = toDomNodes(rpcReplyElement, Optional.fromNullable(outputNode), context);
+                QName qName = rpc.getOutput() != null ? rpc.getOutput().getQName() : QName.cachedReference(QName.create(rpcName, "output"));
                 List<Node<?>> rpcOutNodes = Collections.<Node<?>>singletonList(ImmutableCompositeNode.create(
-                        rpc.getOutput().getQName(), domNodes));
+                        qName, domNodes));
                 return ImmutableCompositeNode.create(rpcName, rpcOutNodes);
             }
         }
index b716c8cbe7d605b3dba073d15309752f00ead2f7..e93a5704d5d1914810a612d53505f044819af632 100644 (file)
@@ -9,25 +9,25 @@
 package org.opendaylight.yangtools.yang.data.impl.codec.xml;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 import com.google.common.base.Charsets;
 import com.google.common.base.Optional;
 import com.google.common.collect.Lists;
 import com.google.common.io.ByteSource;
-
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-
 import javax.activation.UnsupportedDataTypeException;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
-
 import org.custommonkey.xmlunit.XMLUnit;
 import org.junit.Before;
 import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+import org.opendaylight.yangtools.yang.data.api.Node;
 import org.opendaylight.yangtools.yang.data.api.SimpleNode;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
@@ -57,6 +57,10 @@ public class XmlDocumentUtilsTest {
             "<ref xmlns:ltha=\"urn:opendaylight:controller:rpc:test\">/ltha:cont/ltha:l[ltha:id='id']</ref>\n" +
             "</input>";
 
+    public static final String RPC_REPLY = "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"m-1\">\n" +
+            " <ok/>\n" +
+            "</rpc-reply>";
+
     private SchemaContext schema;
     private RpcDefinition testRpc;
 
@@ -87,6 +91,18 @@ public class XmlDocumentUtilsTest {
         XMLUnit.compareXML(inputDocument, serializedDocument);
     }
 
+    @Test
+    public void testRpcReplyToDom() throws Exception {
+        final Document reply = readXmlToDocument(RPC_REPLY);
+        final CompositeNode domNodes = XmlDocumentUtils.rpcReplyToDomNodes(reply, QName.create("urn:opendaylight:controller:rpc:test", "2014-07-28", "test"), schema);
+        assertEquals(1, domNodes.getValue().size());
+        final Node<?> outputNode = domNodes.getValue().get(0);
+        assertTrue(outputNode instanceof CompositeNode);
+        assertEquals(1, ((CompositeNode) outputNode).getValue().size());
+        final Node<?> okNode = ((CompositeNode) outputNode).getValue().get(0);
+        assertEquals("ok", okNode.getNodeType().getLocalName());
+    }
+
     public static Document readXmlToDocument(final String xmlContent) throws SAXException, IOException {
         return readXmlToDocument(new ByteArrayInputStream(xmlContent.getBytes(Charsets.UTF_8)));
     }