Package org.springframework.mock.web
Class MockPageContext
- java.lang.Object
 - javax.servlet.jsp.JspContext
 - javax.servlet.jsp.PageContext
 - org.springframework.mock.web.MockPageContext
 
public class MockPageContext extends PageContext
Mock implementation of thePageContextinterface. Only necessary for testing applications when testing custom JSP tags.Note: Expects initialization via the constructor rather than via the
PageContext.initializemethod. Does not support writing to a JspWriter, request dispatching, orhandlePageExceptioncalls.- 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
Constructors Constructor Description MockPageContext()Create new MockPageContext with a defaultMockServletContext,MockHttpServletRequest,MockHttpServletResponse,MockServletConfig.MockPageContext(ServletContext servletContext)Create new MockPageContext with a defaultMockHttpServletRequest,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
Methods inherited from class javax.servlet.jsp.PageContext
getErrorData, pushBody
Methods inherited from class javax.servlet.jsp.JspContext
popBody, pushBody
Constructor Detail
MockPageContext
public MockPageContext()
Create new MockPageContext with a defaultMockServletContext,MockHttpServletRequest,MockHttpServletResponse,MockServletConfig.
MockPageContext
public MockPageContext(ServletContext servletContext)
Create new MockPageContext with a defaultMockHttpServletRequest,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 inrequest- 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 inrequest- the current HttpServletRequestresponse- 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 inrequest- the current HttpServletRequestresponse- the current HttpServletResponseservletConfig- 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:
 initializein classPageContext
release
public void release()
- Specified by:
 releasein classPageContext
setAttribute
public void setAttribute(String name, Object value)
- Specified by:
 setAttributein classJspContext
setAttribute
public void setAttribute(String name, Object value, int scope)
- Specified by:
 setAttributein classJspContext
getAttribute
public Object getAttribute(String name)
- Specified by:
 getAttributein classJspContext
getAttribute
public Object getAttribute(String name, int scope)
- Specified by:
 getAttributein classJspContext
findAttribute
public Object findAttribute(String name)
- Specified by:
 findAttributein classJspContext
removeAttribute
public void removeAttribute(String name)
- Specified by:
 removeAttributein classJspContext
removeAttribute
public void removeAttribute(String name, int scope)
- Specified by:
 removeAttributein classJspContext
getAttributesScope
public int getAttributesScope(String name)
- Specified by:
 getAttributesScopein classJspContext
getAttributeNames
public Enumeration<String> getAttributeNames()
getAttributeNamesInScope
public Enumeration<String> getAttributeNamesInScope(int scope)
- Specified by:
 getAttributeNamesInScopein classJspContext
getOut
public JspWriter getOut()
- Specified by:
 getOutin classJspContext
getExpressionEvaluator
@Deprecated public ExpressionEvaluator getExpressionEvaluator()
Deprecated.- Specified by:
 getExpressionEvaluatorin classJspContext
getELContext
public ELContext getELContext()
- Specified by:
 getELContextin classJspContext
getVariableResolver
@Deprecated public VariableResolver getVariableResolver()
Deprecated.- Specified by:
 getVariableResolverin classJspContext
getSession
public HttpSession getSession()
- Specified by:
 getSessionin classPageContext
getPage
public Object getPage()
- Specified by:
 getPagein classPageContext
getRequest
public ServletRequest getRequest()
- Specified by:
 getRequestin classPageContext
getResponse
public ServletResponse getResponse()
- Specified by:
 getResponsein classPageContext
getException
public Exception getException()
- Specified by:
 getExceptionin classPageContext
getServletConfig
public ServletConfig getServletConfig()
- Specified by:
 getServletConfigin classPageContext
getServletContext
public ServletContext getServletContext()
- Specified by:
 getServletContextin classPageContext
forward
public void forward(String path) throws ServletException, IOException
- Specified by:
 forwardin classPageContext- Throws:
 ServletExceptionIOException
include
public void include(String path) throws ServletException, IOException
- Specified by:
 includein classPageContext- Throws:
 ServletExceptionIOException
include
public void include(String path, boolean flush) throws ServletException, IOException
- Specified by:
 includein classPageContext- Throws:
 ServletExceptionIOException
getContentAsByteArray
public byte[] getContentAsByteArray()
getContentAsString
public String getContentAsString() throws UnsupportedEncodingException
- Throws:
 UnsupportedEncodingException
handlePageException
public void handlePageException(Exception ex) throws ServletException, IOException
- Specified by:
 handlePageExceptionin classPageContext- Throws:
 ServletExceptionIOException
handlePageException
public void handlePageException(Throwable ex) throws ServletException, IOException
- Specified by:
 handlePageExceptionin classPageContext- Throws:
 ServletExceptionIOException