889bd5899020fd78755685254cf0924fdd288b5e
[controller.git] / opendaylight / md-sal / cds-access-client / src / test / java / org / opendaylight / controller / cluster / access / client / AbstractClientActorTest.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.mockito.Mockito.doReturn;
11
12 import akka.actor.ActorRef;
13 import com.google.common.testing.FakeTicker;
14 import org.junit.Before;
15 import org.mockito.Mock;
16 import org.mockito.MockitoAnnotations;
17 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
18 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
19 import org.opendaylight.controller.cluster.access.concepts.FrontendType;
20 import org.opendaylight.controller.cluster.access.concepts.MemberName;
21
22 /**
23  * Abstract base class for client actors and their components.
24  *
25  * @author Robert Varga
26  */
27 public abstract class AbstractClientActorTest {
28     private static final MemberName MEMBER_NAME = MemberName.forName("member-1");
29
30     @Mock
31     private ClientActorContext mockActorContext;
32     @Mock
33     private ActorRef mockSelf;
34
35     protected final FakeTicker ticker = new FakeTicker();
36
37     @Before
38     public void setup() {
39         MockitoAnnotations.initMocks(this);
40
41         final FrontendType frontendType = FrontendType.forName(getClass().getSimpleName());
42         final FrontendIdentifier frontendId = FrontendIdentifier.create(MEMBER_NAME, frontendType);
43         final ClientIdentifier clientId = ClientIdentifier.create(frontendId, 0);
44
45         doReturn(ticker).when(mockActorContext).ticker();
46         doReturn(clientId).when(mockActorContext).getIdentifier();
47         doReturn(getClass().getSimpleName()).when(mockActorContext).persistenceId();
48         doReturn(mockSelf).when(mockActorContext).self();
49     }
50
51     protected final ClientActorContext actorContext() {
52         return mockActorContext;
53     }
54
55     protected final ActorRef self() {
56         return mockSelf;
57     }
58 }