Teach sal-remoterpc-connector to route actions
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / test / java / org / opendaylight / controller / remote / rpc / RemoteOpsProviderTest.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.assertTrue;
11 import static org.mockito.Mockito.mock;
12
13 import akka.actor.ActorRef;
14 import akka.actor.ActorSystem;
15 import akka.testkit.javadsl.TestKit;
16 import com.typesafe.config.Config;
17 import com.typesafe.config.ConfigFactory;
18 import java.util.concurrent.TimeUnit;
19 import org.junit.AfterClass;
20 import org.junit.BeforeClass;
21 import org.junit.Test;
22 import org.opendaylight.mdsal.dom.api.DOMActionProviderService;
23 import org.opendaylight.mdsal.dom.api.DOMActionService;
24 import org.opendaylight.mdsal.dom.api.DOMRpcProviderService;
25 import org.opendaylight.mdsal.dom.api.DOMRpcService;
26 import scala.concurrent.Await;
27 import scala.concurrent.duration.FiniteDuration;
28
29 public class RemoteOpsProviderTest {
30     static ActorSystem system;
31     static RemoteOpsProviderConfig moduleConfig;
32
33     @BeforeClass
34     public static void setup() {
35         moduleConfig = new RemoteOpsProviderConfig.Builder("odl-cluster-rpc")
36                 .withConfigReader(ConfigFactory::load).build();
37         final Config config = moduleConfig.get();
38         system = ActorSystem.create("odl-cluster-rpc", config);
39
40     }
41
42     @AfterClass
43     public static void teardown() {
44         TestKit.shutdownActorSystem(system);
45         system = null;
46     }
47
48     @Test
49     public void testRemoteRpcProvider() throws Exception {
50         try (RemoteOpsProvider rpcProvider = new RemoteOpsProvider(system, mock(DOMRpcProviderService.class),
51                 mock(DOMRpcService.class), new RemoteOpsProviderConfig(system.settings().config()),
52                 mock(DOMActionProviderService.class), mock(DOMActionService.class))) {
53
54             rpcProvider.start();
55             final ActorRef actorRef = Await.result(
56                     system.actorSelection(moduleConfig.getRpcManagerPath()).resolveOne(
57                             FiniteDuration.create(1, TimeUnit.SECONDS)), FiniteDuration.create(2, TimeUnit.SECONDS));
58
59             assertTrue(actorRef.path().toString().contains(moduleConfig.getRpcManagerPath()));
60         }
61     }
62 }

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