Migrate from JavaTestKit to javadsl.TestKit
[controller.git] / opendaylight / md-sal / cds-access-client / src / test / java / org / opendaylight / controller / cluster / access / client / ClientActorContextTest.java
index 34abbe5477f42090b6c24fb3602872c4ecbcda65..4dcbccbfb859d030b8313c3480c614a7302c4d4d 100644 (file)
@@ -8,10 +8,13 @@
 package org.opendaylight.controller.cluster.access.client;
 
 import static org.junit.Assert.assertSame;
-import akka.actor.ActorRef;
-import akka.actor.Scheduler;
-import akka.dispatch.Dispatcher;
+
+import akka.actor.ActorSystem;
+import akka.testkit.TestProbe;
+import akka.testkit.javadsl.TestKit;
 import com.google.common.base.Ticker;
+import java.util.concurrent.TimeUnit;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
@@ -20,39 +23,59 @@ import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
 import org.opendaylight.controller.cluster.access.concepts.FrontendType;
 import org.opendaylight.controller.cluster.access.concepts.MemberName;
+import scala.concurrent.duration.Duration;
+import scala.concurrent.duration.FiniteDuration;
 
 public class ClientActorContextTest {
     private static final MemberName MEMBER_NAME = MemberName.forName("member-1");
-    private static final FrontendType FRONTEND_TYPE = FrontendType.forName(ClientActorContextTest.class.getSimpleName());
+    private static final FrontendType FRONTEND_TYPE =
+            FrontendType.forName(ClientActorContextTest.class.getSimpleName());
     private static final FrontendIdentifier FRONTEND_ID = FrontendIdentifier.create(MEMBER_NAME, FRONTEND_TYPE);
     private static final ClientIdentifier CLIENT_ID = ClientIdentifier.create(FRONTEND_ID, 0);
     private static final String PERSISTENCE_ID = ClientActorContextTest.class.getSimpleName();
 
     @Mock
-    private ActorRef mockSelf;
-
-    @Mock
-    private Scheduler mockScheduler;
-
-    @Mock
-    private Dispatcher mockDispatcher;
+    private InternalCommand<? extends BackendInfo> command;
+    private ActorSystem system;
+    private TestProbe probe;
+    private ClientActorContext ctx;
 
     @Before
     public void setup() {
         MockitoAnnotations.initMocks(this);
+        system = ActorSystem.apply();
+        probe = new TestProbe(system);
+        ctx = new ClientActorContext(probe.ref(), PERSISTENCE_ID, system,
+                CLIENT_ID, AccessClientUtil.newMockClientActorConfig());
     }
 
     @Test
     public void testMockingControl() {
-        ClientActorContext ctx = new ClientActorContext(mockSelf, mockScheduler, mockDispatcher, PERSISTENCE_ID, CLIENT_ID);
         assertSame(CLIENT_ID, ctx.getIdentifier());
         assertSame(PERSISTENCE_ID, ctx.persistenceId());
-        assertSame(mockSelf, ctx.self());
+        assertSame(probe.ref(), ctx.self());
     }
 
     @Test
     public void testTicker() {
-        ClientActorContext ctx = new ClientActorContext(mockSelf, mockScheduler, mockDispatcher, PERSISTENCE_ID, CLIENT_ID);
         assertSame(Ticker.systemTicker(), ctx.ticker());
     }
+
+    @Test
+    public void testExecuteInActor() throws Exception {
+        ctx.executeInActor(command);
+        probe.expectMsg(command);
+    }
+
+    @Test
+    public void testExecuteInActorScheduled() throws Exception {
+        final FiniteDuration delay = Duration.apply(1, TimeUnit.SECONDS);
+        ctx.executeInActor(command, delay);
+        probe.expectMsg(command);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        TestKit.shutdownActorSystem(system);
+    }
 }