org.springframework.mock.web
Class MockPageContext

java.lang.Object
  extended by PageContext
      extended by org.springframework.mock.web.MockPageContext

public class MockPageContext
extends PageContext

Mock implementation of the javax.servlet.jsp.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
private  java.util.Map<java.lang.String,java.lang.Object> attributes
           
private  JspWriter out
           
private  HttpServletRequest request
           
private  HttpServletResponse response
           
private  ServletConfig servletConfig
           
private  ServletContext servletContext
           
 
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
 java.lang.Object findAttribute(java.lang.String name)
           
 void forward(java.lang.String url)
           
 java.lang.Object getAttribute(java.lang.String name)
           
 java.lang.Object getAttribute(java.lang.String name, int scope)
           
 java.util.Enumeration<java.lang.String> getAttributeNames()
           
 java.util.Enumeration<java.lang.String> getAttributeNamesInScope(int scope)
           
 int getAttributesScope(java.lang.String name)
           
 ELContext getELContext()
           
 java.lang.Exception getException()
           
 ExpressionEvaluator getExpressionEvaluator()
           
 JspWriter getOut()
           
 java.lang.Object getPage()
           
 ServletRequest getRequest()
           
 ServletResponse getResponse()
           
 ServletConfig getServletConfig()
           
 ServletContext getServletContext()
           
 HttpSession getSession()
           
 VariableResolver getVariableResolver()
           
 void handlePageException(java.lang.Exception ex)
           
 void handlePageException(java.lang.Throwable ex)
           
 void include(java.lang.String url)
           
 void include(java.lang.String url, boolean flush)
           
 void initialize(Servlet servlet, ServletRequest request, ServletResponse response, java.lang.String errorPageURL, boolean needsSession, int bufferSize, boolean autoFlush)
           
 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)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

servletContext

private final ServletContext servletContext

request

private final HttpServletRequest request

response

private final HttpServletResponse response

servletConfig

private final ServletConfig servletConfig

attributes

private final java.util.Map<java.lang.String,java.lang.Object> attributes

out

private JspWriter out
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,
                       java.lang.String errorPageURL,
                       boolean needsSession,
                       int bufferSize,
                       boolean autoFlush)

release

public void release()

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value)

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value,
                         int scope)

getAttribute

public java.lang.Object getAttribute(java.lang.String name)

getAttribute

public java.lang.Object getAttribute(java.lang.String name,
                                     int scope)

findAttribute

public java.lang.Object findAttribute(java.lang.String name)

removeAttribute

public void removeAttribute(java.lang.String name)

removeAttribute

public void removeAttribute(java.lang.String name,
                            int scope)

getAttributesScope

public int getAttributesScope(java.lang.String name)

getAttributeNames

public java.util.Enumeration<java.lang.String> getAttributeNames()

getAttributeNamesInScope

public java.util.Enumeration<java.lang.String> getAttributeNamesInScope(int scope)

getOut

public JspWriter getOut()

getExpressionEvaluator

public ExpressionEvaluator getExpressionEvaluator()

getELContext

public ELContext getELContext()

getVariableResolver

public VariableResolver getVariableResolver()

getSession

public HttpSession getSession()

getPage

public java.lang.Object getPage()

getRequest

public ServletRequest getRequest()

getResponse

public ServletResponse getResponse()

getException

public java.lang.Exception getException()

getServletConfig

public ServletConfig getServletConfig()

getServletContext

public ServletContext getServletContext()

forward

public void forward(java.lang.String url)
             throws ServletException,
                    java.io.IOException
Throws:
ServletException
java.io.IOException

include

public void include(java.lang.String url)
             throws ServletException,
                    java.io.IOException
Throws:
ServletException
java.io.IOException

include

public void include(java.lang.String url,
                    boolean flush)
             throws ServletException,
                    java.io.IOException
Throws:
ServletException
java.io.IOException

handlePageException

public void handlePageException(java.lang.Exception ex)
                         throws ServletException,
                                java.io.IOException
Throws:
ServletException
java.io.IOException

handlePageException

public void handlePageException(java.lang.Throwable ex)
                         throws ServletException,
                                java.io.IOException
Throws:
ServletException
java.io.IOException