Migrate from JavaTestKit to javadsl.TestKit
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / test / java / org / opendaylight / controller / remote / rpc / RpcListenerTest.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
9 package org.opendaylight.controller.remote.rpc;
10
11 import akka.actor.ActorRef;
12 import akka.actor.ActorSystem;
13 import akka.testkit.javadsl.TestKit;
14 import com.typesafe.config.ConfigFactory;
15 import java.net.URISyntaxException;
16 import java.util.Collections;
17 import org.junit.AfterClass;
18 import org.junit.BeforeClass;
19 import org.junit.Test;
20 import org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier;
21 import org.opendaylight.controller.remote.rpc.registry.RpcRegistry;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
24 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
25
26 public class RpcListenerTest {
27
28     private static final QName TEST_QNAME = QName.create("test", "2015-06-12", "test");
29     private static final SchemaPath RPC_TYPE = SchemaPath.create(true, TEST_QNAME);
30     private static final YangInstanceIdentifier TEST_PATH = YangInstanceIdentifier
31             .create(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME));
32     private static final DOMRpcIdentifier RPC_ID = DOMRpcIdentifier.create(RPC_TYPE, TEST_PATH);
33     static ActorSystem system;
34
35
36     @BeforeClass
37     public static void setup() throws InterruptedException {
38         system = ActorSystem.create("opendaylight-rpc", ConfigFactory.load().getConfig("odl-cluster-rpc"));
39     }
40
41     @AfterClass
42     public static void teardown() {
43         TestKit.shutdownActorSystem(system);
44         system = null;
45     }
46
47     @Test
48     public void testRouteAdd() throws URISyntaxException, InterruptedException {
49         new TestKit(system) {
50             {
51                 // Test announcements
52                 final TestKit probeReg = new TestKit(system);
53                 final ActorRef rpcRegistry = probeReg.getRef();
54
55                 final RpcListener rpcListener = new RpcListener(rpcRegistry);
56                 rpcListener.onRpcAvailable(Collections.singleton(RPC_ID));
57                 probeReg.expectMsgClass(RpcRegistry.Messages.AddOrUpdateRoutes.class);
58             }
59         };
60     }
61
62     @Test
63     public void testRouteRemove() throws URISyntaxException, InterruptedException {
64         new TestKit(system) {
65             {
66                 // Test announcements
67                 final TestKit probeReg = new TestKit(system);
68                 final ActorRef rpcRegistry = probeReg.getRef();
69
70                 final RpcListener rpcListener = new RpcListener(rpcRegistry);
71                 rpcListener.onRpcUnavailable(Collections.singleton(RPC_ID));
72                 probeReg.expectMsgClass(RpcRegistry.Messages.RemoveRoutes.class);
73             }
74         };
75     }
76 }