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 javax.servlet.jsp.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(javax.servlet.ServletContext servletContext)
          Create new MockPageContext with a default MockHttpServletRequest, MockHttpServletResponse, MockServletConfig.
MockPageContext(javax.servlet.ServletContext servletContext, javax.servlet.http.HttpServletRequest request)
          Create new MockPageContext with a MockHttpServletResponse, MockServletConfig.
MockPageContext(javax.servlet.ServletContext servletContext, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Create new MockPageContext with a MockServletConfig.
MockPageContext(javax.servlet.ServletContext servletContext, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.ServletConfig servletConfig)
          Create new MockServletConfig.
 
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<java.lang.String> getAttributeNames()
           
 java.util.Enumeration<java.lang.String> getAttributeNamesInScope(int scope)
           
 int getAttributesScope(java.lang.String name)
           
 byte[] getContentAsByteArray()
           
 java.lang.String getContentAsString()
           
 javax.el.ELContext getELContext()
           
 java.lang.Exception getException()
           
 javax.servlet.jsp.el.ExpressionEvaluator getExpressionEvaluator()
           
 javax.servlet.jsp.JspWriter getOut()
           
 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()
           
 javax.servlet.jsp.el.VariableResolver getVariableResolver()
           
 void handlePageException(java.lang.Exception ex)
           
 void handlePageException(java.lang.Throwable ex)
           
 void include(java.lang.String path)
           
 void include(java.lang.String path, boolean flush)
           
 void initialize(javax.servlet.Servlet servlet, javax.servlet.ServletRequest request, javax.servlet.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 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(javax.servlet.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(javax.servlet.ServletContext servletContext,
                       javax.servlet.http.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(javax.servlet.ServletContext servletContext,
                       javax.servlet.http.HttpServletRequest request,
                       javax.servlet.http.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(javax.servlet.ServletContext servletContext,
                       javax.servlet.http.HttpServletRequest request,
                       javax.servlet.http.HttpServletResponse response,
                       javax.servlet.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(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

release

public void release()
Specified by:
release 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.JspContext

setAttribute

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

getAttribute

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

getAttribute

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

findAttribute

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

removeAttribute

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

removeAttribute

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

getAttributesScope

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

getAttributeNames

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

getAttributeNamesInScope

public java.util.Enumeration<java.lang.String> getAttributeNamesInScope(int scope)
Specified by:
getAttributeNamesInScope in class javax.servlet.jsp.JspContext

getOut

public javax.servlet.jsp.JspWriter getOut()
Specified by:
getOut in class javax.servlet.jsp.JspContext

getExpressionEvaluator

public javax.servlet.jsp.el.ExpressionEvaluator getExpressionEvaluator()
Specified by:
getExpressionEvaluator in class javax.servlet.jsp.JspContext

getELContext

public javax.el.ELContext getELContext()
Specified by:
getELContext in class javax.servlet.jsp.JspContext

getVariableResolver

public javax.servlet.jsp.el.VariableResolver getVariableResolver()
Specified by:
getVariableResolver in class javax.servlet.jsp.JspContext

getSession

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

getException

public java.lang.Exception getException()
Specified by:
getException 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

forward

public void forward(java.lang.String path)
             throws javax.servlet.ServletException,
                    java.io.IOException
Specified by:
forward in class javax.servlet.jsp.PageContext
Throws:
javax.servlet.ServletException
java.io.IOException

include

public void include(java.lang.String path)
             throws javax.servlet.ServletException,
                    java.io.IOException
Specified by:
include in class javax.servlet.jsp.PageContext
Throws:
javax.servlet.ServletException
java.io.IOException

include

public void include(java.lang.String path,
                    boolean flush)
             throws javax.servlet.ServletException,
                    java.io.IOException
Specified by:
include in class javax.servlet.jsp.PageContext
Throws:
javax.servlet.ServletException
java.io.IOException

getContentAsByteArray

public byte[] getContentAsByteArray()

getContentAsString

public java.lang.String getContentAsString()
                                    throws java.io.UnsupportedEncodingException
Throws:
java.io.UnsupportedEncodingException

handlePageException

public void handlePageException(java.lang.Exception ex)
                         throws javax.servlet.ServletException,
                                java.io.IOException
Specified by:
handlePageException in class javax.servlet.jsp.PageContext
Throws:
javax.servlet.ServletException
java.io.IOException

handlePageException

public void handlePageException(java.lang.Throwable ex)
                         throws javax.servlet.ServletException,
                                java.io.IOException
Specified by:
handlePageException in class javax.servlet.jsp.PageContext
Throws:
javax.servlet.ServletException
java.io.IOException

Spring Framework