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