2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
10 package org.opendaylight.controller.remote.rpc;
13 import akka.actor.ActorRef;
14 import akka.actor.ActorSystem;
15 import akka.testkit.JavaTestKit;
16 import com.typesafe.config.ConfigFactory;
17 import junit.framework.Assert;
18 import org.junit.AfterClass;
19 import org.junit.BeforeClass;
20 import org.junit.Test;
21 import org.opendaylight.controller.sal.core.api.Broker;
22 import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry;
23 import org.opendaylight.controller.sal.core.api.model.SchemaService;
24 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
25 import scala.concurrent.Await;
26 import scala.concurrent.duration.Duration;
29 import java.util.concurrent.TimeUnit;
31 import static org.mockito.Mockito.mock;
32 import static org.mockito.Mockito.when;
34 public class RemoteRpcProviderTest {
36 static ActorSystem system;
40 public static void setup() throws InterruptedException {
41 system = ActorSystem.create("opendaylight-rpc", ConfigFactory.load().getConfig("odl-cluster"));
45 public static void teardown() {
46 JavaTestKit.shutdownActorSystem(system);
51 public void testRemoteRpcProvider() throws Exception {
52 RemoteRpcProvider rpcProvider = new RemoteRpcProvider(system, mock(RpcProvisionRegistry.class));
53 Broker.ProviderSession session = mock(Broker.ProviderSession.class);
54 SchemaService schemaService = mock(SchemaService.class);
55 when(schemaService.getGlobalContext()). thenReturn(mock(SchemaContext.class));
56 when(session.getService(SchemaService.class)).thenReturn(schemaService);
57 rpcProvider.onSessionInitiated(session);
58 ActorRef actorRef = Await.result(system.actorSelection(ActorConstants.RPC_MANAGER_PATH).resolveOne(Duration.create(1, TimeUnit.SECONDS)),
59 Duration.create(2, TimeUnit.SECONDS));
60 Assert.assertTrue(actorRef.path().toString().contains(ActorConstants.RPC_MANAGER_PATH));