001: /*
002: * Copyright (c) 2002-2003 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.webwork.views.jsp;
006:
007: import com.mockobjects.servlet.MockHttpServletRequest;
008: import junit.framework.AssertionFailedError;
009:
010: import javax.servlet.http.HttpSession;
011: import javax.servlet.RequestDispatcher;
012: import java.util.*;
013:
014: /**
015: * WebWorkMockHttpServletRequest
016: *
017: * @author Jason Carreira
018: * Created Mar 28, 2003 10:28:50 PM
019: */
020: public class WebWorkMockHttpServletRequest extends
021: MockHttpServletRequest {
022:
023: Locale locale = Locale.US;
024: private Map attributes = new HashMap();
025: private Map parameterMap = new HashMap();
026: private String context = "";
027: private String pathInfo = "";
028: private String queryString;
029: private String requestURI;
030: private String scheme;
031: private String serverName;
032: private int serverPort;
033: private String encoding;
034: private String requestDispatherString;
035:
036: public void setAttribute(String s, Object o) {
037: attributes.put(s, o);
038: }
039:
040: public Object getAttribute(String s) {
041: return attributes.get(s);
042: }
043:
044: public Enumeration getAttributeNames() {
045: Vector v = new Vector();
046: v.addAll(attributes.keySet());
047:
048: return v.elements();
049: }
050:
051: public String getContextPath() {
052: return this .context;
053: }
054:
055: public void setLocale(Locale locale) {
056: this .locale = locale;
057: }
058:
059: public Locale getLocale() {
060: return locale;
061: }
062:
063: public void setCharacterEncoding(String s) {
064: this .encoding = s;
065: }
066:
067: public String getCharacterEncoding() {
068: return encoding;
069: }
070:
071: public void setParameterMap(Map parameterMap) {
072: this .parameterMap = parameterMap;
073: }
074:
075: public Map getParameterMap() {
076: return parameterMap;
077: }
078:
079: public String getParameter(String string) {
080: return (String) parameterMap.get(string);
081: }
082:
083: public Enumeration getParameterNames() {
084: return Collections.enumeration(parameterMap.keySet());
085: }
086:
087: public String[] getParameterValues(String string) {
088: return (String[]) parameterMap.get(string);
089: }
090:
091: public String getPathInfo() {
092: return pathInfo;
093: }
094:
095: public void setQueryString(String queryString) {
096: this .queryString = queryString;
097: }
098:
099: public String getQueryString() {
100: return queryString;
101: }
102:
103: public RequestDispatcher getRequestDispatcher(String string) {
104: this .requestDispatherString = string;
105: return super .getRequestDispatcher(string);
106: }
107:
108: /**
109: * Get's the source string that was used in the last getRequestDispatcher method call.
110: */
111: public String getRequestDispatherString() {
112: return requestDispatherString;
113: }
114:
115: public void setRequestURI(String requestURI) {
116: this .requestURI = requestURI;
117: }
118:
119: public String getRequestURI() {
120: return requestURI;
121: }
122:
123: public void setScheme(String scheme) {
124: this .scheme = scheme;
125: }
126:
127: public String getScheme() {
128: return scheme;
129: }
130:
131: public void setServerName(String serverName) {
132: this .serverName = serverName;
133: }
134:
135: public String getServerName() {
136: return serverName;
137: }
138:
139: public void setServerPort(int serverPort) {
140: this .serverPort = serverPort;
141: }
142:
143: public int getServerPort() {
144: return serverPort;
145: }
146:
147: public HttpSession getSession() {
148: HttpSession session = null;
149:
150: try {
151: session = super .getSession();
152: } catch (AssertionFailedError e) {
153: //ignore
154: }
155:
156: if (session == null) {
157: session = new WebWorkMockHttpSession();
158: setSession(session);
159: }
160:
161: return session;
162: }
163:
164: public void setupGetContext(String context) {
165: this .context = context;
166: }
167:
168: public void setupGetPathInfo(String pathInfo) {
169: this .pathInfo = pathInfo;
170: }
171:
172: public int getRemotePort() {
173: return 0;
174: }
175:
176: public String getLocalName() {
177: return null;
178: }
179:
180: public String getLocalAddr() {
181: return null;
182: }
183:
184: public int getLocalPort() {
185: return 0;
186: }
187: }
|