Eliminate use of deprecated mockito methods
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / sharding / RoleChangeListenerActorTest.java
1 /*
2  * Copyright (c) 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.cluster.sharding;
9
10 import static akka.actor.ActorRef.noSender;
11 import static org.mockito.ArgumentMatchers.any;
12 import static org.mockito.ArgumentMatchers.eq;
13 import static org.mockito.Mockito.doNothing;
14 import static org.mockito.Mockito.mock;
15 import static org.mockito.Mockito.timeout;
16 import static org.mockito.Mockito.verify;
17
18 import akka.actor.ActorRef;
19 import akka.actor.Props;
20 import akka.testkit.javadsl.TestKit;
21 import org.junit.Test;
22 import org.opendaylight.controller.cluster.datastore.AbstractActorTest;
23 import org.opendaylight.controller.cluster.dom.api.LeaderLocation;
24 import org.opendaylight.controller.cluster.dom.api.LeaderLocationListener;
25 import org.opendaylight.controller.cluster.notifications.LeaderStateChanged;
26 import org.opendaylight.controller.cluster.notifications.RegisterRoleChangeListener;
27
28 public class RoleChangeListenerActorTest extends AbstractActorTest {
29
30     @Test
31     public void testRegisterRoleChangeListenerOnStart() {
32         final TestKit testKit = new TestKit(getSystem());
33         final LeaderLocationListener listener = mock(LeaderLocationListener.class);
34         final Props props = RoleChangeListenerActor.props(testKit.getRef(), listener);
35
36         getSystem().actorOf(props, "testRegisterRoleChangeListenerOnStart");
37         testKit.expectMsgClass(RegisterRoleChangeListener.class);
38     }
39
40     @Test
41     public void testOnDataTreeChanged() {
42         final LeaderLocationListener listener = mock(LeaderLocationListener.class);
43         doNothing().when(listener).onLeaderLocationChanged(any());
44         final Props props = RoleChangeListenerActor.props(getSystem().deadLetters(), listener);
45
46         final ActorRef subject = getSystem().actorOf(props, "testDataTreeChangedChanged");
47
48         subject.tell(new LeaderStateChanged("member-1", null, (short) 0), noSender());
49         verify(listener, timeout(5000)).onLeaderLocationChanged(eq(LeaderLocation.UNKNOWN));
50
51         subject.tell(new LeaderStateChanged("member-1", "member-1", (short) 0), noSender());
52         verify(listener, timeout(5000)).onLeaderLocationChanged(eq(LeaderLocation.LOCAL));
53
54         subject.tell(new LeaderStateChanged("member-1", "member-2", (short) 0), noSender());
55         verify(listener, timeout(5000)).onLeaderLocationChanged(eq(LeaderLocation.REMOTE));
56     }
57 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.