Bug 7449: Slice ReadTransactionSuccess response
[controller.git] / opendaylight / md-sal / cds-access-client / src / test / java / org / opendaylight / controller / cluster / access / client / ClientActorContextTest.java
1 /*
2  * Copyright (c) 2016 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.access.client;
9
10 import static org.junit.Assert.assertSame;
11
12 import akka.actor.ActorSystem;
13 import akka.testkit.JavaTestKit;
14 import akka.testkit.TestProbe;
15 import com.google.common.base.Ticker;
16 import java.util.concurrent.TimeUnit;
17 import org.junit.After;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.mockito.Mock;
21 import org.mockito.MockitoAnnotations;
22 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
23 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
24 import org.opendaylight.controller.cluster.access.concepts.FrontendType;
25 import org.opendaylight.controller.cluster.access.concepts.MemberName;
26 import scala.concurrent.duration.Duration;
27 import scala.concurrent.duration.FiniteDuration;
28
29 public class ClientActorContextTest {
30     private static final MemberName MEMBER_NAME = MemberName.forName("member-1");
31     private static final FrontendType FRONTEND_TYPE =
32             FrontendType.forName(ClientActorContextTest.class.getSimpleName());
33     private static final FrontendIdentifier FRONTEND_ID = FrontendIdentifier.create(MEMBER_NAME, FRONTEND_TYPE);
34     private static final ClientIdentifier CLIENT_ID = ClientIdentifier.create(FRONTEND_ID, 0);
35     private static final String PERSISTENCE_ID = ClientActorContextTest.class.getSimpleName();
36
37     @Mock
38     private InternalCommand<? extends BackendInfo> command;
39     private ActorSystem system;
40     private TestProbe probe;
41     private ClientActorContext ctx;
42
43     @Before
44     public void setup() {
45         MockitoAnnotations.initMocks(this);
46         system = ActorSystem.apply();
47         probe = new TestProbe(system);
48         ctx = new ClientActorContext(probe.ref(), PERSISTENCE_ID, system,
49                 CLIENT_ID, AccessClientUtil.newMockClientActorConfig());
50     }
51
52     @Test
53     public void testMockingControl() {
54         assertSame(CLIENT_ID, ctx.getIdentifier());
55         assertSame(PERSISTENCE_ID, ctx.persistenceId());
56         assertSame(probe.ref(), ctx.self());
57     }
58
59     @Test
60     public void testTicker() {
61         assertSame(Ticker.systemTicker(), ctx.ticker());
62     }
63
64     @Test
65     public void testExecuteInActor() throws Exception {
66         ctx.executeInActor(command);
67         probe.expectMsg(command);
68     }
69
70     @Test
71     public void testExecuteInActorScheduled() throws Exception {
72         final FiniteDuration delay = Duration.apply(1, TimeUnit.SECONDS);
73         ctx.executeInActor(command, delay);
74         probe.expectMsg(command);
75     }
76
77     @After
78     public void tearDown() throws Exception {
79         JavaTestKit.shutdownActorSystem(system);
80     }
81 }

©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.