KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mockobjects > servlet > MockHttpServletResponse


1 package com.mockobjects.servlet;
2
3 import com.mockobjects.*;
4
5 import javax.servlet.ServletOutputStream JavaDoc;
6 import javax.servlet.http.Cookie JavaDoc;
7 import javax.servlet.http.HttpServletResponse JavaDoc;
8 import java.io.IOException JavaDoc;
9 import java.io.PrintWriter JavaDoc;
10 import java.util.Locale JavaDoc;
11
12 public class MockHttpServletResponse extends MockObject
13     implements HttpServletResponse JavaDoc {
14
15     private final ExpectationList myContentTypes =
16         new ExpectationList("MockHttpServletResponse.setContentType");
17     private final ExpectationList myHeaders =
18         new ExpectationList("MockHttpServletResponse.setHeader");
19     private final ExpectationCounter mySetStatusCalls =
20         new ExpectationCounter("MockHttpServletResponse.setStatus");
21     private final ExpectationList myRedirects =
22         new ExpectationList("MockHttpServletResponse.sendRedirect");
23     private MockServletOutputStream myOutputStream =
24         new MockServletOutputStream();
25     private final ExpectationValue myErrorCode =
26         new ExpectationValue("MockHttpServletResponse.sendError");
27     private final ExpectationValue myErrorMessage =
28         new ExpectationValue("MockHttpServletResponse.sendError");
29     private final ExpectationValue length = new ExpectationValue("MockHttpServletResponse.length");
30
31     /**
32      * Not Implemented
33      */

34     public void addCookie(Cookie JavaDoc arg1) {
35         notImplemented();
36     }
37
38     /**
39      * Not Implemented
40      */

41     public void addDateHeader(String JavaDoc arg1, long arg2) {
42         notImplemented();
43     }
44
45     /**
46      * Not Implemented
47      */

48     public void addHeader(String JavaDoc arg1, String JavaDoc arg2) {
49         notImplemented();
50     }
51
52     /**
53      * Not Implemented
54      */

55     public void addIntHeader(String JavaDoc arg1, int arg2) {
56         notImplemented();
57     }
58
59     /**
60      * Not Implemented
61      */

62     public boolean containsHeader(String JavaDoc arg1) {
63         notImplemented();
64         return false;
65     }
66
67     /**
68      * Not Implemented
69      */

70     public String JavaDoc encodeRedirectUrl(String JavaDoc arg1) {
71         notImplemented();
72         return null;
73     }
74
75     /**
76      * Not Implemented
77      */

78     public String JavaDoc encodeRedirectURL(String JavaDoc arg1) {
79         notImplemented();
80         return null;
81     }
82
83     /**
84      * Not Implemented
85      */

86     public String JavaDoc encodeUrl(String JavaDoc arg1) {
87         notImplemented();
88         return null;
89     }
90
91     /**
92      * Not Implemented
93      */

94     public String JavaDoc encodeURL(String JavaDoc arg1) {
95         notImplemented();
96         return null;
97     }
98
99     /**
100      * Not Implemented
101      */

102     public void flushBuffer() throws java.io.IOException JavaDoc {
103         notImplemented();
104     }
105
106     /**
107      * Not Implemented
108      */

109     public int getBufferSize() {
110         notImplemented();
111         return 0;
112     }
113
114     /**
115      * Not Implemented
116      */

117     public String JavaDoc getCharacterEncoding() {
118         notImplemented();
119         return null;
120     }
121
122     /**
123      * Not Implemented
124      */

125     public Locale JavaDoc getLocale() {
126         notImplemented();
127         return null;
128     }
129
130     public ServletOutputStream JavaDoc getOutputStream()
131         throws IOException JavaDoc {
132         return myOutputStream;
133     }
134
135     public String JavaDoc getOutputStreamContents() {
136         return myOutputStream.getContents();
137     }
138
139     public PrintWriter JavaDoc getWriter() throws IOException JavaDoc {
140         return new PrintWriter JavaDoc(myOutputStream, true);
141     }
142
143     /**
144      * Not Implemented
145      */

146     public boolean isCommitted() {
147         notImplemented();
148         return false;
149     }
150
151     /**
152      * Not Implemented
153      */

154     public void reset() {
155         notImplemented();
156     }
157
158     /**
159      * Not Implemented
160      */

161     public void resetBuffer() {
162         notImplemented();
163     }
164
165     public void setExpectedError(int anErrorCode) {
166         myErrorCode.setExpected(anErrorCode);
167     }
168
169     public void setExpectedError(int anErrorCode, String JavaDoc anErrorMessage) {
170         setExpectedError(anErrorCode);
171         myErrorMessage.setExpected(anErrorMessage);
172     }
173
174     public void setExpectedErrorNothing() {
175         myErrorCode.setExpectNothing();
176         myErrorMessage.setExpectNothing();
177     }
178
179     public void sendError(int anErrorCode) throws java.io.IOException JavaDoc {
180         myErrorCode.setActual(anErrorCode);
181     }
182
183     public void sendError(int anErrorCode, String JavaDoc anErrorMessage)
184         throws IOException JavaDoc {
185         sendError(anErrorCode);
186         myErrorMessage.setActual(anErrorMessage);
187     }
188
189     public void sendRedirect(String JavaDoc aURL) throws java.io.IOException JavaDoc {
190         myRedirects.addActual(aURL);
191     }
192
193     /**
194      * Not Implemented
195      */

196     public void setBufferSize(int arg1) {
197         notImplemented();
198     }
199
200     public void setContentLength(int length) {
201         this.length.setActual(length);
202     }
203
204     public void setExpectedContentLength(int length){
205         this.length.setExpected(length);
206     }
207
208     public void setContentType(String JavaDoc contentType) {
209         myContentTypes.addActual(contentType);
210     }
211
212     /**
213      * Not Implemented
214      */

215     public void setDateHeader(String JavaDoc arg1, long arg2) {
216         notImplemented();
217     }
218
219     public void setExpectedContentType(String JavaDoc contentType) {
220         myContentTypes.addExpected(contentType);
221     }
222
223     public void setExpectedHeader(String JavaDoc key, String JavaDoc value) {
224         myHeaders.addExpected(new MapEntry(key, value));
225     }
226
227     public void setExpectedRedirect(String JavaDoc aURL) throws IOException JavaDoc {
228         myRedirects.addExpected(aURL);
229     }
230
231     public void setExpectedSetStatusCalls(int callCount) {
232         mySetStatusCalls.setExpected(callCount);
233     }
234
235     public void setHeader(String JavaDoc key, String JavaDoc value) {
236         myHeaders.addActual(new MapEntry(key, value));
237     }
238
239     /**
240      * Not Implemented
241      */

242     public void setIntHeader(String JavaDoc arg1, int arg2) {
243         notImplemented();
244     }
245
246     /**
247      * Not Implemented
248      */

249     public void setLocale(Locale JavaDoc arg1) {
250         notImplemented();
251     }
252
253     public void setStatus(int status) {
254         mySetStatusCalls.inc();
255     }
256
257     /**
258      * Not Implemented
259      */

260     public void setStatus(int arg1, String JavaDoc arg2) {
261         notImplemented();
262     }
263
264     public void setupOutputStream(MockServletOutputStream anOutputStream) {
265         myOutputStream = anOutputStream;
266     }
267 }
268
Popular Tags