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 org.junit.AfterClass;
17 import org.junit.BeforeClass;
18 import org.junit.Test;
19 import org.opendaylight.controller.md.sal.common.impl.routing.RoutingUtils;
20 import org.opendaylight.controller.remote.rpc.registry.RpcRegistry;
21 import org.opendaylight.controller.sal.core.api.RpcRoutingContext;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
26 import java.net.URISyntaxException;
28 public class RouteRpcListenerTest {
30 static ActorSystem system;
34 public static void setup() throws InterruptedException {
35 system = ActorSystem.create("opendaylight-rpc", ConfigFactory.load().getConfig("odl-cluster"));
39 public static void teardown() {
40 JavaTestKit.shutdownActorSystem(system);
45 public void testRouteAdd() throws URISyntaxException, InterruptedException {
46 new JavaTestKit(system) {
49 JavaTestKit probeReg = new JavaTestKit(system);
50 ActorRef rpcRegistry = probeReg.getRef();
52 RoutedRpcListener rpcListener = new RoutedRpcListener(rpcRegistry);
54 QName qName = new QName(new URI("actor2"), "actor2");
55 RpcRoutingContext context = RpcRoutingContext.create(qName, qName);
56 YangInstanceIdentifier identifier = YangInstanceIdentifier.create(new YangInstanceIdentifier.NodeIdentifier(qName));
57 rpcListener.onRouteChange(RoutingUtils.announcementChange(context, identifier));
59 probeReg.expectMsgClass(RpcRegistry.Messages.AddOrUpdateRoutes.class);
64 public void testRouteRemove() throws URISyntaxException, InterruptedException {
65 new JavaTestKit(system) {
68 JavaTestKit probeReg = new JavaTestKit(system);
69 ActorRef rpcRegistry = probeReg.getRef();
71 RoutedRpcListener rpcListener = new RoutedRpcListener(rpcRegistry);
73 QName qName = new QName(new URI("actor2"), "actor2");
74 RpcRoutingContext context = RpcRoutingContext.create(qName, qName);
75 YangInstanceIdentifier identifier = YangInstanceIdentifier.create(new YangInstanceIdentifier.NodeIdentifier(qName));
76 rpcListener.onRouteChange(RoutingUtils.removalChange(context, identifier));
78 probeReg.expectMsgClass(RpcRegistry.Messages.RemoveRoutes.class);