001: /*
002: * Copyright (c) 2002-2006 by OpenSymphony
003: * All rights reserved.
004: */
005:
006: package com.opensymphony.xwork.mock;
007:
008: import java.util.ArrayList;
009: import java.util.Iterator;
010: import java.util.List;
011:
012: import com.opensymphony.xwork.ActionInvocation;
013: import com.opensymphony.xwork.ActionContext;
014: import com.opensymphony.xwork.ActionProxy;
015: import com.opensymphony.xwork.Result;
016: import com.opensymphony.xwork.interceptor.PreResultListener;
017: import com.opensymphony.xwork.util.OgnlValueStack;
018:
019: /**
020: * Mock for an {@link ActionInvocation}.
021: *
022: * @author plightbo
023: * @author Rainer Hermanns
024: * @author tm_jee
025: * @version $Id: MockActionInvocation.java 974 2006-04-02 10:00:21Z tmjee $
026: */
027: public class MockActionInvocation implements ActionInvocation {
028:
029: private Object action;
030: private ActionContext invocationContext;
031: private ActionProxy proxy;
032: private Result result;
033: private String resultCode;
034: private OgnlValueStack stack;
035:
036: private List preResultListeners = new ArrayList();
037:
038: public Object getAction() {
039: return action;
040: }
041:
042: public void setAction(Object action) {
043: this .action = action;
044: }
045:
046: public ActionContext getInvocationContext() {
047: return invocationContext;
048: }
049:
050: public void setInvocationContext(ActionContext invocationContext) {
051: this .invocationContext = invocationContext;
052: }
053:
054: public ActionProxy getProxy() {
055: return proxy;
056: }
057:
058: public void setProxy(ActionProxy proxy) {
059: this .proxy = proxy;
060: }
061:
062: public Result getResult() {
063: return result;
064: }
065:
066: public void setResult(Result result) {
067: this .result = result;
068: }
069:
070: public String getResultCode() {
071: return resultCode;
072: }
073:
074: public void setResultCode(String resultCode) {
075: this .resultCode = resultCode;
076: }
077:
078: public OgnlValueStack getStack() {
079: return stack;
080: }
081:
082: public void setStack(OgnlValueStack stack) {
083: this .stack = stack;
084: }
085:
086: public boolean isExecuted() {
087: return false;
088: }
089:
090: public void addPreResultListener(PreResultListener listener) {
091: preResultListeners.add(listener);
092: }
093:
094: public String invoke() throws Exception {
095: for (Iterator i = preResultListeners.iterator(); i.hasNext();) {
096: PreResultListener listener = (PreResultListener) i.next();
097: listener.beforeResult(this , resultCode);
098: }
099: return resultCode;
100: }
101:
102: public String invokeActionOnly() throws Exception {
103: return resultCode;
104: }
105:
106: }
|