1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts2.views.jsp;
23
24 import java.util.Collections;
25 import java.util.Enumeration;
26 import java.util.HashMap;
27 import java.util.Locale;
28 import java.util.Map;
29 import java.util.Vector;
30
31 import javax.servlet.RequestDispatcher;
32 import javax.servlet.http.HttpSession;
33
34 import junit.framework.AssertionFailedError;
35
36 import com.mockobjects.servlet.MockHttpServletRequest;
37
38
39 /***
40 * StrutsMockHttpServletRequest
41 *
42 */
43 public class StrutsMockHttpServletRequest extends MockHttpServletRequest {
44
45 Locale locale = Locale.US;
46 private Map attributes = new HashMap();
47 private Map parameterMap = new HashMap();
48 private String context = "";
49 private String pathInfo = "";
50 private String queryString;
51 private String requestURI;
52 private String scheme;
53 private String serverName;
54 private int serverPort;
55 private String encoding;
56 private String requestDispatherString;
57
58
59 public void setAttribute(String s, Object o) {
60 attributes.put(s, o);
61 }
62
63 public Object getAttribute(String s) {
64 return attributes.get(s);
65 }
66
67 public Enumeration getAttributeNames() {
68 Vector v = new Vector();
69 v.addAll(attributes.keySet());
70
71 return v.elements();
72 }
73
74 public String getContextPath() {
75 return this.context;
76 }
77
78 public void setLocale(Locale locale) {
79 this.locale = locale;
80 }
81
82 public Locale getLocale() {
83 return locale;
84 }
85
86 public void setCharacterEncoding(String s) {
87 this.encoding = s;
88 }
89
90 public String getCharacterEncoding() {
91 return encoding;
92 }
93
94 public void setParameterMap(Map parameterMap) {
95 this.parameterMap = parameterMap;
96 }
97
98 public Map getParameterMap() {
99 return parameterMap;
100 }
101
102 public String getParameter(String string) {
103 return (String) parameterMap.get(string);
104 }
105
106 public Enumeration getParameterNames() {
107 return Collections.enumeration(parameterMap.keySet());
108 }
109
110 public String[] getParameterValues(String string) {
111 return (String[]) parameterMap.get(string);
112 }
113
114 public String getPathInfo() {
115 return pathInfo;
116 }
117
118 public void setQueryString(String queryString) {
119 this.queryString = queryString;
120 }
121
122 public String getQueryString() {
123 return queryString;
124 }
125
126 public RequestDispatcher getRequestDispatcher(String string) {
127 this.requestDispatherString = string;
128 return super.getRequestDispatcher(string);
129 }
130
131 /***
132 * Get's the source string that was used in the last getRequestDispatcher method call.
133 */
134 public String getRequestDispatherString() {
135 return requestDispatherString;
136 }
137
138 public void setRequestURI(String requestURI) {
139 this.requestURI = requestURI;
140 }
141
142 public String getRequestURI() {
143 return requestURI;
144 }
145
146 public void setScheme(String scheme) {
147 this.scheme = scheme;
148 }
149
150 public String getScheme() {
151 return scheme;
152 }
153
154 public void setServerName(String serverName) {
155 this.serverName = serverName;
156 }
157
158 public String getServerName() {
159 return serverName;
160 }
161
162 public void setServerPort(int serverPort) {
163 this.serverPort = serverPort;
164 }
165
166 public int getServerPort() {
167 return serverPort;
168 }
169
170 public HttpSession getSession() {
171 HttpSession session = null;
172
173 try {
174 session = super.getSession();
175 } catch (AssertionFailedError e) {
176
177 }
178
179 if (session == null) {
180 session = new StrutsMockHttpSession();
181 setSession(session);
182 }
183
184 return session;
185 }
186
187 public void setupGetContext(String context) {
188 this.context = context;
189 }
190
191 public void setupGetPathInfo(String pathInfo) {
192 this.pathInfo = pathInfo;
193 }
194
195 public int getRemotePort() {
196 return 0;
197 }
198
199 public String getLocalName() {
200 return null;
201 }
202
203 public String getLocalAddr() {
204 return null;
205 }
206
207 public int getLocalPort() {
208 return 0;
209 }
210 }