8b4599ca8ceac01684376b63be3dded36e354e2b
[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
10 package org.opendaylight.controller.remote.rpc;
11
12
13 import akka.actor.ActorRef;
14 import akka.actor.ActorSystem;
15 import akka.testkit.JavaTestKit;
16 import com.typesafe.config.Config;
17 import org.junit.AfterClass;
18 import org.junit.Assert;
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;
27
28 import java.util.concurrent.TimeUnit;
29
30 import static org.mockito.Mockito.mock;
31 import static org.mockito.Mockito.when;
32
33 public class RemoteRpcProviderTest {
34
35   static ActorSystem system;
36   static RemoteRpcProviderConfig moduleConfig;
37
38   @BeforeClass
39   public static void setup() throws InterruptedException {
40     moduleConfig = new RemoteRpcProviderConfig.Builder("odl-cluster-rpc").build();
41     Config config = moduleConfig.get();
42     system = ActorSystem.create("odl-cluster-rpc", config);
43
44   }
45
46   @AfterClass
47   public static void teardown() {
48     JavaTestKit.shutdownActorSystem(system);
49     system = null;
50   }
51
52   @Test
53   public void testRemoteRpcProvider() throws Exception {
54     RemoteRpcProvider rpcProvider = new RemoteRpcProvider(system, mock(RpcProvisionRegistry.class));
55     Broker.ProviderSession session = mock(Broker.ProviderSession.class);
56     SchemaService schemaService = mock(SchemaService.class);
57     when(schemaService.getGlobalContext()). thenReturn(mock(SchemaContext.class));
58     when(session.getService(SchemaService.class)).thenReturn(schemaService);
59
60     rpcProvider.onSessionInitiated(session);
61
62     ActorRef actorRef = Await.result(
63             system.actorSelection(
64                     moduleConfig.getRpcManagerPath()).resolveOne(Duration.create(1, TimeUnit.SECONDS)),
65                                                                  Duration.create(2, TimeUnit.SECONDS));
66
67     Assert.assertTrue(actorRef.path().toString().contains(moduleConfig.getRpcManagerPath()));
68   }
69 }