1 package com.atlassian.core.ofbiz.test.mock;
2
3 import com.atlassian.core.action.ActionDispatcher;
4 import com.atlassian.core.action.DefaultActionDispatcher;
5 import webwork.action.Action;
6 import webwork.dispatcher.ActionResult;
7
8 import java.util.ArrayList;
9 import java.util.Collection;
10 import java.util.List;
11 import java.util.Map;
12
13 public class MockActionDispatcher implements ActionDispatcher {
14 String result;
15 List resultActions;
16 Exception resultException;
17
18 List actionsCalled = new ArrayList();
19 List parametersCalled = new ArrayList();
20 Collection calls = new ArrayList();
21 private boolean delegating;
22 private ActionDispatcher decoratedDispatcher;
23
24 public MockActionDispatcher(boolean delegating) {
25 this.delegating = delegating;
26
27 if (delegating) {
28 decoratedDispatcher = new DefaultActionDispatcher();
29 }
30
31 result = Action.SUCCESS;
32 }
33
34 public ActionResult execute(String actionName) throws Exception {
35 return execute(actionName, null);
36 }
37
38 public ActionResult execute(String actionName, Map parameters) throws Exception {
39 calls.add(new Object[]{"execute", actionName, parameters});
40 actionsCalled.add(actionName);
41 parametersCalled.add(parameters);
42
43 if (delegating)
44 return decoratedDispatcher.execute(actionName, parameters);
45 else
46 return getActionResult();
47 }
48
49 private ActionResult getActionResult() {
50 ActionResult actionResult = new ActionResult(result, null, resultActions, resultException);
51 return actionResult;
52 }
53
54 public List getActionsCalled() {
55 return actionsCalled;
56 }
57
58 public List getParametersCalled() {
59 return parametersCalled;
60 }
61
62 public void setResult(String result) {
63 this.result = result;
64 }
65
66 public void setResultAction(Action action) {
67 resultActions = new ArrayList();
68 resultActions.add(action);
69 }
70
71 public Collection getCalls() {
72 return calls;
73 }
74 }