Migrate to UntypedAbstractActor
[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
9 package org.opendaylight.controller.remote.rpc;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.mockito.Matchers.eq;
13 import static org.mockito.Mockito.when;
14
15 import akka.actor.Status.Failure;
16 import akka.testkit.javadsl.TestKit;
17 import org.junit.Assert;
18 import org.junit.Test;
19 import org.mockito.Mockito;
20 import org.opendaylight.controller.remote.rpc.messages.ExecuteRpc;
21 import org.opendaylight.controller.remote.rpc.messages.RpcResponse;
22 import org.opendaylight.mdsal.dom.api.DOMRpcException;
23 import org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException;
24 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
25 import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
26 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
27 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
28 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
29
30 public class RpcBrokerTest extends AbstractRpcTest {
31
32     @Test
33     public void testExecuteRpc() {
34         new TestKit(node1) {
35             {
36
37                 final ContainerNode invokeRpcResult = makeRPCOutput("bar");
38                 final DOMRpcResult rpcResult = new DefaultDOMRpcResult(invokeRpcResult);
39                 when(domRpcService1.invokeRpc(eq(TEST_RPC_TYPE), Mockito.<NormalizedNode<?, ?>>any())).thenReturn(
40                         FluentFutures.immediateFluentFuture(rpcResult));
41
42                 final ExecuteRpc executeMsg = ExecuteRpc.from(TEST_RPC_ID, null);
43
44                 rpcInvoker1.tell(executeMsg, getRef());
45
46                 final RpcResponse rpcResponse = expectMsgClass(duration("5 seconds"), RpcResponse.class);
47
48                 assertEquals(rpcResult.getResult(), rpcResponse.getResultNormalizedNode());
49             }
50         };
51     }
52
53     @Test
54     public void testExecuteRpcFailureWithException() {
55         new TestKit(node1) {
56             {
57                 when(domRpcService1.invokeRpc(eq(TEST_RPC_TYPE), Mockito.<NormalizedNode<?, ?>>any()))
58                         .thenReturn(FluentFutures.immediateFailedFluentFuture(
59                                 new DOMRpcImplementationNotAvailableException("NOT FOUND")));
60
61                 final ExecuteRpc executeMsg = ExecuteRpc.from(TEST_RPC_ID, null);
62
63                 rpcInvoker1.tell(executeMsg, getRef());
64
65                 final Failure rpcResponse = expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);
66
67                 Assert.assertTrue(rpcResponse.cause() instanceof DOMRpcException);
68             }
69         };
70     }
71 }

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