Remove reliance on org.opendaylight.controller.sal.core.api.Broker
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / test / java / org / opendaylight / controller / remote / rpc / RemoteRpcProviderTest.java
1 /*
2  * Copyright (c) 2014 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.mockito.Mockito.mock;
12
13 import akka.actor.ActorRef;
14 import akka.actor.ActorSystem;
15 import akka.testkit.JavaTestKit;
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.Assert;
21 import org.junit.BeforeClass;
22 import org.junit.Test;
23 import org.opendaylight.controller.md.sal.dom.api.DOMRpcProviderService;
24 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
25 import scala.concurrent.Await;
26 import scala.concurrent.duration.Duration;
27
28 public class RemoteRpcProviderTest {
29     static ActorSystem system;
30     static RemoteRpcProviderConfig moduleConfig;
31
32     @BeforeClass
33     public static void setup() throws InterruptedException {
34         moduleConfig = new RemoteRpcProviderConfig.Builder("odl-cluster-rpc")
35                 .withConfigReader(ConfigFactory::load).build();
36         final Config config = moduleConfig.get();
37         system = ActorSystem.create("odl-cluster-rpc", config);
38
39     }
40
41     @AfterClass
42     public static void teardown() {
43         JavaTestKit.shutdownActorSystem(system);
44         system = null;
45     }
46
47     @Test
48     public void testRemoteRpcProvider() throws Exception {
49         try (final RemoteRpcProvider rpcProvider = new RemoteRpcProvider(system, mock(DOMRpcProviderService.class),
50             mock(DOMRpcService.class), new RemoteRpcProviderConfig(system.settings().config()))) {
51
52             rpcProvider.start();
53
54             final ActorRef actorRef = Await.result(
55                     system.actorSelection(moduleConfig.getRpcManagerPath()).resolveOne(
56                             Duration.create(1, TimeUnit.SECONDS)), Duration.create(2, TimeUnit.SECONDS));
57
58             Assert.assertTrue(actorRef.path().toString().contains(moduleConfig.getRpcManagerPath()));
59         }
60     }
61 }