Add support for reusable streaming
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / test / java / org / opendaylight / controller / remote / rpc / RpcBrokerTest.java
1 /*
2  * Copyright (c) 2014, 2017 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.remote.rpc;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
12 import static org.mockito.ArgumentMatchers.any;
13 import static org.mockito.ArgumentMatchers.eq;
14 import static org.mockito.Mockito.when;
15
16 import akka.actor.Status.Failure;
17 import java.time.Duration;
18 import org.junit.Test;
19 import org.opendaylight.controller.remote.rpc.messages.ExecuteRpc;
20 import org.opendaylight.controller.remote.rpc.messages.RpcResponse;
21 import org.opendaylight.mdsal.dom.api.DOMRpcException;
22 import org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException;
23 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
24 import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
25 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
26 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
27
28 public class RpcBrokerTest extends AbstractRpcTest {
29
30     @Test
31     public void testExecuteRpc() {
32         final ContainerNode invokeRpcResult = makeRPCOutput("bar");
33         final DOMRpcResult rpcResult = new DefaultDOMRpcResult(invokeRpcResult);
34         when(domRpcService1.invokeRpc(eq(TEST_RPC_TYPE), any())).thenReturn(
35             FluentFutures.immediateFluentFuture(rpcResult));
36
37         final ExecuteRpc executeMsg = ExecuteRpc.from(TEST_RPC_ID, null);
38
39         rpcInvoker1.tell(executeMsg, rpcRegistry1Probe.getRef());
40
41         final RpcResponse rpcResponse = rpcRegistry1Probe.expectMsgClass(Duration.ofSeconds(5), RpcResponse.class);
42
43         assertEquals(rpcResult.getResult(), rpcResponse.getResultNormalizedNode());
44     }
45
46     @Test
47     public void testExecuteRpcFailureWithException() {
48         when(domRpcService1.invokeRpc(eq(TEST_RPC_TYPE), any())).thenReturn(FluentFutures.immediateFailedFluentFuture(
49             new DOMRpcImplementationNotAvailableException("NOT FOUND")));
50
51         final ExecuteRpc executeMsg = ExecuteRpc.from(TEST_RPC_ID, null);
52
53         rpcInvoker1.tell(executeMsg, rpcRegistry1Probe.getRef());
54
55         final Failure rpcResponse = rpcRegistry1Probe.expectMsgClass(Duration.ofSeconds(5), Failure.class);
56
57         assertTrue(rpcResponse.cause() instanceof DOMRpcException);
58     }
59 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.