summaryrefslogtreecommitdiffstats
path: root/infra/rpc
diff options
context:
space:
mode:
Diffstat (limited to 'infra/rpc')
-rw-r--r--infra/rpc/impl/src/main/java/io/fd/honeycomb/rpc/HoneycombDOMRpcService.java8
-rw-r--r--infra/rpc/impl/src/test/java/io/fd/honeycomb/rpc/HoneycombDOMRpcServiceTest.java32
2 files changed, 26 insertions, 14 deletions
diff --git a/infra/rpc/impl/src/main/java/io/fd/honeycomb/rpc/HoneycombDOMRpcService.java b/infra/rpc/impl/src/main/java/io/fd/honeycomb/rpc/HoneycombDOMRpcService.java
index 68f29f208..01adbd6da 100644
--- a/infra/rpc/impl/src/main/java/io/fd/honeycomb/rpc/HoneycombDOMRpcService.java
+++ b/infra/rpc/impl/src/main/java/io/fd/honeycomb/rpc/HoneycombDOMRpcService.java
@@ -71,8 +71,12 @@ public final class HoneycombDOMRpcService implements DOMRpcService {
private ListenableFuture<DOMRpcResult> getDOMRpcResult(final ListenableFuture<DataObject> invoke) {
return Futures.transform(
invoke,
- (Function<DataObject, DOMRpcResult>) output -> {
- final ContainerNode outputNode = serializer.toNormalizedNodeRpcData(output);
+ output -> {
+ // If result is available convert it to BI form. Otherwise pass null as DOMRpcResult expects.
+ ContainerNode outputNode = null;
+ if (output != null) {
+ outputNode = serializer.toNormalizedNodeRpcData(output);
+ }
return new DefaultDOMRpcResult(outputNode);
});
}
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