Merge "Revert "Revert "BUG-1425: Integrated new Binding to Normalized Node codec...
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / utils / MockActorContext.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.cluster.datastore.utils;
10
11 import static org.junit.Assert.assertNotNull;
12 import akka.actor.ActorRef;
13 import akka.actor.ActorSelection;
14 import akka.actor.ActorSystem;
15 import scala.concurrent.duration.FiniteDuration;
16
17 public class MockActorContext extends ActorContext {
18
19     private volatile Object executeShardOperationResponse;
20     private volatile Object executeRemoteOperationResponse;
21     private volatile Object executeLocalOperationResponse;
22     private volatile Object executeLocalShardOperationResponse;
23     private volatile Exception executeRemoteOperationFailure;
24     private volatile Object inputMessage;
25
26     public MockActorContext(ActorSystem actorSystem) {
27         super(actorSystem, null, new MockClusterWrapper(), new MockConfiguration());
28     }
29
30     public MockActorContext(ActorSystem actorSystem, ActorRef shardManager) {
31         super(actorSystem, shardManager, new MockClusterWrapper(), new MockConfiguration());
32     }
33
34
35     @Override public Object executeShardOperation(String shardName,
36         Object message, FiniteDuration duration) {
37         return executeShardOperationResponse;
38     }
39
40     @Override public Object executeRemoteOperation(ActorSelection actor,
41         Object message, FiniteDuration duration) {
42         return executeRemoteOperationResponse;
43     }
44
45     @Override public ActorSelection findPrimary(String shardName) {
46         return null;
47     }
48
49     public void setExecuteShardOperationResponse(Object response){
50         executeShardOperationResponse = response;
51     }
52
53     public void setExecuteRemoteOperationResponse(Object response){
54         executeRemoteOperationResponse = response;
55     }
56
57     public void setExecuteRemoteOperationFailure(Exception executeRemoteOperationFailure) {
58         this.executeRemoteOperationFailure = executeRemoteOperationFailure;
59     }
60
61     public void setExecuteLocalOperationResponse(
62         Object executeLocalOperationResponse) {
63         this.executeLocalOperationResponse = executeLocalOperationResponse;
64     }
65
66     public void setExecuteLocalShardOperationResponse(
67         Object executeLocalShardOperationResponse) {
68         this.executeLocalShardOperationResponse = executeLocalShardOperationResponse;
69     }
70
71     @SuppressWarnings("unchecked")
72     public <T> T getInputMessage(Class<T> expType) throws Exception {
73         assertNotNull("Input message was null", inputMessage);
74         return (T) expType.getMethod("fromSerializable", Object.class).invoke(null, inputMessage);
75     }
76
77     @Override
78     public Object executeLocalOperation(ActorRef actor,
79         Object message, FiniteDuration duration) {
80         return this.executeLocalOperationResponse;
81     }
82
83     @Override
84     public Object executeLocalShardOperation(String shardName,
85         Object message, FiniteDuration duration) {
86         return this.executeLocalShardOperationResponse;
87     }
88 }