2 * Copyright (c) 2014, 2017 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
8 package org.opendaylight.controller.remote.rpc;
10 import akka.actor.ActorRef;
11 import akka.actor.ActorSystem;
12 import akka.testkit.javadsl.TestKit;
13 import com.typesafe.config.ConfigFactory;
14 import java.util.Collections;
15 import org.junit.AfterClass;
16 import org.junit.BeforeClass;
17 import org.junit.Test;
18 import org.opendaylight.controller.remote.rpc.registry.ActionRegistry;
19 import org.opendaylight.controller.remote.rpc.registry.RpcRegistry;
20 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
21 import org.opendaylight.mdsal.dom.api.DOMActionInstance;
22 import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier;
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.stmt.SchemaNodeIdentifier.Absolute;
27 public class OpsListenerTest {
29 private static final QName TEST_QNAME = QName.create("test", "2015-06-12", "test");
30 private static final Absolute RPC_TYPE = Absolute.of(TEST_QNAME);
31 private static final YangInstanceIdentifier TEST_PATH =
32 YangInstanceIdentifier.create(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME));
33 private static final DOMRpcIdentifier RPC_ID = DOMRpcIdentifier.create(TEST_QNAME, TEST_PATH);
34 private static final DOMActionInstance ACTION_INSTANCE = DOMActionInstance.of(RPC_TYPE,
35 LogicalDatastoreType.OPERATIONAL, TEST_PATH);
37 private static ActorSystem SYSTEM;
40 public static void setup() {
41 SYSTEM = ActorSystem.create("opendaylight-rpc", ConfigFactory.load().getConfig("odl-cluster-rpc"));
45 public static void teardown() {
46 TestKit.shutdownActorSystem(SYSTEM);
51 public void testRouteAdd() {
53 final TestKit probeReg = new TestKit(SYSTEM);
54 final ActorRef rpcRegistry = probeReg.getRef();
56 final OpsListener opsListener = new OpsListener(rpcRegistry, rpcRegistry);
57 opsListener.onRpcAvailable(Collections.singleton(RPC_ID));
58 probeReg.expectMsgClass(RpcRegistry.Messages.AddOrUpdateRoutes.class);
62 public void testActionRouteAdd() {
64 final TestKit probeReg = new TestKit(SYSTEM);
65 final ActorRef actionRegistry = probeReg.getRef();
67 final OpsListener opsListener = new OpsListener(actionRegistry, actionRegistry);
68 opsListener.onActionsChanged(Collections.emptySet(),Collections.singleton(ACTION_INSTANCE));
69 probeReg.expectMsgClass(ActionRegistry.Messages.UpdateActions.class);
73 public void testRouteRemove() {
75 final TestKit probeReg = new TestKit(SYSTEM);
76 final ActorRef rpcRegistry = probeReg.getRef();
78 final OpsListener opsListener = new OpsListener(rpcRegistry, rpcRegistry);
79 opsListener.onRpcUnavailable(Collections.singleton(RPC_ID));
80 probeReg.expectMsgClass(RpcRegistry.Messages.RemoveRoutes.class);
84 // public void testAcceptsImplementation() {
86 // final TestKit probeReg = new TestKit(SYSTEM);
87 // final ActorRef opsRegistry = probeReg.getRef();
89 // final OpsListener opsListener = new OpsListener(opsRegistry, opsRegistry);
90 // opsListener.acceptsImplementation()