diff options
author | Marek Gradzki <mgradzki@cisco.com> | 2018-03-07 11:02:29 +0100 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2018-03-07 11:57:06 +0100 |
commit | a604b493ab32467635ec1767b2747bcf8f22cae9 (patch) | |
tree | d3813d11dcfa2a6e92068f3b842de25b2c6bb2e7 /infra/rpc/impl/src/test | |
parent | 58049e06ac79053d72e97dd333fe65a44642c6d3 (diff) |
Fix handling of RPCs that do not produce a result
The output statement of RPC operation is optional.
In such cases DefaultDOMRpcResult should be initialized with null result.
Change-Id: Ia832e480b3c72607b3636493bc044a9144f247be
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'infra/rpc/impl/src/test')
-rw-r--r-- | infra/rpc/impl/src/test/java/io/fd/honeycomb/rpc/HoneycombDOMRpcServiceTest.java | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/infra/rpc/impl/src/test/java/io/fd/honeycomb/rpc/HoneycombDOMRpcServiceTest.java b/infra/rpc/impl/src/test/java/io/fd/honeycomb/rpc/HoneycombDOMRpcServiceTest.java index 26219d8b4..53d37f375 100644 --- a/infra/rpc/impl/src/test/java/io/fd/honeycomb/rpc/HoneycombDOMRpcServiceTest.java +++ b/infra/rpc/impl/src/test/java/io/fd/honeycomb/rpc/HoneycombDOMRpcServiceTest.java @@ -17,13 +17,14 @@ package io.fd.honeycomb.rpc; import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import java.util.concurrent.CompletableFuture; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentMatchers; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.yangtools.yang.binding.DataObject; @@ -41,8 +42,6 @@ public class HoneycombDOMRpcServiceTest { private SchemaPath path; @Mock private DataObject input; - @Mock - private ContainerNode output; private ContainerNode node; private HoneycombDOMRpcService service; @@ -51,32 +50,41 @@ public class HoneycombDOMRpcServiceTest { public void setUp() { MockitoAnnotations.initMocks(this); node = mockContainerNode(QName.create("a")); - service = new HoneycombDOMRpcService(serializer, registry); - - Mockito.when(serializer.fromNormalizedNodeRpcData(ArgumentMatchers.any(), ArgumentMatchers.any())).thenReturn(input); - Mockito.when(serializer.toNormalizedNodeRpcData(ArgumentMatchers.any())).thenReturn(output); + when(serializer.fromNormalizedNodeRpcData(ArgumentMatchers.any(), ArgumentMatchers.any())).thenReturn(input); } @Test public void testInvokeRpc() throws Exception { - Mockito.when(registry.invoke(path, input)).thenReturn(CompletableFuture.completedFuture(input)); + final ContainerNode outputBi = mock(ContainerNode.class); + final DataObject outputBa = mock(DataObject.class); + when(serializer.toNormalizedNodeRpcData(ArgumentMatchers.any())).thenReturn(outputBi); + when(registry.invoke(path, input)).thenReturn(CompletableFuture.completedFuture(outputBa)); + + assertEquals(outputBi, service.invokeRpc(path, node).get().getResult()); + } + + @Test + public void testInvokeRpcNoResult() throws Exception { + final DataObject outputBa = null; + final ContainerNode outputBi = null; + when(registry.invoke(path, input)).thenReturn(CompletableFuture.completedFuture(outputBa)); - assertEquals(output, service.invokeRpc(path, node).get().getResult()); + assertEquals(outputBi, service.invokeRpc(path, node).get().getResult()); } @Test(expected = RpcException.class) public void testInvokeRpcFailed() throws Exception { final CompletableFuture future = new CompletableFuture(); future.completeExceptionally(new RuntimeException()); - Mockito.when(registry.invoke(path, input)).thenReturn(future); + when(registry.invoke(path, input)).thenReturn(future); service.invokeRpc(path, node).checkedGet(); } private ContainerNode mockContainerNode(final QName nn1) { - final ContainerNode nn1B = Mockito.mock(ContainerNode.class); - Mockito.when(nn1B.getNodeType()).thenReturn(nn1); + final ContainerNode nn1B = mock(ContainerNode.class); + when(nn1B.getNodeType()).thenReturn(nn1); return nn1B; } }
\ No newline at end of file |