001: // StrutsTestCase - a JUnit extension for testing Struts actions
002: // within the context of the ActionServlet.
003: // Copyright (C) 2002 Deryl Seale
004: //
005: // This library is free software; you can redistribute it and/or
006: // modify it under the terms of the Apache Software License as
007: // published by the Apache Software Foundation; either version 1.1
008: // of the License, or (at your option) any later version.
009: //
010: // This library is distributed in the hope that it will be useful,
011: // but WITHOUT ANY WARRANTY; without even the implied warranty of
012: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: // Apache Software Foundation Licens for more details.
014: //
015: // You may view the full text here: http://www.apache.org/LICENSE.txt
016:
017: package servletunit.struts;
018:
019: import javax.servlet.ServletOutputStream;
020: import javax.servlet.http.Cookie;
021: import javax.servlet.http.HttpServletResponse;
022: import java.io.IOException;
023: import java.io.PrintWriter;
024: import java.util.Locale;
025:
026: /**
027: * A wrapper for the HttpServletResponse class. This is used in
028: * CactusStrutsTestCase so that we can retrieve the redirect URL
029: * set by the ActionServlet in processing an action. This allows
030: * us to use the ActionServlet as a black box, rather than mimic
031: * its behavior as was previously the case.
032: */
033: public class StrutsResponseWrapper implements HttpServletResponse {
034:
035: private HttpServletResponse response;
036: private String redirectLocation;
037:
038: public StrutsResponseWrapper(HttpServletResponse response) {
039: this .response = response;
040: }
041:
042: public void addCookie(Cookie cookie) {
043: this .response.addCookie(cookie);
044: }
045:
046: public void addDateHeader(String name, long date) {
047: this .response.addDateHeader(name, date);
048: }
049:
050: public void addHeader(String name, String value) {
051: this .response.addHeader(name, value);
052: }
053:
054: public void addIntHeader(String name, int value) {
055: this .response.addIntHeader(name, value);
056: }
057:
058: public boolean containsHeader(String name) {
059: return this .response.containsHeader(name);
060: }
061:
062: public String encodeRedirectUrl(String url) {
063: return this .response.encodeRedirectUrl(url);
064: }
065:
066: public String encodeRedirectURL(String url) {
067: return this .response.encodeRedirectURL(url);
068: }
069:
070: public String encodeUrl(String url) {
071: return this .response.encodeUrl(url);
072: }
073:
074: public String encodeURL(String url) {
075: return this .response.encodeURL(url);
076: }
077:
078: public void flushBuffer() throws IOException {
079: this .response.flushBuffer();
080: }
081:
082: public int getBufferSize() {
083: return this .response.getBufferSize();
084: }
085:
086: public String getCharacterEncoding() {
087: return this .response.getCharacterEncoding();
088: }
089:
090: public Locale getLocale() {
091: return this .response.getLocale();
092: }
093:
094: public ServletOutputStream getOutputStream() throws IOException {
095: return this .response.getOutputStream();
096: }
097:
098: public PrintWriter getWriter() throws IOException {
099: return this .response.getWriter();
100: }
101:
102: public boolean isCommitted() {
103: return this .response.isCommitted();
104: }
105:
106: public void reset() {
107: this .response.reset();
108: }
109:
110: public void resetBuffer() {
111: this .response.resetBuffer();
112: }
113:
114: public void sendError(int sc) throws IOException {
115: this .response.sendError(sc);
116: }
117:
118: public void sendError(int sc, String msg) throws IOException {
119: this .response.sendError(sc, msg);
120: }
121:
122: public void sendRedirect(String location) throws IOException {
123: this .redirectLocation = location;
124: this .response.sendRedirect(location);
125: }
126:
127: public void setBufferSize(int size) {
128: this .response.setBufferSize(size);
129: }
130:
131: public void setContentLength(int len) {
132: this .response.setContentLength(len);
133: }
134:
135: public void setContentType(String type) {
136: this .response.setContentType(type);
137: }
138:
139: public void setDateHeader(String name, long date) {
140: this .response.setDateHeader(name, date);
141: }
142:
143: public void setHeader(String name, String value) {
144: this .response.setHeader(name, value);
145: }
146:
147: public void setIntHeader(String name, int value) {
148: this .response.setIntHeader(name, value);
149: }
150:
151: public void setStatus(int sc) {
152: this .response.setStatus(sc);
153: }
154:
155: public void setStatus(int sc, String sm) {
156: this .response.setStatus(sc, sm);
157: }
158:
159: public void setLocale(Locale loc) {
160: this .response.setLocale(loc);
161: }
162:
163: public String getRedirectLocation() {
164: return this.redirectLocation;
165: }
166:
167: }
|