1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.portletbridge.mock;
17  
18  import java.io.BufferedReader;
19  import java.io.IOException;
20  import java.io.UnsupportedEncodingException;
21  import java.net.URL;
22  import java.security.Principal;
23  import java.util.Enumeration;
24  import java.util.Hashtable;
25  import java.util.Locale;
26  import java.util.Map;
27  
28  import javax.servlet.RequestDispatcher;
29  import javax.servlet.ServletInputStream;
30  import javax.servlet.http.Cookie;
31  import javax.servlet.http.HttpServletRequest;
32  import javax.servlet.http.HttpSession;
33  
34  /***
35   * @author JMcCrindle
36   */
37  public class MockHttpServletRequest implements HttpServletRequest {
38      
39      private HttpSession session = null;
40      private URL url = null;
41      private String contextPath = null;
42      private Hashtable headers = new Hashtable();
43  
44      /***
45       * 
46       */
47      public MockHttpServletRequest() {
48          super();
49      }
50      
51      public void setupSession(HttpSession session) {
52          this.session = session;
53      }
54      
55      public void setupUrl(URL url) {
56          this.url = url;
57      }
58      
59      public void setupContextPath(String contextPath) {
60          this.contextPath = contextPath;
61      }
62      
63      /* (non-Javadoc)
64       * @see javax.servlet.http.HttpServletRequest#getAuthType()
65       */
66      public String getAuthType() {
67          // TODO Auto-generated method stub
68          return null;
69      }
70  
71      /* (non-Javadoc)
72       * @see javax.servlet.http.HttpServletRequest#getCookies()
73       */
74      public Cookie[] getCookies() {
75          // TODO Auto-generated method stub
76          return null;
77      }
78  
79      /* (non-Javadoc)
80       * @see javax.servlet.http.HttpServletRequest#getDateHeader(java.lang.String)
81       */
82      public long getDateHeader(String arg0) {
83          // TODO Auto-generated method stub
84          return 0;
85      }
86  
87      /* (non-Javadoc)
88       * @see javax.servlet.http.HttpServletRequest#getHeader(java.lang.String)
89       */
90      public String getHeader(String name) {
91          return (String) headers.get(name);
92      }
93  
94      /* (non-Javadoc)
95       * @see javax.servlet.http.HttpServletRequest#getHeaders(java.lang.String)
96       */
97      public Enumeration getHeaders(String name) {
98          return null;
99      }
100 
101     /* (non-Javadoc)
102      * @see javax.servlet.http.HttpServletRequest#getHeaderNames()
103      */
104     public Enumeration getHeaderNames() {
105         return headers.keys();
106     }
107 
108     /* (non-Javadoc)
109      * @see javax.servlet.http.HttpServletRequest#getIntHeader(java.lang.String)
110      */
111     public int getIntHeader(String arg0) {
112         // TODO Auto-generated method stub
113         return 0;
114     }
115 
116     /* (non-Javadoc)
117      * @see javax.servlet.http.HttpServletRequest#getMethod()
118      */
119     public String getMethod() {
120         // TODO Auto-generated method stub
121         return null;
122     }
123 
124     /* (non-Javadoc)
125      * @see javax.servlet.http.HttpServletRequest#getPathInfo()
126      */
127     public String getPathInfo() {
128         // TODO Auto-generated method stub
129         return null;
130     }
131 
132     /* (non-Javadoc)
133      * @see javax.servlet.http.HttpServletRequest#getPathTranslated()
134      */
135     public String getPathTranslated() {
136         // TODO Auto-generated method stub
137         return null;
138     }
139 
140     /* (non-Javadoc)
141      * @see javax.servlet.http.HttpServletRequest#getContextPath()
142      */
143     public String getContextPath() {
144         return contextPath;
145     }
146 
147     /* (non-Javadoc)
148      * @see javax.servlet.http.HttpServletRequest#getQueryString()
149      */
150     public String getQueryString() {
151         return url.getQuery();
152     }
153 
154     /* (non-Javadoc)
155      * @see javax.servlet.http.HttpServletRequest#getRemoteUser()
156      */
157     public String getRemoteUser() {
158         // TODO Auto-generated method stub
159         return null;
160     }
161 
162     /* (non-Javadoc)
163      * @see javax.servlet.http.HttpServletRequest#isUserInRole(java.lang.String)
164      */
165     public boolean isUserInRole(String arg0) {
166         // TODO Auto-generated method stub
167         return false;
168     }
169 
170     /* (non-Javadoc)
171      * @see javax.servlet.http.HttpServletRequest#getUserPrincipal()
172      */
173     public Principal getUserPrincipal() {
174         // TODO Auto-generated method stub
175         return null;
176     }
177 
178     /* (non-Javadoc)
179      * @see javax.servlet.http.HttpServletRequest#getRequestedSessionId()
180      */
181     public String getRequestedSessionId() {
182         // TODO Auto-generated method stub
183         return null;
184     }
185 
186     /* (non-Javadoc)
187      * @see javax.servlet.http.HttpServletRequest#getRequestURI()
188      */
189     public String getRequestURI() {
190         return url.getPath();
191     }
192 
193     /* (non-Javadoc)
194      * @see javax.servlet.http.HttpServletRequest#getRequestURL()
195      */
196     public StringBuffer getRequestURL() {
197         return new StringBuffer(url.toString());
198     }
199 
200     /* (non-Javadoc)
201      * @see javax.servlet.http.HttpServletRequest#getServletPath()
202      */
203     public String getServletPath() {
204         // TODO Auto-generated method stub
205         return null;
206     }
207 
208     /* (non-Javadoc)
209      * @see javax.servlet.http.HttpServletRequest#getSession(boolean)
210      */
211     public HttpSession getSession(boolean create) {
212         return session != null ? session : new MockHttpSession();
213     }
214 
215     /* (non-Javadoc)
216      * @see javax.servlet.http.HttpServletRequest#getSession()
217      */
218     public HttpSession getSession() {
219         return session;
220     }
221 
222     /* (non-Javadoc)
223      * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdValid()
224      */
225     public boolean isRequestedSessionIdValid() {
226         // TODO Auto-generated method stub
227         return false;
228     }
229 
230     /* (non-Javadoc)
231      * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromCookie()
232      */
233     public boolean isRequestedSessionIdFromCookie() {
234         // TODO Auto-generated method stub
235         return false;
236     }
237 
238     /* (non-Javadoc)
239      * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromURL()
240      */
241     public boolean isRequestedSessionIdFromURL() {
242         // TODO Auto-generated method stub
243         return false;
244     }
245 
246     /* (non-Javadoc)
247      * @see javax.servlet.http.HttpServletRequest#isRequestedSessionIdFromUrl()
248      */
249     public boolean isRequestedSessionIdFromUrl() {
250         // TODO Auto-generated method stub
251         return false;
252     }
253 
254     /* (non-Javadoc)
255      * @see javax.servlet.ServletRequest#getAttribute(java.lang.String)
256      */
257     public Object getAttribute(String arg0) {
258         // TODO Auto-generated method stub
259         return null;
260     }
261 
262     /* (non-Javadoc)
263      * @see javax.servlet.ServletRequest#getAttributeNames()
264      */
265     public Enumeration getAttributeNames() {
266         // TODO Auto-generated method stub
267         return null;
268     }
269 
270     /* (non-Javadoc)
271      * @see javax.servlet.ServletRequest#getCharacterEncoding()
272      */
273     public String getCharacterEncoding() {
274         // TODO Auto-generated method stub
275         return null;
276     }
277 
278     /* (non-Javadoc)
279      * @see javax.servlet.ServletRequest#setCharacterEncoding(java.lang.String)
280      */
281     public void setCharacterEncoding(String arg0)
282             throws UnsupportedEncodingException {
283         // TODO Auto-generated method stub
284 
285     }
286 
287     /* (non-Javadoc)
288      * @see javax.servlet.ServletRequest#getContentLength()
289      */
290     public int getContentLength() {
291         // TODO Auto-generated method stub
292         return 0;
293     }
294 
295     /* (non-Javadoc)
296      * @see javax.servlet.ServletRequest#getContentType()
297      */
298     public String getContentType() {
299         // TODO Auto-generated method stub
300         return null;
301     }
302 
303     /* (non-Javadoc)
304      * @see javax.servlet.ServletRequest#getInputStream()
305      */
306     public ServletInputStream getInputStream() throws IOException {
307         // TODO Auto-generated method stub
308         return null;
309     }
310 
311     /* (non-Javadoc)
312      * @see javax.servlet.ServletRequest#getParameter(java.lang.String)
313      */
314     public String getParameter(String arg0) {
315         // TODO Auto-generated method stub
316         return null;
317     }
318 
319     /* (non-Javadoc)
320      * @see javax.servlet.ServletRequest#getParameterNames()
321      */
322     public Enumeration getParameterNames() {
323         // TODO Auto-generated method stub
324         return null;
325     }
326 
327     /* (non-Javadoc)
328      * @see javax.servlet.ServletRequest#getParameterValues(java.lang.String)
329      */
330     public String[] getParameterValues(String arg0) {
331         // TODO Auto-generated method stub
332         return null;
333     }
334 
335     /* (non-Javadoc)
336      * @see javax.servlet.ServletRequest#getParameterMap()
337      */
338     public Map getParameterMap() {
339         // TODO Auto-generated method stub
340         return null;
341     }
342 
343     /* (non-Javadoc)
344      * @see javax.servlet.ServletRequest#getProtocol()
345      */
346     public String getProtocol() {
347         // TODO Auto-generated method stub
348         return null;
349     }
350 
351     /* (non-Javadoc)
352      * @see javax.servlet.ServletRequest#getScheme()
353      */
354     public String getScheme() {
355         // TODO Auto-generated method stub
356         return null;
357     }
358 
359     /* (non-Javadoc)
360      * @see javax.servlet.ServletRequest#getServerName()
361      */
362     public String getServerName() {
363         // TODO Auto-generated method stub
364         return null;
365     }
366 
367     /* (non-Javadoc)
368      * @see javax.servlet.ServletRequest#getServerPort()
369      */
370     public int getServerPort() {
371         // TODO Auto-generated method stub
372         return 0;
373     }
374 
375     /* (non-Javadoc)
376      * @see javax.servlet.ServletRequest#getReader()
377      */
378     public BufferedReader getReader() throws IOException {
379         // TODO Auto-generated method stub
380         return null;
381     }
382 
383     /* (non-Javadoc)
384      * @see javax.servlet.ServletRequest#getRemoteAddr()
385      */
386     public String getRemoteAddr() {
387         // TODO Auto-generated method stub
388         return null;
389     }
390 
391     /* (non-Javadoc)
392      * @see javax.servlet.ServletRequest#getRemoteHost()
393      */
394     public String getRemoteHost() {
395         // TODO Auto-generated method stub
396         return null;
397     }
398 
399     /* (non-Javadoc)
400      * @see javax.servlet.ServletRequest#setAttribute(java.lang.String, java.lang.Object)
401      */
402     public void setAttribute(String arg0, Object arg1) {
403         // TODO Auto-generated method stub
404 
405     }
406 
407     /* (non-Javadoc)
408      * @see javax.servlet.ServletRequest#removeAttribute(java.lang.String)
409      */
410     public void removeAttribute(String arg0) {
411         // TODO Auto-generated method stub
412 
413     }
414 
415     /* (non-Javadoc)
416      * @see javax.servlet.ServletRequest#getLocale()
417      */
418     public Locale getLocale() {
419         // TODO Auto-generated method stub
420         return null;
421     }
422 
423     /* (non-Javadoc)
424      * @see javax.servlet.ServletRequest#getLocales()
425      */
426     public Enumeration getLocales() {
427         // TODO Auto-generated method stub
428         return null;
429     }
430 
431     /* (non-Javadoc)
432      * @see javax.servlet.ServletRequest#isSecure()
433      */
434     public boolean isSecure() {
435         // TODO Auto-generated method stub
436         return false;
437     }
438 
439     /* (non-Javadoc)
440      * @see javax.servlet.ServletRequest#getRequestDispatcher(java.lang.String)
441      */
442     public RequestDispatcher getRequestDispatcher(String arg0) {
443         // TODO Auto-generated method stub
444         return null;
445     }
446 
447     /* (non-Javadoc)
448      * @see javax.servlet.ServletRequest#getRealPath(java.lang.String)
449      */
450     public String getRealPath(String arg0) {
451         // TODO Auto-generated method stub
452         return null;
453     }
454 
455 }