Cleanup TestKit use
[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.util.Collections;
16 import org.junit.AfterClass;
17 import org.junit.BeforeClass;
18 import org.junit.Test;
19 import org.opendaylight.controller.remote.rpc.registry.RpcRegistry;
20 import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
21 import org.opendaylight.yangtools.yang.common.QName;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
23 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
24
25 public class RpcListenerTest {
26
27     private static final QName TEST_QNAME = QName.create("test", "2015-06-12", "test");
28     private static final SchemaPath RPC_TYPE = SchemaPath.create(true, TEST_QNAME);
29     private static final YangInstanceIdentifier TEST_PATH = YangInstanceIdentifier
30             .create(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME));
31     private static final DOMRpcIdentifier RPC_ID = DOMRpcIdentifier.create(RPC_TYPE, TEST_PATH);
32
33     private static ActorSystem SYSTEM;
34
35     @BeforeClass
36     public static void setup() {
37         SYSTEM = ActorSystem.create("opendaylight-rpc", ConfigFactory.load().getConfig("odl-cluster-rpc"));
38     }
39
40     @AfterClass
41     public static void teardown() {
42         TestKit.shutdownActorSystem(SYSTEM);
43         SYSTEM = null;
44     }
45
46     @Test
47     public void testRouteAdd() {
48         // Test announcements
49         final TestKit probeReg = new TestKit(SYSTEM);
50         final ActorRef rpcRegistry = probeReg.getRef();
51
52         final RpcListener rpcListener = new RpcListener(rpcRegistry);
53         rpcListener.onRpcAvailable(Collections.singleton(RPC_ID));
54         probeReg.expectMsgClass(RpcRegistry.Messages.AddOrUpdateRoutes.class);
55     }
56
57     @Test
58     public void testRouteRemove() {
59         // Test announcements
60         final TestKit probeReg = new TestKit(SYSTEM);
61         final ActorRef rpcRegistry = probeReg.getRef();
62
63         final RpcListener rpcListener = new RpcListener(rpcRegistry);
64         rpcListener.onRpcUnavailable(Collections.singleton(RPC_ID));
65         probeReg.expectMsgClass(RpcRegistry.Messages.RemoveRoutes.class);
66     }
67 }