Add support for reusable streaming
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / test / java / org / opendaylight / controller / remote / rpc / OpsBrokerTest.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 OpsBrokerTest extends AbstractOpsTest {
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         final ExecuteRpc executeRpc = ExecuteRpc.from(TEST_RPC_ID, null);
37
38         rpcInvoker1.tell(executeRpc, rpcRegistry1Probe.getRef());
39
40         final RpcResponse rpcResponse = rpcRegistry1Probe.expectMsgClass(Duration.ofSeconds(5), RpcResponse.class);
41
42         assertEquals(rpcResult.getResult(), rpcResponse.getOutput());
43     }
44
45     @Test
46     public void testExecuteRpcFailureWithException() {
47         when(domRpcService1.invokeRpc(eq(TEST_RPC_TYPE), any())).thenReturn(FluentFutures.immediateFailedFluentFuture(
48             new DOMRpcImplementationNotAvailableException("NOT FOUND")));
49
50         final ExecuteRpc executeMsg = ExecuteRpc.from(TEST_RPC_ID, null);
51
52         rpcInvoker1.tell(executeMsg, rpcRegistry1Probe.getRef());
53
54         final Failure rpcResponse = rpcRegistry1Probe.expectMsgClass(Duration.ofSeconds(5), Failure.class);
55
56         assertTrue(rpcResponse.cause() instanceof DOMRpcException);
57     }
58 }

©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.