The Spring Framework

org.springframework.mock.web
Class MockPageContext

java.lang.Object
  extended by javax.servlet.jsp.JspContext
      extended by javax.servlet.jsp.PageContext
          extended by org.springframework.mock.web.MockPageContext

public class MockPageContext
extends PageContext

Mock implementation of the PageContext interface.

Used for testing the web framework; only necessary for testing applications when testing custom JSP tags.

Note: Expects initialization via the constructor rather than via the PageContext.initialize method. Does not support writing to a JspWriter, request dispatching, and handlePageException calls.

Since:
1.0.2
Author:
Juergen Hoeller

Field Summary
 
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()
          Create new MockPageContext with a default MockServletContext, MockHttpServletRequest, MockHttpServletResponse, MockServletConfig.
MockPageContext(ServletContext servletContext)
          Create new MockPageContext with a default MockHttpServletRequest, MockHttpServletResponse, MockServletConfig.
MockPageContext(ServletContext servletContext, HttpServletRequest request)
          Create new MockPageContext with a MockHttpServletResponse, MockServletConfig.
MockPageContext(ServletContext servletContext, HttpServletRequest request, HttpServletResponse response)
          Create new MockPageContext with a MockServletConfig.
MockPageContext(ServletContext servletContext, HttpServletRequest request, HttpServletResponse response, ServletConfig servletConfig)
          Create new MockServletConfig.
 
Method Summary
 Object findAttribute(String name)
           
 void forward(String url)
           
 Object getAttribute(String name)
           
 Object getAttribute(String name, int scope)
           
 Enumeration getAttributeNames()
           
 Enumeration getAttributeNamesInScope(int scope)
           
 int getAttributesScope(String name)
           
 Exception getException()
           
 ExpressionEvaluator getExpressionEvaluator()
           
 JspWriter getOut()
           
 Object getPage()
           
 ServletRequest getRequest()
           
 ServletResponse getResponse()
           
 ServletConfig getServletConfig()
           
 ServletContext getServletContext()
           
 HttpSession getSession()
           
 VariableResolver getVariableResolver()
           
 void handlePageException(Exception ex)
           
 void handlePageException(Throwable ex)
           
 void include(String url)
           
 void include(String url, boolean flush)
           
 void initialize(Servlet servlet, ServletRequest request, ServletResponse response, String errorPageURL, boolean needsSession, int bufferSize, boolean autoFlush)
           
 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)
           
 
Methods inherited from class javax.servlet.jsp.PageContext
getErrorData, pushBody
 
Methods inherited from class javax.servlet.jsp.JspContext
popBody, pushBody
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MockPageContext

public MockPageContext()
Create new MockPageContext with a default MockServletContext, MockHttpServletRequest, MockHttpServletResponse, MockServletConfig.


MockPageContext

public MockPageContext(ServletContext servletContext)
Create new MockPageContext with a default MockHttpServletRequest, MockHttpServletResponse, MockServletConfig.

Parameters:
servletContext - the ServletContext that the JSP page runs in (only necessary when actually accessing the ServletContext)

MockPageContext

public MockPageContext(ServletContext servletContext,
                       HttpServletRequest request)
Create new MockPageContext with a MockHttpServletResponse, MockServletConfig.

Parameters:
servletContext - the ServletContext that the JSP page runs in
request - the current HttpServletRequest (only necessary when actually accessing the request)

MockPageContext

public MockPageContext(ServletContext servletContext,
                       HttpServletRequest request,
                       HttpServletResponse response)
Create new MockPageContext with a MockServletConfig.

Parameters:
servletContext - the ServletContext that the JSP page runs in
request - the current HttpServletRequest
response - the current HttpServletResponse (only necessary when actually writing to the response)

MockPageContext

public MockPageContext(ServletContext servletContext,
                       HttpServletRequest request,
                       HttpServletResponse response,
                       ServletConfig servletConfig)
Create new MockServletConfig.

Parameters:
servletContext - the ServletContext that the JSP page runs in
request - the current HttpServletRequest
response - the current HttpServletResponse
servletConfig - the ServletConfig (hardly ever accessed from within a tag)
Method Detail

initialize

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

release

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

setAttribute

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

setAttribute

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

getAttribute

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

getAttribute

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

findAttribute

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

removeAttribute

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

removeAttribute

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

getAttributesScope

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

getAttributeNames

public Enumeration getAttributeNames()

getAttributeNamesInScope

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

getOut

public JspWriter getOut()
Specified by:
getOut in class JspContext

getExpressionEvaluator

public ExpressionEvaluator getExpressionEvaluator()
Specified by:
getExpressionEvaluator in class JspContext

getVariableResolver

public VariableResolver getVariableResolver()
Specified by:
getVariableResolver in class JspContext

getSession

public HttpSession getSession()
Specified by:
getSession 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

getException

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

getServletConfig

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

getServletContext

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

forward

public void forward(String url)
             throws ServletException,
                    IOException
Specified by:
forward in class PageContext
Throws:
ServletException
IOException

include

public void include(String url)
             throws ServletException,
                    IOException
Specified by:
include in class PageContext
Throws:
ServletException
IOException

include

public void include(String url,
                    boolean flush)
             throws ServletException,
                    IOException
Specified by:
include in class PageContext
Throws:
ServletException
IOException

handlePageException

public void handlePageException(Exception ex)
                         throws ServletException,
                                IOException
Specified by:
handlePageException in class PageContext
Throws:
ServletException
IOException

handlePageException

public void handlePageException(Throwable ex)
                         throws ServletException,
                                IOException
Specified by:
handlePageException in class PageContext
Throws:
ServletException
IOException

The Spring Framework

Copyright © 2002-2007 The Spring Framework.