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
9 package org.opendaylight.controller.remote.rpc;
12 import akka.actor.ActorRef;
13 import akka.actor.ActorSystem;
14 import akka.testkit.JavaTestKit;
15 import com.typesafe.config.ConfigFactory;
16 import java.net.URISyntaxException;
17 import java.util.Collections;
18 import org.junit.AfterClass;
19 import org.junit.BeforeClass;
20 import org.junit.Test;
21 import org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier;
22 import org.opendaylight.controller.remote.rpc.registry.RpcRegistry;
23 import org.opendaylight.yangtools.yang.common.QName;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
25 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
27 public class RpcListenerTest {
29 private static final QName TEST_QNAME = QName.create("test", "2015-06-12", "test");
30 private static final SchemaPath RPC_TYPE = SchemaPath.create(true, TEST_QNAME);
31 private static final YangInstanceIdentifier TEST_PATH = YangInstanceIdentifier
32 .create(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME));
33 private static final DOMRpcIdentifier RPC_ID = DOMRpcIdentifier.create(RPC_TYPE, TEST_PATH);
34 static ActorSystem system;
38 public static void setup() throws InterruptedException {
39 system = ActorSystem.create("opendaylight-rpc", ConfigFactory.load().getConfig("odl-cluster-rpc"));
43 public static void teardown() {
44 JavaTestKit.shutdownActorSystem(system);
49 public void testRouteAdd() throws URISyntaxException, InterruptedException {
50 new JavaTestKit(system) {
53 final JavaTestKit probeReg = new JavaTestKit(system);
54 final ActorRef rpcRegistry = probeReg.getRef();
56 final RpcListener rpcListener = new RpcListener(rpcRegistry);
57 rpcListener.onRpcAvailable(Collections.singleton(RPC_ID));
58 probeReg.expectMsgClass(RpcRegistry.Messages.AddOrUpdateRoutes.class);
64 public void testRouteRemove() throws URISyntaxException, InterruptedException {
65 new JavaTestKit(system) {
68 final JavaTestKit probeReg = new JavaTestKit(system);
69 final ActorRef rpcRegistry = probeReg.getRef();
71 final RpcListener rpcListener = new RpcListener(rpcRegistry);
72 rpcListener.onRpcUnavailable(Collections.singleton(RPC_ID));
73 probeReg.expectMsgClass(RpcRegistry.Messages.RemoveRoutes.class);