Search in sources :

Example 6 with DefaultDOMRpcResult

use of org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult in project controller by opendaylight.

the class GetConstantService method invokeRpc.

@Nonnull
@Override
public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(@Nonnull final DOMRpcIdentifier rpc, @Nullable final NormalizedNode<?, ?> input) {
    LOG.debug("get-constant invoked, current value: {}", constant);
    final LeafNode<Object> value = ImmutableLeafNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(CONSTANT)).withValue(constant).build();
    final ContainerNode result = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(OUTPUT)).withChild(value).build();
    return Futures.immediateCheckedFuture(new DefaultDOMRpcResult(result));
}
Also used : DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Nonnull(javax.annotation.Nonnull)

Example 7 with DefaultDOMRpcResult

use of org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult in project controller by opendaylight.

the class RemoteRpcImplementationTest method testInvokeRpcWithNullInput.

/**
 * 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);
    when(domRpcService2.invokeRpc(eq(TEST_RPC_TYPE), inputCaptor.capture())).thenReturn(Futures.<DOMRpcResult, DOMRpcException>immediateCheckedFuture(rpcResult));
    final CheckedFuture<DOMRpcResult, DOMRpcException> frontEndFuture = remoteRpcImpl1.invokeRpc(TEST_RPC_ID, null);
    assertTrue(frontEndFuture instanceof RemoteDOMRpcFuture);
    final DOMRpcResult result = frontEndFuture.checkedGet(5, TimeUnit.SECONDS);
    assertEquals(rpcOutput, result.getResult());
}
Also used : DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) ArgumentCaptor(org.mockito.ArgumentCaptor) DOMRpcResult(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult) DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMRpcException(org.opendaylight.controller.md.sal.dom.api.DOMRpcException) Test(org.junit.Test)

Example 8 with DefaultDOMRpcResult

use of org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult in project controller by opendaylight.

the class RemoteRpcImplementationTest method testInvokeRpcWithNoOutput.

/**
 * This test method invokes and executes the remote rpc.
 */
@Test
public void testInvokeRpcWithNoOutput() throws Exception {
    final ContainerNode rpcOutput = null;
    final DOMRpcResult rpcResult = new DefaultDOMRpcResult(rpcOutput);
    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(Futures.<DOMRpcResult, DOMRpcException>immediateCheckedFuture(rpcResult));
    final CheckedFuture<DOMRpcResult, DOMRpcException> frontEndFuture = remoteRpcImpl1.invokeRpc(TEST_RPC_ID, invokeRpcInput);
    assertTrue(frontEndFuture instanceof RemoteDOMRpcFuture);
    final DOMRpcResult result = frontEndFuture.checkedGet(5, TimeUnit.SECONDS);
    assertNull(result.getResult());
}
Also used : DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) ArgumentCaptor(org.mockito.ArgumentCaptor) DOMRpcResult(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult) DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMRpcException(org.opendaylight.controller.md.sal.dom.api.DOMRpcException) Test(org.junit.Test)

Example 9 with DefaultDOMRpcResult

use of org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult in project controller by opendaylight.

the class RemoteRpcImplementationTest method testInvokeRpc.

/**
 * This test method invokes and executes the remote rpc.
 */
@Test
public void testInvokeRpc() throws Exception {
    final ContainerNode rpcOutput = makeRPCOutput("bar");
    final DOMRpcResult rpcResult = new DefaultDOMRpcResult(rpcOutput);
    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(Futures.<DOMRpcResult, DOMRpcException>immediateCheckedFuture(rpcResult));
    final CheckedFuture<DOMRpcResult, DOMRpcException> frontEndFuture = remoteRpcImpl1.invokeRpc(TEST_RPC_ID, invokeRpcInput);
    assertTrue(frontEndFuture instanceof RemoteDOMRpcFuture);
    final DOMRpcResult result = frontEndFuture.checkedGet(5, TimeUnit.SECONDS);
    assertEquals(rpcOutput, result.getResult());
}
Also used : DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) ArgumentCaptor(org.mockito.ArgumentCaptor) DOMRpcResult(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult) DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMRpcException(org.opendaylight.controller.md.sal.dom.api.DOMRpcException) Test(org.junit.Test)

Aggregations

DefaultDOMRpcResult (org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult)9 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)8 Test (org.junit.Test)6 DOMRpcResult (org.opendaylight.controller.md.sal.dom.api.DOMRpcResult)6 DOMRpcException (org.opendaylight.controller.md.sal.dom.api.DOMRpcException)4 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)4 Nonnull (javax.annotation.Nonnull)3 ArgumentCaptor (org.mockito.ArgumentCaptor)3 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)2 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)2 TestKit (akka.testkit.javadsl.TestKit)1 MountPoint (org.opendaylight.controller.md.sal.binding.api.MountPoint)1 DOMRpcAvailabilityListener (org.opendaylight.controller.md.sal.dom.api.DOMRpcAvailabilityListener)1 DOMRpcService (org.opendaylight.controller.md.sal.dom.api.DOMRpcService)1 ExecuteRpc (org.opendaylight.controller.remote.rpc.messages.ExecuteRpc)1 RpcResponse (org.opendaylight.controller.remote.rpc.messages.RpcResponse)1 RpcConsumerRegistry (org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry)1 KnockKnockOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.KnockKnockOutput)1 KnockKnockOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.KnockKnockOutputBuilder)1 OpendaylightOfMigrationTestModelService (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.OpendaylightOfMigrationTestModelService)1