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 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  ServletContext application
           
protected  HashMap attributes
           
protected  ServletConfig config
           
protected  ServletRequest request
           
protected  ServletResponse response
           
protected  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(ServletConfig config, ServletRequest request, ServletResponse response)
           
 
Method Summary
 Object findAttribute(String name)
           
 void forward(String path)
           
 Object getAttribute(String name)
           
 Object getAttribute(String name, int scope)
           
 Enumeration getAttributeNamesInScope(int scope)
           
 int getAttributesScope(String name)
           
 Exception getException()
           
 JspWriter getOut()
           Custom JspWriter that throws the specified exception (supplied on the constructor...if any), else it simply returns.
 Object getPage()
           
 ServletRequest getRequest()
           
 ServletResponse getResponse()
           
 ServletConfig getServletConfig()
           
 ServletContext getServletContext()
           
 HttpSession getSession()
           
 void handlePageException(Exception e)
           
 void handlePageException(Throwable t)
           
 void include(String path)
           
 void initialize(Servlet servlet, ServletRequest request, ServletResponse response, String errorPageURL, boolean needsSession, int bufferSize, boolean autoFlush)
           
 JspWriter popBody()
           
 BodyContent pushBody()
           
 void release()
           
 void removeAttribute(String name)
           
 void removeAttribute(String name, int scope)
           
 void setAttribute(String name, Object value)
           
 void setAttribute(String name, Object value, int scope)
           
 void setValues(ServletConfig config, ServletRequest request, ServletResponse response)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

application

protected ServletContext application

attributes

protected HashMap attributes

config

protected ServletConfig config

request

protected ServletRequest request

response

protected ServletResponse response

session

protected HttpSession session
Constructor Detail

MockPageContext

public MockPageContext()

MockPageContext

public MockPageContext(ServletConfig config,
                       ServletRequest request,
                       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(ServletConfig config,
                      ServletRequest request,
                      ServletResponse response)

findAttribute

public Object findAttribute(String name)
Specified by:
findAttribute in class PageContext

forward

public void forward(String path)
Specified by:
forward in class PageContext

getAttribute

public Object getAttribute(String name)
Specified by:
getAttribute in class PageContext

getAttribute

public Object getAttribute(String name,
                           int scope)
Specified by:
getAttribute in class PageContext

getAttributeNamesInScope

public Enumeration getAttributeNamesInScope(int scope)
Specified by:
getAttributeNamesInScope in class PageContext

getAttributesScope

public int getAttributesScope(String name)
Specified by:
getAttributesScope in class PageContext

getException

public Exception getException()
Specified by:
getException in class PageContext

getOut

public JspWriter getOut()

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

Specified by:
getOut in class PageContext

getPage

public Object getPage()
Specified by:
getPage in class PageContext

getRequest

public ServletRequest getRequest()
Specified by:
getRequest in class PageContext

getResponse

public ServletResponse getResponse()
Specified by:
getResponse in class PageContext

getServletConfig

public ServletConfig getServletConfig()
Specified by:
getServletConfig in class PageContext

getServletContext

public ServletContext getServletContext()
Specified by:
getServletContext in class PageContext

getSession

public HttpSession getSession()
Specified by:
getSession in class PageContext

handlePageException

public void handlePageException(Exception e)
Specified by:
handlePageException in class PageContext

handlePageException

public void handlePageException(Throwable t)
Specified by:
handlePageException in class PageContext

include

public void include(String path)
Specified by:
include in class PageContext

initialize

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

popBody

public JspWriter popBody()
Overrides:
popBody in class PageContext

pushBody

public BodyContent pushBody()
Overrides:
pushBody in class PageContext

release

public void release()
Specified by:
release in class PageContext

removeAttribute

public void removeAttribute(String name)
Specified by:
removeAttribute in class PageContext

removeAttribute

public void removeAttribute(String name,
                            int scope)
Specified by:
removeAttribute in class PageContext

setAttribute

public void setAttribute(String name,
                         Object value)
Specified by:
setAttribute in class PageContext

setAttribute

public void setAttribute(String name,
                         Object value,
                         int scope)
Specified by:
setAttribute in class PageContext


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