KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > servletunit > struts > StrutsResponseWrapper


1 // StrutsTestCase - a JUnit extension for testing Struts actions
2
// within the context of the ActionServlet.
3
// Copyright (C) 2002 Deryl Seale
4
//
5
// This library is free software; you can redistribute it and/or
6
// modify it under the terms of the Apache Software License as
7
// published by the Apache Software Foundation; either version 1.1
8
// of the License, or (at your option) any later version.
9
//
10
// This library is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// Apache Software Foundation Licens for more details.
14
//
15
// You may view the full text here: http://www.apache.org/LICENSE.txt
16

17 package servletunit.struts;
18
19 import javax.servlet.ServletOutputStream JavaDoc;
20 import javax.servlet.http.Cookie JavaDoc;
21 import javax.servlet.http.HttpServletResponse JavaDoc;
22 import java.io.IOException JavaDoc;
23 import java.io.PrintWriter JavaDoc;
24 import java.util.Locale JavaDoc;
25
26 /**
27  * A wrapper for the HttpServletResponse class. This is used in
28  * CactusStrutsTestCase so that we can retrieve the redirect URL
29  * set by the ActionServlet in processing an action. This allows
30  * us to use the ActionServlet as a black box, rather than mimic
31  * its behavior as was previously the case.
32  */

33 public class StrutsResponseWrapper implements HttpServletResponse JavaDoc
34 {
35
36     private HttpServletResponse JavaDoc response;
37     private String JavaDoc redirectLocation;
38
39     public StrutsResponseWrapper(HttpServletResponse JavaDoc response) {
40         this.response = response;
41     }
42
43     public void addCookie(Cookie JavaDoc cookie)
44     {
45         this.response.addCookie(cookie);
46     }
47
48     public void addDateHeader(String JavaDoc name, long date)
49     {
50         this.response.addDateHeader(name,date);
51     }
52
53     public void addHeader(String JavaDoc name, String JavaDoc value)
54     {
55         this.response.addHeader(name,value);
56     }
57
58     public void addIntHeader(String JavaDoc name, int value)
59     {
60         this.response.addIntHeader(name,value);
61     }
62
63     public boolean containsHeader(String JavaDoc name)
64     {
65         return this.response.containsHeader(name);
66     }
67
68     public String JavaDoc encodeRedirectUrl(String JavaDoc url)
69     {
70         return this.response.encodeRedirectUrl(url);
71     }
72
73     public String JavaDoc encodeRedirectURL(String JavaDoc url)
74     {
75         return this.response.encodeRedirectURL(url);
76     }
77
78     public String JavaDoc encodeUrl(String JavaDoc url)
79     {
80         return this.response.encodeUrl(url);
81     }
82
83     public String JavaDoc encodeURL(String JavaDoc url)
84     {
85         return this.response.encodeURL(url);
86     }
87
88     public void flushBuffer() throws IOException JavaDoc
89     {
90         this.response.flushBuffer();
91     }
92
93     public int getBufferSize()
94     {
95         return this.response.getBufferSize();
96     }
97
98     public String JavaDoc getCharacterEncoding()
99     {
100         return this.response.getCharacterEncoding();
101     }
102
103     public Locale JavaDoc getLocale()
104     {
105         return this.response.getLocale();
106     }
107
108     public ServletOutputStream JavaDoc getOutputStream() throws IOException JavaDoc
109     {
110         return this.response.getOutputStream();
111     }
112
113     public PrintWriter JavaDoc getWriter() throws IOException JavaDoc
114     {
115         return this.response.getWriter();
116     }
117
118     public boolean isCommitted()
119     {
120         return this.response.isCommitted();
121     }
122
123     public void reset()
124     {
125         this.response.reset();
126     }
127
128     public void resetBuffer()
129     {
130     }
131
132     public void sendError(int sc) throws IOException JavaDoc
133     {
134         this.response.sendError(sc);
135     }
136
137     public void sendError(int sc, String JavaDoc msg) throws IOException JavaDoc
138     {
139         this.response.sendError(sc,msg);
140     }
141
142     public void sendRedirect(String JavaDoc location) throws IOException JavaDoc
143     {
144         this.redirectLocation = location;
145         this.response.sendRedirect(location);
146     }
147
148     public void setBufferSize(int size)
149     {
150         this.response.setBufferSize(size);
151     }
152
153     public void setContentLength(int len)
154     {
155         this.response.setContentLength(len);
156     }
157
158     public void setContentType(String JavaDoc type)
159     {
160         this.response.setContentType(type);
161     }
162
163     public void setDateHeader(String JavaDoc name, long date)
164     {
165         this.response.setDateHeader(name,date);
166     }
167
168     public void setHeader(String JavaDoc name, String JavaDoc value)
169     {
170         this.response.setHeader(name,value);
171     }
172
173     public void setIntHeader(String JavaDoc name, int value)
174     {
175         this.response.setIntHeader(name,value);
176     }
177
178     public void setStatus(int sc)
179     {
180         this.response.setStatus(sc);
181     }
182
183     public void setStatus(int sc, String JavaDoc sm)
184     {
185         this.response.setStatus(sc,sm);
186     }
187
188     public void setLocale(Locale JavaDoc loc)
189     {
190         this.response.setLocale(loc);
191     }
192
193     public String JavaDoc getRedirectLocation() {
194         return this.redirectLocation;
195     }
196
197 }
198
199
Popular Tags