NETCONF-540: ignore namespace prefix when sending error rpc-reply 16/71416/1
authorMarek Gradzki <mgradzki@cisco.com>
Fri, 20 Apr 2018 05:57:38 +0000 (07:57 +0200)
committerMarek Gradzki <mgradzki@cisco.com>
Thu, 26 Apr 2018 11:41:41 +0000 (13:41 +0200)
Change-Id: I29bfa55e6ac043be6306b8da026ae5228ec9344e
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/SendErrorExceptionUtil.java
netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/messages/SendErrorExceptionUtilTest.java
netconf/netconf-util/src/test/resources/netconfMessages/rpc_ns.xml [new file with mode: 0644]

index 4768fad00ecea66354528281f700e8ff74f3afe5..159fb34ddb56d2c065b2e345b2e6c5a2f2e273d5 100644 (file)
@@ -62,7 +62,7 @@ public final class SendErrorExceptionUtil {
             final DocumentedException sendErrorException) {
         try {
             final Element incommingRpc = incommingDocument.getDocumentElement();
-            Preconditions.checkState(incommingRpc.getTagName().equals(XmlNetconfConstants.RPC_KEY),
+            Preconditions.checkState(incommingRpc.getLocalName().equals(XmlNetconfConstants.RPC_KEY),
                     "Missing %s element", XmlNetconfConstants.RPC_KEY);
 
             final Element rpcReply = errorDocument.getDocumentElement();
index 4109756949ed4d1009fac4a7fe3967ead7a316c6..14973a2c5ab50fe370568fa20c482b8c5cbea93b 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.netconf.util.messages;
 
+import static org.junit.Assert.assertEquals;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
@@ -19,11 +20,13 @@ import io.netty.channel.ChannelFuture;
 import io.netty.util.concurrent.GenericFutureListener;
 import org.junit.Before;
 import org.junit.Test;
+import org.mockito.ArgumentCaptor;
 import org.opendaylight.controller.config.util.xml.DocumentedException;
 import org.opendaylight.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.api.NetconfSession;
 import org.opendaylight.netconf.util.test.XmlFileLoader;
 import org.w3c.dom.Document;
+import org.w3c.dom.Element;
 
 public class SendErrorExceptionUtilTest {
 
@@ -62,4 +65,15 @@ public class SendErrorExceptionUtilTest {
         SendErrorExceptionUtil.sendErrorMessage(netconfSession, exception, new NetconfMessage(helloMessage));
         verify(channelFuture, times(1)).addListener(any(GenericFutureListener.class));
     }
+
+    @Test
+    public void testSendErrorMessage4() throws Exception {
+        Document helloMessage = XmlFileLoader.xmlFileToDocument("netconfMessages/rpc_ns.xml");
+        SendErrorExceptionUtil.sendErrorMessage(netconfSession, exception, new NetconfMessage(helloMessage));
+        final ArgumentCaptor<NetconfMessage> messageCaptor = ArgumentCaptor.forClass(NetconfMessage.class);
+        verify(netconfSession, times(1)).sendMessage(messageCaptor.capture());
+        final Element rpcReply = messageCaptor.getValue().getDocument().getDocumentElement();
+        assertEquals("Invalid value of message-id attribute in the reply message", "a",
+            rpcReply.getAttribute("message-id"));
+    }
 }
diff --git a/netconf/netconf-util/src/test/resources/netconfMessages/rpc_ns.xml b/netconf/netconf-util/src/test/resources/netconfMessages/rpc_ns.xml
new file mode 100644 (file)
index 0000000..67f5722
--- /dev/null
@@ -0,0 +1,8 @@
+<nc:rpc message-id="a" a="64" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
+    <no-arg xmlns="urn:opendaylight:params:xml:ns:yang:controller:test:impl">
+        <context-instance>/modules/module[type='impl-netconf' and name='instance-from-code']</context-instance>
+        <arg1>
+            testarg1
+        </arg1>
+    </no-arg>
+</nc:rpc>