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