X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-remoterpc-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fremote%2Frpc%2FRemoteOpsImplementationTest.java;fp=opendaylight%2Fmd-sal%2Fsal-remoterpc-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fremote%2Frpc%2FRemoteRpcImplementationTest.java;h=6a7681223eca790c0b78e40ecb2149f668ea3fa6;hp=5b3394eebd223dacf65df2616e65b8f98e9b5444;hb=927bce5688e4b9d33d3e5e9b769d8a0dba5ccdd4;hpb=a2b838f96589b502578fa4e15cef2769f886a378;ds=sidebyside diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/RemoteRpcImplementationTest.java b/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/RemoteOpsImplementationTest.java similarity index 58% rename from opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/RemoteRpcImplementationTest.java rename to opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/RemoteOpsImplementationTest.java index 5b3394eebd..6a7681223e 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/RemoteRpcImplementationTest.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/RemoteOpsImplementationTest.java @@ -13,18 +13,24 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.when; import com.google.common.util.concurrent.ListenableFuture; +import java.util.Collections; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import org.junit.Ignore; import org.junit.Test; import org.mockito.ArgumentCaptor; +import org.opendaylight.mdsal.dom.api.DOMActionException; +import org.opendaylight.mdsal.dom.api.DOMActionResult; +import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier; import org.opendaylight.mdsal.dom.api.DOMRpcException; import org.opendaylight.mdsal.dom.api.DOMRpcResult; 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; @@ -35,7 +41,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath; * * @author Thomas Pantelis */ -public class RemoteRpcImplementationTest extends AbstractRpcTest { +public class RemoteOpsImplementationTest extends AbstractOpsTest { /** * This test method invokes and executes the remote rpc. @@ -45,10 +51,12 @@ public class RemoteRpcImplementationTest extends AbstractRpcTest { final ContainerNode rpcOutput = makeRPCOutput("bar"); final DOMRpcResult rpcResult = new DefaultDOMRpcResult(rpcOutput); +// Answer> answer = FluentFutures.immediateFluentFuture(rpcResult); + final NormalizedNode invokeRpcInput = makeRPCInput("foo"); @SuppressWarnings({"unchecked", "rawtypes"}) final ArgumentCaptor> inputCaptor = - (ArgumentCaptor) ArgumentCaptor.forClass(NormalizedNode.class); + ArgumentCaptor.forClass(NormalizedNode.class); when(domRpcService2.invokeRpc(eq(TEST_RPC_TYPE), inputCaptor.capture())).thenReturn( FluentFutures.immediateFluentFuture(rpcResult)); @@ -60,6 +68,27 @@ public class RemoteRpcImplementationTest extends AbstractRpcTest { assertEquals(rpcOutput, result.getResult()); } + /** + * This test method invokes and executes the remote action. + */ + @Test + public void testInvokeAction() throws Exception { + final ContainerNode actionOutput = makeRPCOutput("bar"); + final DOMActionResult actionResult = new SimpleDOMActionResult(actionOutput, Collections.emptyList()); + final NormalizedNode invokeActionInput = makeRPCInput("foo"); + @SuppressWarnings({"unchecked", "rawtypes"}) + final ArgumentCaptor 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 frontEndFuture = remoteActionImpl1.invokeAction(TEST_RPC_TYPE, + 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. */ @@ -82,6 +111,28 @@ public class RemoteRpcImplementationTest extends AbstractRpcTest { assertEquals(rpcOutput, result.getResult()); } + /** + * This test method invokes and executes the remote action. + */ + @Test + public void testInvokeActionWithNullInput() throws Exception { + final ContainerNode actionOutput = makeRPCOutput("bar"); + final DOMActionResult actionResult = new SimpleDOMActionResult(actionOutput); + + @SuppressWarnings({"unchecked", "rawtypes"}) + final ArgumentCaptor inputCaptor = + ArgumentCaptor.forClass(ContainerNode.class); + doReturn(FluentFutures.immediateFluentFuture(actionResult)).when(domActionService2).invokeAction( + eq(TEST_RPC_TYPE), eq(TEST_DATA_TREE_ID), inputCaptor.capture()); + + ListenableFuture frontEndFuture = remoteActionImpl1.invokeAction(TEST_RPC_TYPE, + TEST_DATA_TREE_ID, actionOutput); + 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. */ @@ -129,6 +180,32 @@ public class RemoteRpcImplementationTest extends AbstractRpcTest { } } + /** + * This test method invokes and executes the remote rpc. + */ + @SuppressWarnings({"checkstyle:AvoidHidingCauseException", "checkstyle:IllegalThrows"}) + @Test(expected = DOMActionException.class) + public void testInvokeActionWithRemoteFailedFuture() throws Throwable { + final ContainerNode invokeActionInput = makeRPCInput("foo"); + @SuppressWarnings({"unchecked", "rawtypes"}) + final ArgumentCaptor inputCaptor = + ArgumentCaptor.forClass(ContainerNode.class); + + when(domActionService2.invokeAction(eq(TEST_RPC_TYPE), eq(TEST_DATA_TREE_ID), + inputCaptor.capture())).thenReturn(FluentFutures.immediateFailedFluentFuture( + new RemoteDOMRpcException("Test Exception", null))); + + final ListenableFuture frontEndFuture = remoteActionImpl1.invokeAction(TEST_RPC_TYPE, + TEST_DATA_TREE_ID, invokeActionInput); + assertTrue(frontEndFuture instanceof RemoteDOMActionFuture); + + try { + frontEndFuture.get(5, TimeUnit.SECONDS); + } catch (ExecutionException e) { + throw e.getCause(); + } + } + /** * This test method invokes and tests exceptions when akka timeout occured * Currently ignored since this test with current config takes around 15 seconds to complete. @@ -164,4 +241,27 @@ public class RemoteRpcImplementationTest extends AbstractRpcTest { throw e.getCause(); } } + + /** + * This test method invokes remote rpc and lookup failed + * with runtime exception. + */ + @Test(expected = DOMActionException.class) + @SuppressWarnings({"checkstyle:AvoidHidingCauseException", "checkstyle:IllegalThrows"}) + public void testInvokeActionWithLookupException() throws Throwable { + final ContainerNode invokeRpcInput = makeRPCInput("foo"); + + doThrow(new RuntimeException("test")).when(domActionService2).invokeAction(any(SchemaPath.class), + any(DOMDataTreeIdentifier.class), any(ContainerNode.class)); + + final ListenableFuture frontEndFuture = remoteActionImpl1.invokeAction(TEST_RPC_TYPE, + TEST_DATA_TREE_ID, invokeRpcInput); + assertTrue(frontEndFuture instanceof RemoteDOMActionFuture); + + try { + frontEndFuture.get(5, TimeUnit.SECONDS); + } catch (ExecutionException e) { + throw e.getCause(); + } + } }