Do not use null input for discard-changes 25/103725/2
authorSangwook Ha <sangwook.ha@verizon.com>
Wed, 21 Dec 2022 18:27:10 +0000 (10:27 -0800)
committerRobert Varga <nite@hq.sk>
Sat, 31 Dec 2022 14:56:08 +0000 (14:56 +0000)
There is already a NormalizedNode defined in NetconfMessageTransformUtil
for the content of the 'discard-changes' RPC.

Use the static variable instead of 'null'. This would make message
transformation more robust and fix an error caused by an augmentation
to the RPC input while generating NetconfMessage.

JIRA: NETCONF-934
Change-Id: I38777313d74e92bd955248ceea78e765729d9259
Signed-off-by: Sangwook Ha <sangwook.ha@verizon.com>
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/util/NetconfBaseOps.java
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDataTreeServiceImplTest.java
netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/tx/NetconfDeviceWriteOnlyTxTest.java

index d55b0ebc4a84f0460194ae5cf68713b9e5699dee..af09e9f575a8cb735f379608b570ae43639c3645 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.netconf.sal.connect.netconf.util;
 import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Objects.requireNonNull;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.COMMIT_RPC_CONTENT;
+import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.DISCARD_CHANGES_RPC_CONTENT;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.EDIT_CONTENT_NODEID;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.GET_RPC_CONTENT;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_CANDIDATE_NODEID;
@@ -133,8 +134,8 @@ public final class NetconfBaseOps {
     }
 
     public ListenableFuture<? extends DOMRpcResult> discardChanges(final FutureCallback<DOMRpcResult> callback) {
-        // FIXME: eliminate null
-        return addCallback(requireNonNull(callback), rpc.invokeNetconf(NETCONF_DISCARD_CHANGES_QNAME, null));
+        return addCallback(requireNonNull(callback), rpc.invokeNetconf(NETCONF_DISCARD_CHANGES_QNAME,
+            DISCARD_CHANGES_RPC_CONTENT));
     }
 
     public ListenableFuture<? extends DOMRpcResult> commit(final FutureCallback<DOMRpcResult> callback) {
index 03b3471ef859309609bdae5479f4a2c184430a36..89f54e85d8a7b0c9113320069749e6cf94991581 100644 (file)
@@ -11,7 +11,6 @@ import static org.hamcrest.CoreMatchers.containsString;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.ArgumentMatchers.isNull;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.verify;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_COMMIT_QNAME;
@@ -83,9 +82,8 @@ public class NetconfDataTreeServiceImplTest extends AbstractTestModelTest {
 
     @Test
     public void discardChanges() {
-        doReturn(Futures.immediateFuture(new DefaultDOMRpcResult())).when(rpcService).invokeNetconf(any(), isNull());
         netconService.discardChanges();
-        verify(rpcService).invokeNetconf(eq(NETCONF_DISCARD_CHANGES_QNAME), isNull());
+        verify(rpcService).invokeNetconf(eq(NETCONF_DISCARD_CHANGES_QNAME), any());
     }
 
     @Test
@@ -166,4 +164,4 @@ public class NetconfDataTreeServiceImplTest extends AbstractTestModelTest {
                 new RemoteDeviceId("device-1", InetSocketAddress.createUnresolved("localhost", 17830));
         return AbstractNetconfDataTreeService.of(id, new EmptyMountPointContext(SCHEMA_CONTEXT), rpcService, prefs);
     }
-}
\ No newline at end of file
+}
index 778a178fae1bd72423043911dfe327bbe92af78e..34fd21ba7fd7f1c71e11caa14ca2ddcbe764204f 100644 (file)
@@ -10,13 +10,13 @@ package org.opendaylight.netconf.sal.connect.netconf.sal.tx;
 import static org.junit.Assert.assertThrows;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.ArgumentMatchers.isNull;
 import static org.mockito.Mockito.atMost;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.inOrder;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
+import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.DISCARD_CHANGES_RPC_CONTENT;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_CANDIDATE_NODEID;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_FILTER_QNAME;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_RUNNING_NODEID;
@@ -88,9 +88,6 @@ public class NetconfDeviceWriteOnlyTxTest extends AbstractBaseSchemasTest {
 
     @Test
     public void testDiscardChanges() {
-        doReturn(Futures.immediateFuture(new DefaultDOMRpcResult((ContainerNode) null)))
-                .when(rpc).invokeNetconf(any(), isNull());
-
         final var future = new WriteCandidateTx(id, new NetconfBaseOps(rpc, mock(MountPointContext.class)), false)
             .commit();
         assertThrows(ExecutionException.class, () -> Futures.getDone(future));
@@ -101,8 +98,8 @@ public class NetconfDeviceWriteOnlyTxTest extends AbstractBaseSchemasTest {
             NetconfBaseOps.getLockContent(NETCONF_CANDIDATE_NODEID));
         inOrder.verify(rpc).invokeNetconf(NetconfMessageTransformUtil.NETCONF_COMMIT_QNAME,
             NetconfMessageTransformUtil.COMMIT_RPC_CONTENT);
-        inOrder.verify(rpc).invokeNetconf(eq(NetconfMessageTransformUtil.NETCONF_DISCARD_CHANGES_QNAME),
-            isNull());
+        inOrder.verify(rpc).invokeNetconf(NetconfMessageTransformUtil.NETCONF_DISCARD_CHANGES_QNAME,
+            DISCARD_CHANGES_RPC_CONTENT);
         inOrder.verify(rpc).invokeNetconf(NetconfMessageTransformUtil.NETCONF_UNLOCK_QNAME,
             NetconfBaseOps.getUnLockContent(NETCONF_CANDIDATE_NODEID));
     }
@@ -157,8 +154,6 @@ public class NetconfDeviceWriteOnlyTxTest extends AbstractBaseSchemasTest {
 
     @Test
     public void testListenerCancellation() throws Exception {
-        doReturn(Futures.immediateFuture(new DefaultDOMRpcResult((ContainerNode) null)))
-                .when(rpc).invokeNetconf(any(), isNull());
         final WriteCandidateTx tx = new WriteCandidateTx(
                 id, new NetconfBaseOps(rpc, BASE_SCHEMAS.getBaseSchema().getMountPointContext()), false);
         final TxListener listener = mock(TxListener.class);