KickJava   Java API By Example, From Geeks To Geeks.

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


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.IOException JavaDoc;
40 import java.io.PrintWriter JavaDoc;
41 import java.io.StringWriter JavaDoc;
42 import java.util.Locale JavaDoc;
43
44 import javax.servlet.ServletOutputStream JavaDoc;
45 import javax.servlet.http.Cookie JavaDoc;
46 import javax.servlet.http.HttpServletResponse JavaDoc;
47
48 /**
49  * @author Jeffrey Fredrick
50  */

51 public class MockServletResponse implements HttpServletResponse JavaDoc {
52     private StringWriter JavaDoc stringWriter = new StringWriter JavaDoc();
53     private PrintWriter JavaDoc writer = new PrintWriter JavaDoc(stringWriter);
54     private String JavaDoc contentType;
55     private int status;
56     private ServletOutputStream JavaDoc outputStream = new MockServletOutputStream(stringWriter);
57
58     public String JavaDoc getContentType() {
59         return contentType;
60     }
61
62     public int getStatus() {
63         return status;
64     }
65
66     public String JavaDoc getWritten() {
67         return stringWriter.getBuffer().toString();
68     }
69
70     /* (non-Javadoc)
71      * @see javax.servlet.http.HttpServletResponse#addCookie(javax.servlet.http.Cookie)
72      */

73     public void addCookie(Cookie JavaDoc arg0) {
74     }
75
76     /* (non-Javadoc)
77      * @see javax.servlet.http.HttpServletResponse#containsHeader(java.lang.String)
78      */

79     public boolean containsHeader(String JavaDoc arg0) {
80         return false;
81     }
82
83     /* (non-Javadoc)
84      * @see javax.servlet.http.HttpServletResponse#encodeURL(java.lang.String)
85      */

86     public String JavaDoc encodeURL(String JavaDoc arg0) {
87         return null;
88     }
89
90     /* (non-Javadoc)
91      * @see javax.servlet.http.HttpServletResponse#encodeRedirectURL(java.lang.String)
92      */

93     public String JavaDoc encodeRedirectURL(String JavaDoc arg0) {
94         return null;
95     }
96
97     /* (non-Javadoc)
98      * @see javax.servlet.http.HttpServletResponse#encodeUrl(java.lang.String)
99      */

100     public String JavaDoc encodeUrl(String JavaDoc arg0) {
101         return null;
102     }
103
104     /* (non-Javadoc)
105      * @see javax.servlet.http.HttpServletResponse#encodeRedirectUrl(java.lang.String)
106      */

107     public String JavaDoc encodeRedirectUrl(String JavaDoc arg0) {
108         return null;
109     }
110
111     /* (non-Javadoc)
112      * @see javax.servlet.http.HttpServletResponse#sendError(int, java.lang.String)
113      */

114     public void sendError(int arg0, String JavaDoc arg1) throws IOException JavaDoc {
115     }
116
117     /* (non-Javadoc)
118      * @see javax.servlet.http.HttpServletResponse#sendError(int)
119      */

120     public void sendError(int arg0) throws IOException JavaDoc {
121     }
122
123     /* (non-Javadoc)
124      * @see javax.servlet.http.HttpServletResponse#sendRedirect(java.lang.String)
125      */

126     public void sendRedirect(String JavaDoc arg0) throws IOException JavaDoc {
127     }
128
129     /* (non-Javadoc)
130      * @see javax.servlet.http.HttpServletResponse#setDateHeader(java.lang.String, long)
131      */

132     public void setDateHeader(String JavaDoc arg0, long arg1) {
133     }
134
135     /* (non-Javadoc)
136      * @see javax.servlet.http.HttpServletResponse#addDateHeader(java.lang.String, long)
137      */

138     public void addDateHeader(String JavaDoc arg0, long arg1) {
139     }
140
141     /* (non-Javadoc)
142      * @see javax.servlet.http.HttpServletResponse#setHeader(java.lang.String, java.lang.String)
143      */

144     public void setHeader(String JavaDoc arg0, String JavaDoc arg1) {
145     }
146
147     /* (non-Javadoc)
148      * @see javax.servlet.http.HttpServletResponse#addHeader(java.lang.String, java.lang.String)
149      */

150     public void addHeader(String JavaDoc arg0, String JavaDoc arg1) {
151     }
152
153     /* (non-Javadoc)
154      * @see javax.servlet.http.HttpServletResponse#setIntHeader(java.lang.String, int)
155      */

156     public void setIntHeader(String JavaDoc arg0, int arg1) {
157     }
158
159     /* (non-Javadoc)
160      * @see javax.servlet.http.HttpServletResponse#addIntHeader(java.lang.String, int)
161      */

162     public void addIntHeader(String JavaDoc arg0, int arg1) {
163     }
164
165     /* (non-Javadoc)
166      * @see javax.servlet.http.HttpServletResponse#setStatus(int)
167      */

168     public void setStatus(int arg0) {
169         status = arg0;
170     }
171
172     /* (non-Javadoc)
173      * @see javax.servlet.http.HttpServletResponse#setStatus(int, java.lang.String)
174      */

175     public void setStatus(int arg0, String JavaDoc arg1) {
176         status = arg0;
177     }
178
179     /* (non-Javadoc)
180      * @see javax.servlet.ServletResponse#getCharacterEncoding()
181      */

182     public String JavaDoc getCharacterEncoding() {
183         return null;
184     }
185
186     /* (non-Javadoc)
187      * @see javax.servlet.ServletResponse#getOutputStream()
188      */

189     public ServletOutputStream JavaDoc getOutputStream() throws IOException JavaDoc {
190         return outputStream;
191     }
192
193     /* (non-Javadoc)
194      * @see javax.servlet.ServletResponse#getWriter()
195      */

196     public PrintWriter JavaDoc getWriter() throws IOException JavaDoc {
197         return writer;
198     }
199
200     /* (non-Javadoc)
201      * @see javax.servlet.ServletResponse#setContentLength(int)
202      */

203     public void setContentLength(int arg0) {
204     }
205
206     /* (non-Javadoc)
207      * @see javax.servlet.ServletResponse#setContentType(java.lang.String)
208      */

209     public void setContentType(String JavaDoc type) {
210         contentType = type;
211     }
212
213     /* (non-Javadoc)
214      * @see javax.servlet.ServletResponse#setBufferSize(int)
215      */

216     public void setBufferSize(int arg0) {
217     }
218
219     /* (non-Javadoc)
220      * @see javax.servlet.ServletResponse#getBufferSize()
221      */

222     public int getBufferSize() {
223         return 0;
224     }
225
226     /* (non-Javadoc)
227      * @see javax.servlet.ServletResponse#flushBuffer()
228      */

229     public void flushBuffer() throws IOException JavaDoc {
230     }
231
232     /* (non-Javadoc)
233      * @see javax.servlet.ServletResponse#isCommitted()
234      */

235     public boolean isCommitted() {
236         return false;
237     }
238
239     /* (non-Javadoc)
240      * @see javax.servlet.ServletResponse#reset()
241      */

242     public void reset() {
243     }
244
245     /* (non-Javadoc)
246      * @see javax.servlet.ServletResponse#setLocale(java.util.Locale)
247      */

248     public void setLocale(Locale JavaDoc arg0) {
249     }
250
251     /* (non-Javadoc)
252      * @see javax.servlet.ServletResponse#getLocale()
253      */

254     public Locale JavaDoc getLocale() {
255         return null;
256     }
257 }
258
Popular Tags