KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > mock > MockServletRequest


1 /********************************************************************************
2  * CruiseControl, a Continuous Integration Toolkit
3  * Copyright (c) 2003, ThoughtWorks, Inc.
4  * 651 W Washington Ave. Suite 600
5  * Chicago, IL 60661 USA
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * + Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * + Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  *
20  * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
21  * names of its contributors may be used to endorse or promote
22  * products derived from this software without specific prior
23  * written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  ********************************************************************************/

37 package net.sourceforge.cruisecontrol.mock;
38
39 import java.io.BufferedReader JavaDoc;
40 import java.io.IOException JavaDoc;
41 import java.security.Principal JavaDoc;
42 import java.util.Enumeration JavaDoc;
43 import java.util.Locale JavaDoc;
44 import java.util.Map JavaDoc;
45 import java.util.HashMap JavaDoc;
46 import java.util.Collections JavaDoc;
47 import java.util.ArrayList JavaDoc;
48 import javax.servlet.RequestDispatcher JavaDoc;
49 import javax.servlet.ServletInputStream JavaDoc;
50 import javax.servlet.http.Cookie JavaDoc;
51 import javax.servlet.http.HttpServletRequest JavaDoc;
52 import javax.servlet.http.HttpSession JavaDoc;
53
54 /**
55  *
56  * @author <a HREF="mailto:robertdw@sourceforge.net">Robert Watkins</a>
57  */

58 public class MockServletRequest implements HttpServletRequest JavaDoc {
59     private String JavaDoc contextPath = "";
60     private String JavaDoc servletPath;
61     private Map JavaDoc params = new HashMap JavaDoc();
62     private String JavaDoc pathInfo;
63     private Locale JavaDoc locale;
64
65     public MockServletRequest() {
66     }
67
68     public MockServletRequest(String JavaDoc contextPath, String JavaDoc servletPath) {
69         this.contextPath = contextPath;
70         this.servletPath = servletPath;
71     }
72
73     public Object JavaDoc getAttribute(String JavaDoc name) {
74         return null;
75     }
76
77     public Enumeration JavaDoc getAttributeNames() {
78         return null;
79     }
80
81     public String JavaDoc getCharacterEncoding() {
82         return null;
83     }
84
85     public int getContentLength() {
86         return 0;
87     }
88
89     public String JavaDoc getContentType() {
90         return null;
91     }
92
93     public ServletInputStream JavaDoc getInputStream() throws IOException JavaDoc {
94         return null;
95     }
96
97     public String JavaDoc getParameter(String JavaDoc paramName) {
98         ArrayList JavaDoc values = (ArrayList JavaDoc) params.get(paramName);
99         if (values == null || values.isEmpty()) {
100             return null; // param not found
101
}
102         return (String JavaDoc) values.get(0);
103     }
104
105     public Enumeration JavaDoc getParameterNames() {
106         return Collections.enumeration(params.keySet());
107     }
108
109     public String JavaDoc[] getParameterValues(String JavaDoc paramName) {
110         ArrayList JavaDoc values = (ArrayList JavaDoc) params.get(paramName);
111         if (values == null || values.isEmpty()) {
112             return null; // param not found
113
}
114         return (String JavaDoc[]) values.toArray(new String JavaDoc[] {});
115     }
116
117     public String JavaDoc getProtocol() {
118         return null;
119     }
120
121     public String JavaDoc getScheme() {
122         return null;
123     }
124
125     public String JavaDoc getServerName() {
126         return null;
127     }
128
129     public int getServerPort() {
130         return 0;
131     }
132
133     public BufferedReader JavaDoc getReader() throws IOException JavaDoc {
134         return null;
135     }
136
137     public String JavaDoc getRemoteAddr() {
138         return null;
139     }
140
141     public String JavaDoc getRemoteHost() {
142         return null;
143     }
144
145     public void setAttribute(String JavaDoc s, Object JavaDoc o) {
146     }
147
148     public void removeAttribute(String JavaDoc s) {
149     }
150
151     public Locale JavaDoc getLocale() {
152         return locale;
153     }
154
155     public Enumeration JavaDoc getLocales() {
156         return null;
157     }
158
159     public boolean isSecure() {
160         return false;
161     }
162
163     public RequestDispatcher JavaDoc getRequestDispatcher(String JavaDoc s) {
164         return null;
165     }
166
167     public String JavaDoc getRealPath(String JavaDoc s) {
168         return null;
169     }
170
171     public String JavaDoc getAuthType() {
172         return null;
173     }
174
175     public Cookie JavaDoc[] getCookies() {
176         return new Cookie JavaDoc[0];
177     }
178
179     public long getDateHeader(String JavaDoc s) {
180         return 0;
181     }
182
183     public String JavaDoc getHeader(String JavaDoc s) {
184         return null;
185     }
186
187     public Enumeration JavaDoc getHeaders(String JavaDoc s) {
188         return null;
189     }
190
191     public Enumeration JavaDoc getHeaderNames() {
192         return null;
193     }
194
195     public int getIntHeader(String JavaDoc s) {
196         return 0;
197     }
198
199     public String JavaDoc getMethod() {
200         return null;
201     }
202
203     public String JavaDoc getPathInfo() {
204         return pathInfo;
205     }
206
207     public String JavaDoc getPathTranslated() {
208         return null;
209     }
210
211     public String JavaDoc getContextPath() {
212         return (contextPath.length() == 0 ? "" : "/" + contextPath);
213     }
214
215     public String JavaDoc getQueryString() {
216         return null;
217     }
218
219     public String JavaDoc getRemoteUser() {
220         return null;
221     }
222
223     public boolean isUserInRole(String JavaDoc s) {
224         return false;
225     }
226
227     public Principal JavaDoc getUserPrincipal() {
228         return null;
229     }
230
231     public String JavaDoc getRequestedSessionId() {
232         return null;
233     }
234
235     public String JavaDoc getRequestURI() {
236         return null;
237     }
238
239     public String JavaDoc getServletPath() {
240         return "/" + servletPath;
241     }
242
243     public HttpSession JavaDoc getSession(boolean b) {
244         return null;
245     }
246
247     public HttpSession JavaDoc getSession() {
248         return null;
249     }
250
251     public boolean isRequestedSessionIdValid() {
252         return false;
253     }
254
255     public boolean isRequestedSessionIdFromCookie() {
256         return false;
257     }
258
259     public boolean isRequestedSessionIdFromURL() {
260         return false;
261     }
262
263     public boolean isRequestedSessionIdFromUrl() {
264         return false;
265     }
266
267     public void addParameter(String JavaDoc paramName, String JavaDoc paramValue) {
268         ArrayList JavaDoc values = (ArrayList JavaDoc) params.get(paramName);
269         if (values == null) {
270             values = new ArrayList JavaDoc();
271             params.put(paramName, values);
272         }
273         values.add(paramValue);
274     }
275     
276     public ArrayList JavaDoc removeParameter(String JavaDoc paramName) {
277         ArrayList JavaDoc values = (ArrayList JavaDoc) params.remove(paramName);
278         return values;
279     }
280
281     public void setPathInfo(String JavaDoc info) {
282         pathInfo = info;
283     }
284
285     /**
286      * @param locale
287      */

288     public void setLocale(Locale JavaDoc locale) {
289         this.locale = locale;
290     }
291 }
292
Popular Tags