org.apache.struts.mock
Class MockPageContext

java.lang.Object
  extended by javax.servlet.jsp.PageContext
      extended by org.apache.struts.mock.MockPageContext

public class MockPageContext
extends javax.servlet.jsp.PageContext

Mock ServletContext object for low-level unit tests of Struts controller components. Coarser grained tests should be implemented in terms of the Cactus framework, instead of the mock object classes.

WARNING - Only the minimal set of methods needed to create unit tests is provided, plus additional methods to configure this object as necessary. Methods for unsupported operations will throw UnsupportedOperationException.

WARNING - Because unit tests operate in a single threaded environment, no synchronization is performed.

Version:
$Rev: 471754 $ $Date: 2005-05-07 12:45:39 -0400 (Sat, 07 May 2005) $

Field Summary
protected  javax.servlet.ServletContext application
           
protected  java.util.HashMap attributes
           
protected  javax.servlet.ServletConfig config
           
protected  javax.servlet.ServletRequest request
           
protected  javax.servlet.ServletResponse response
           
protected  javax.servlet.http.HttpSession session
           
 
Fields inherited from class javax.servlet.jsp.PageContext
APPLICATION, APPLICATION_SCOPE, CONFIG, EXCEPTION, OUT, PAGE, PAGE_SCOPE, PAGECONTEXT, REQUEST, REQUEST_SCOPE, RESPONSE, SESSION, SESSION_SCOPE
 
Constructor Summary
MockPageContext()
           
MockPageContext(boolean throwIOException, boolean returnBody)
           Construct a new PageContext impl.
MockPageContext(javax.servlet.ServletConfig config, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)
           
 
Method Summary
 java.lang.Object findAttribute(java.lang.String name)
           
 void forward(java.lang.String path)
           
 java.lang.Object getAttribute(java.lang.String name)
           
 java.lang.Object getAttribute(java.lang.String name, int scope)
           
 java.util.Enumeration getAttributeNamesInScope(int scope)
           
 int getAttributesScope(java.lang.String name)
           
 java.lang.Exception getException()
           
 javax.servlet.jsp.JspWriter getOut()
           Custom JspWriter that throws the specified exception (supplied on the constructor...if any), else it simply returns.
 java.lang.Object getPage()
           
 javax.servlet.ServletRequest getRequest()
           
 javax.servlet.ServletResponse getResponse()
           
 javax.servlet.ServletConfig getServletConfig()
           
 javax.servlet.ServletContext getServletContext()
           
 javax.servlet.http.HttpSession getSession()
           
 void handlePageException(java.lang.Exception e)
           
 void handlePageException(java.lang.Throwable t)
           
 void include(java.lang.String path)
           
 void initialize(javax.servlet.Servlet servlet, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, java.lang.String errorPageURL, boolean needsSession, int bufferSize, boolean autoFlush)
           
 javax.servlet.jsp.JspWriter popBody()
           
 javax.servlet.jsp.tagext.BodyContent pushBody()
           
 void release()
           
 void removeAttribute(java.lang.String name)
           
 void removeAttribute(java.lang.String name, int scope)
           
 void setAttribute(java.lang.String name, java.lang.Object value)
           
 void setAttribute(java.lang.String name, java.lang.Object value, int scope)
           
 void setValues(javax.servlet.ServletConfig config, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

application

protected javax.servlet.ServletContext application

attributes

protected java.util.HashMap attributes

config

protected javax.servlet.ServletConfig config

request

protected javax.servlet.ServletRequest request

response

protected javax.servlet.ServletResponse response

session

protected javax.servlet.http.HttpSession session
Constructor Detail

MockPageContext

public MockPageContext()

MockPageContext

public MockPageContext(javax.servlet.ServletConfig config,
                       javax.servlet.ServletRequest request,
                       javax.servlet.ServletResponse response)

MockPageContext

public MockPageContext(boolean throwIOException,
                       boolean returnBody)

Construct a new PageContext impl.

Parameters:
throwIOException - Determines if the returned JspWriter should throw an IOException on any method call.
returnBody - Determines if getOut() should return a new JspWriter or a BodyContent.
Method Detail

setValues

public void setValues(javax.servlet.ServletConfig config,
                      javax.servlet.ServletRequest request,
                      javax.servlet.ServletResponse response)

findAttribute

public java.lang.Object findAttribute(java.lang.String name)
Specified by:
findAttribute in class javax.servlet.jsp.PageContext

forward

public void forward(java.lang.String path)
Specified by:
forward in class javax.servlet.jsp.PageContext

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Specified by:
getAttribute in class javax.servlet.jsp.PageContext

getAttribute

public java.lang.Object getAttribute(java.lang.String name,
                                     int scope)
Specified by:
getAttribute in class javax.servlet.jsp.PageContext

getAttributeNamesInScope

public java.util.Enumeration getAttributeNamesInScope(int scope)
Specified by:
getAttributeNamesInScope in class javax.servlet.jsp.PageContext

getAttributesScope

public int getAttributesScope(java.lang.String name)
Specified by:
getAttributesScope in class javax.servlet.jsp.PageContext

getException

public java.lang.Exception getException()
Specified by:
getException in class javax.servlet.jsp.PageContext

getOut

public javax.servlet.jsp.JspWriter getOut()

Custom JspWriter that throws the specified exception (supplied on the constructor...if any), else it simply returns.

Specified by:
getOut in class javax.servlet.jsp.PageContext

getPage

public java.lang.Object getPage()
Specified by:
getPage in class javax.servlet.jsp.PageContext

getRequest

public javax.servlet.ServletRequest getRequest()
Specified by:
getRequest in class javax.servlet.jsp.PageContext

getResponse

public javax.servlet.ServletResponse getResponse()
Specified by:
getResponse in class javax.servlet.jsp.PageContext

getServletConfig

public javax.servlet.ServletConfig getServletConfig()
Specified by:
getServletConfig in class javax.servlet.jsp.PageContext

getServletContext

public javax.servlet.ServletContext getServletContext()
Specified by:
getServletContext in class javax.servlet.jsp.PageContext

getSession

public javax.servlet.http.HttpSession getSession()
Specified by:
getSession in class javax.servlet.jsp.PageContext

handlePageException

public void handlePageException(java.lang.Exception e)
Specified by:
handlePageException in class javax.servlet.jsp.PageContext

handlePageException

public void handlePageException(java.lang.Throwable t)
Specified by:
handlePageException in class javax.servlet.jsp.PageContext

include

public void include(java.lang.String path)
Specified by:
include in class javax.servlet.jsp.PageContext

initialize

public void initialize(javax.servlet.Servlet servlet,
                       javax.servlet.ServletRequest request,
                       javax.servlet.ServletResponse response,
                       java.lang.String errorPageURL,
                       boolean needsSession,
                       int bufferSize,
                       boolean autoFlush)
Specified by:
initialize in class javax.servlet.jsp.PageContext

popBody

public javax.servlet.jsp.JspWriter popBody()
Overrides:
popBody in class javax.servlet.jsp.PageContext

pushBody

public javax.servlet.jsp.tagext.BodyContent pushBody()
Overrides:
pushBody in class javax.servlet.jsp.PageContext

release

public void release()
Specified by:
release in class javax.servlet.jsp.PageContext

removeAttribute

public void removeAttribute(java.lang.String name)
Specified by:
removeAttribute in class javax.servlet.jsp.PageContext

removeAttribute

public void removeAttribute(java.lang.String name,
                            int scope)
Specified by:
removeAttribute in class javax.servlet.jsp.PageContext

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value)
Specified by:
setAttribute in class javax.servlet.jsp.PageContext

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value,
                         int scope)
Specified by:
setAttribute in class javax.servlet.jsp.PageContext


Copyright © 2000-2007 Apache Software Foundation. All Rights Reserved.