37d81c7afb7859e9e18b616afdef46befad71f42
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / test / java / org / opendaylight / controller / remote / rpc / RpcListenerTest.java
1 /*
2  * Copyright (c) 2014 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
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;
26
27 public class RpcListenerTest {
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     static ActorSystem system;
35
36
37     @BeforeClass
38     public static void setup() throws InterruptedException {
39         system = ActorSystem.create("opendaylight-rpc", ConfigFactory.load().getConfig("odl-cluster-rpc"));
40     }
41
42     @AfterClass
43     public static void teardown() {
44         JavaTestKit.shutdownActorSystem(system);
45         system = null;
46     }
47
48     @Test
49     public void testRouteAdd() throws URISyntaxException, InterruptedException {
50         new JavaTestKit(system) {
51             {
52                 // Test announcements
53                 final JavaTestKit probeReg = new JavaTestKit(system);
54                 final ActorRef rpcRegistry = probeReg.getRef();
55
56                 final RpcListener rpcListener = new RpcListener(rpcRegistry);
57                 rpcListener.onRpcAvailable(Collections.singleton(RPC_ID));
58                 probeReg.expectMsgClass(RpcRegistry.Messages.AddOrUpdateRoutes.class);
59             }
60         };
61     }
62
63     @Test
64     public void testRouteRemove() throws URISyntaxException, InterruptedException {
65         new JavaTestKit(system) {
66             {
67                 // Test announcements
68                 final JavaTestKit probeReg = new JavaTestKit(system);
69                 final ActorRef rpcRegistry = probeReg.getRef();
70
71                 final RpcListener rpcListener = new RpcListener(rpcRegistry);
72                 rpcListener.onRpcUnavailable(Collections.singleton(RPC_ID));
73                 probeReg.expectMsgClass(RpcRegistry.Messages.RemoveRoutes.class);
74             }
75         };
76     }
77 }