Add support for reusable streaming
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / test / java / org / opendaylight / controller / remote / rpc / OpsListenerTest.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 package org.opendaylight.controller.remote.rpc;
9
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.SchemaPath;
26
27 public class OpsListenerTest {
28
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     private static final DOMActionInstance ACTION_INSTANCE = DOMActionInstance.of(RPC_TYPE,
35             LogicalDatastoreType.OPERATIONAL, TEST_PATH);
36
37     private static ActorSystem SYSTEM;
38
39     @BeforeClass
40     public static void setup() {
41         SYSTEM = ActorSystem.create("opendaylight-rpc", ConfigFactory.load().getConfig("odl-cluster-rpc"));
42     }
43
44     @AfterClass
45     public static void teardown() {
46         TestKit.shutdownActorSystem(SYSTEM);
47         SYSTEM = null;
48     }
49
50     @Test
51     public void testRouteAdd() {
52         // Test announcements
53         final TestKit probeReg = new TestKit(SYSTEM);
54         final ActorRef rpcRegistry = probeReg.getRef();
55
56         final OpsListener opsListener = new OpsListener(rpcRegistry, rpcRegistry);
57         opsListener.onRpcAvailable(Collections.singleton(RPC_ID));
58         probeReg.expectMsgClass(RpcRegistry.Messages.AddOrUpdateRoutes.class);
59     }
60
61     @Test
62     public void testActionRouteAdd() {
63         // Test announcements
64         final TestKit probeReg = new TestKit(SYSTEM);
65         final ActorRef actionRegistry = probeReg.getRef();
66
67         final OpsListener opsListener = new OpsListener(actionRegistry, actionRegistry);
68         opsListener.onActionsChanged(Collections.emptySet(),Collections.singleton(ACTION_INSTANCE));
69         probeReg.expectMsgClass(ActionRegistry.Messages.UpdateActions.class);
70     }
71
72     @Test
73     public void testRouteRemove() {
74         // Test announcements
75         final TestKit probeReg = new TestKit(SYSTEM);
76         final ActorRef rpcRegistry = probeReg.getRef();
77
78         final OpsListener opsListener = new OpsListener(rpcRegistry, rpcRegistry);
79         opsListener.onRpcUnavailable(Collections.singleton(RPC_ID));
80         probeReg.expectMsgClass(RpcRegistry.Messages.RemoveRoutes.class);
81     }
82
83 //    @Test
84 //    public void testAcceptsImplementation() {
85 //
86 //        final TestKit probeReg = new TestKit(SYSTEM);
87 //        final ActorRef opsRegistry = probeReg.getRef();
88 //
89 //        final OpsListener opsListener = new OpsListener(opsRegistry, opsRegistry);
90 //        opsListener.acceptsImplementation()
91 //    }
92 }