Partially revert "Adjust for RPCService methods changing"
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / test / java / org / opendaylight / controller / remote / rpc / RemoteOpsImplementationTest.java
index f2aeb2b0674d06e62e4f77dcc75c7319d4f92192..47ce52bf9c21625a9100070747b2da19c5ef1d08 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.controller.remote.rpc;
 
 import static org.junit.Assert.assertEquals;
@@ -33,6 +32,7 @@ import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
 import org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult;
 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 
 /**
@@ -50,8 +50,10 @@ public class RemoteOpsImplementationTest extends AbstractOpsTest {
         final ContainerNode rpcOutput = makeRPCOutput("bar");
         final DOMRpcResult rpcResult = new DefaultDOMRpcResult(rpcOutput);
 
-        final ContainerNode invokeRpcInput = makeRPCInput("foo");
-        final ArgumentCaptor<ContainerNode> inputCaptor = ArgumentCaptor.forClass(ContainerNode.class);
+        final NormalizedNode<?, ?> invokeRpcInput = makeRPCInput("foo");
+        @SuppressWarnings({"unchecked", "rawtypes"})
+        final ArgumentCaptor<NormalizedNode<?, ?>> inputCaptor =
+                ArgumentCaptor.forClass(NormalizedNode.class);
 
         doReturn(FluentFutures.immediateFluentFuture(rpcResult)).when(domRpcService2)
             .invokeRpc(eq(TEST_RPC_TYPE), inputCaptor.capture());
@@ -70,18 +72,42 @@ public class RemoteOpsImplementationTest extends AbstractOpsTest {
     public void testInvokeAction() throws Exception {
         final ContainerNode actionOutput = makeRPCOutput("bar");
         final DOMActionResult actionResult = new SimpleDOMActionResult(actionOutput, Collections.emptyList());
-        final ContainerNode invokeActionInput = makeRPCInput("foo");
-        final ArgumentCaptor<ContainerNode> inputCaptor = ArgumentCaptor.forClass(ContainerNode.class);
+        final NormalizedNode<?, ?> invokeActionInput = makeRPCInput("foo");
+        @SuppressWarnings({"unchecked", "rawtypes"})
+        final ArgumentCaptor<ContainerNode> inputCaptor =
+                ArgumentCaptor.forClass(ContainerNode.class);
         doReturn(FluentFutures.immediateFluentFuture(actionResult)).when(domActionService2).invokeAction(
                 eq(TEST_RPC_TYPE), eq(TEST_DATA_TREE_ID), inputCaptor.capture());
         final ListenableFuture<DOMActionResult> frontEndFuture = remoteActionImpl1.invokeAction(TEST_RPC_TYPE,
-                TEST_DATA_TREE_ID, invokeActionInput);
+                TEST_DATA_TREE_ID, (ContainerNode) invokeActionInput);
         assertTrue(frontEndFuture instanceof RemoteDOMActionFuture);
         final DOMActionResult result = frontEndFuture.get(5, TimeUnit.SECONDS);
         assertEquals(actionOutput, result.getOutput().get());
 
     }
 
+    /**
+     * This test method invokes and executes the remote rpc.
+     */
+    @Test
+    public void testInvokeRpcWithNullInput() throws Exception {
+        final ContainerNode rpcOutput = makeRPCOutput("bar");
+        final DOMRpcResult rpcResult = new DefaultDOMRpcResult(rpcOutput);
+
+        @SuppressWarnings({"unchecked", "rawtypes"})
+        final ArgumentCaptor<NormalizedNode<?, ?>> inputCaptor =
+                (ArgumentCaptor) ArgumentCaptor.forClass(NormalizedNode.class);
+
+        doReturn(FluentFutures.immediateFluentFuture(rpcResult)).when(domRpcService2)
+            .invokeRpc(eq(TEST_RPC_TYPE), inputCaptor.capture());
+
+        ListenableFuture<DOMRpcResult> frontEndFuture = remoteRpcImpl1.invokeRpc(TEST_RPC_ID, null);
+        assertTrue(frontEndFuture instanceof RemoteDOMRpcFuture);
+
+        final DOMRpcResult result = frontEndFuture.get(5, TimeUnit.SECONDS);
+        assertEquals(rpcOutput, result.getResult());
+    }
+
     /**
      * This test method invokes and executes the remote action.
      */
@@ -90,7 +116,9 @@ public class RemoteOpsImplementationTest extends AbstractOpsTest {
         final ContainerNode actionOutput = makeRPCOutput("bar");
         final DOMActionResult actionResult = new SimpleDOMActionResult(actionOutput);
 
-        final ArgumentCaptor<ContainerNode> inputCaptor = ArgumentCaptor.forClass(ContainerNode.class);
+        @SuppressWarnings({"unchecked", "rawtypes"})
+            final ArgumentCaptor<ContainerNode> inputCaptor =
+                  ArgumentCaptor.forClass(ContainerNode.class);
         doReturn(FluentFutures.immediateFluentFuture(actionResult)).when(domActionService2).invokeAction(
                 eq(TEST_RPC_TYPE), eq(TEST_DATA_TREE_ID), inputCaptor.capture());
 
@@ -110,8 +138,10 @@ public class RemoteOpsImplementationTest extends AbstractOpsTest {
         final ContainerNode rpcOutput = null;
         final DOMRpcResult rpcResult = new DefaultDOMRpcResult(rpcOutput);
 
-        final ContainerNode invokeRpcInput = makeRPCInput("foo");
-        final ArgumentCaptor<ContainerNode> inputCaptor = ArgumentCaptor.forClass(ContainerNode.class);
+        final NormalizedNode<?, ?> invokeRpcInput = makeRPCInput("foo");
+        @SuppressWarnings({"unchecked", "rawtypes"})
+        final ArgumentCaptor<NormalizedNode<?, ?>> inputCaptor =
+                (ArgumentCaptor) ArgumentCaptor.forClass(NormalizedNode.class);
 
         doReturn(FluentFutures.immediateFluentFuture(rpcResult)).when(domRpcService2)
             .invokeRpc(eq(TEST_RPC_TYPE), inputCaptor.capture());
@@ -129,8 +159,10 @@ public class RemoteOpsImplementationTest extends AbstractOpsTest {
     @SuppressWarnings({"checkstyle:AvoidHidingCauseException", "checkstyle:IllegalThrows"})
     @Test(expected = DOMRpcException.class)
     public void testInvokeRpcWithRemoteFailedFuture() throws Throwable {
-        final ContainerNode invokeRpcInput = makeRPCInput("foo");
-        final ArgumentCaptor<ContainerNode> inputCaptor = ArgumentCaptor.forClass(ContainerNode.class);
+        final NormalizedNode<?, ?> invokeRpcInput = makeRPCInput("foo");
+        @SuppressWarnings({"unchecked", "rawtypes"})
+        final ArgumentCaptor<NormalizedNode<?, ?>> inputCaptor =
+                (ArgumentCaptor) ArgumentCaptor.forClass(NormalizedNode.class);
 
         when(domRpcService2.invokeRpc(eq(TEST_RPC_TYPE), inputCaptor.capture())).thenReturn(
                 FluentFutures.immediateFailedFluentFuture(new RemoteDOMRpcException("Test Exception", null)));
@@ -152,7 +184,9 @@ public class RemoteOpsImplementationTest extends AbstractOpsTest {
     @Test(expected = DOMActionException.class)
     public void testInvokeActionWithRemoteFailedFuture() throws Throwable {
         final ContainerNode invokeActionInput = makeRPCInput("foo");
-        final ArgumentCaptor<ContainerNode> inputCaptor = ArgumentCaptor.forClass(ContainerNode.class);
+        @SuppressWarnings({"unchecked", "rawtypes"})
+        final ArgumentCaptor<ContainerNode> inputCaptor =
+                ArgumentCaptor.forClass(ContainerNode.class);
 
         when(domActionService2.invokeAction(eq(TEST_RPC_TYPE), eq(TEST_DATA_TREE_ID),
                 inputCaptor.capture())).thenReturn(FluentFutures.immediateFailedFluentFuture(
@@ -176,7 +210,7 @@ public class RemoteOpsImplementationTest extends AbstractOpsTest {
     @Ignore
     @Test(expected = RemoteDOMRpcException.class)
     public void testInvokeRpcWithAkkaTimeoutException() throws Exception {
-        final ContainerNode invokeRpcInput = makeRPCInput("foo");
+        final NormalizedNode<?, ?> invokeRpcInput = makeRPCInput("foo");
         final ListenableFuture<DOMRpcResult> frontEndFuture = remoteRpcImpl1.invokeRpc(TEST_RPC_ID, invokeRpcInput);
         assertTrue(frontEndFuture instanceof RemoteDOMRpcFuture);
 
@@ -190,10 +224,10 @@ public class RemoteOpsImplementationTest extends AbstractOpsTest {
     @Test(expected = DOMRpcException.class)
     @SuppressWarnings({"checkstyle:AvoidHidingCauseException", "checkstyle:IllegalThrows"})
     public void testInvokeRpcWithLookupException() throws Throwable {
-        final ContainerNode invokeRpcInput = makeRPCInput("foo");
+        final NormalizedNode<?, ?> invokeRpcInput = makeRPCInput("foo");
 
         doThrow(new RuntimeException("test")).when(domRpcService2).invokeRpc(any(SchemaPath.class),
-            any(ContainerNode.class));
+            any(NormalizedNode.class));
 
         final ListenableFuture<DOMRpcResult> frontEndFuture = remoteRpcImpl1.invokeRpc(TEST_RPC_ID, invokeRpcInput);
         assertTrue(frontEndFuture instanceof RemoteDOMRpcFuture);