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 thePageContext
interface. 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, orhandlePageException
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
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(@Nullable 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(@Nullable ServletContext servletContext, @Nullable 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(@Nullable ServletContext servletContext, @Nullable HttpServletRequest request, @Nullable 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(@Nullable ServletContext servletContext, @Nullable HttpServletRequest request, @Nullable HttpServletResponse response, @Nullable 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:
initialize
in classPageContext
release
public void release()
- Specified by:
release
in classPageContext
setAttribute
public void setAttribute(String name, @Nullable Object value)
- Specified by:
setAttribute
in classJspContext
setAttribute
public void setAttribute(String name, @Nullable Object value, int scope)
- Specified by:
setAttribute
in classJspContext
getAttribute
@Nullable public Object getAttribute(String name)
- Specified by:
getAttribute
in classJspContext
getAttribute
@Nullable public Object getAttribute(String name, int scope)
- Specified by:
getAttribute
in classJspContext
findAttribute
@Nullable public Object findAttribute(String name)
- Specified by:
findAttribute
in classJspContext
removeAttribute
public void removeAttribute(String name)
- Specified by:
removeAttribute
in classJspContext
removeAttribute
public void removeAttribute(String name, int scope)
- Specified by:
removeAttribute
in classJspContext
getAttributesScope
public int getAttributesScope(String name)
- Specified by:
getAttributesScope
in classJspContext
getAttributeNames
public Enumeration<String> getAttributeNames()
getAttributeNamesInScope
public Enumeration<String> getAttributeNamesInScope(int scope)
- Specified by:
getAttributeNamesInScope
in classJspContext
getOut
public JspWriter getOut()
- Specified by:
getOut
in classJspContext
getExpressionEvaluator
@Deprecated public ExpressionEvaluator getExpressionEvaluator()
Deprecated.- Specified by:
getExpressionEvaluator
in classJspContext
getELContext
@Nullable public ELContext getELContext()
- Specified by:
getELContext
in classJspContext
getVariableResolver
@Deprecated @Nullable public VariableResolver getVariableResolver()
Deprecated.- Specified by:
getVariableResolver
in classJspContext
getSession
public HttpSession getSession()
- Specified by:
getSession
in classPageContext
getPage
public Object getPage()
- Specified by:
getPage
in classPageContext
getRequest
public ServletRequest getRequest()
- Specified by:
getRequest
in classPageContext
getResponse
public ServletResponse getResponse()
- Specified by:
getResponse
in classPageContext
getException
@Nullable public Exception getException()
- Specified by:
getException
in classPageContext
getServletConfig
public ServletConfig getServletConfig()
- Specified by:
getServletConfig
in classPageContext
getServletContext
public ServletContext getServletContext()
- Specified by:
getServletContext
in classPageContext
forward
public void forward(String path) throws ServletException, IOException
- Specified by:
forward
in classPageContext
- Throws:
ServletException
IOException
include
public void include(String path) throws ServletException, IOException
- Specified by:
include
in classPageContext
- Throws:
ServletException
IOException
include
public void include(String path, boolean flush) throws ServletException, IOException
- Specified by:
include
in classPageContext
- Throws:
ServletException
IOException
getContentAsByteArray
public byte[] getContentAsByteArray()
getContentAsString
public String getContentAsString() throws UnsupportedEncodingException
- Throws:
UnsupportedEncodingException
handlePageException
public void handlePageException(Exception ex) throws ServletException, IOException
- Specified by:
handlePageException
in classPageContext
- Throws:
ServletException
IOException
handlePageException
public void handlePageException(Throwable ex) throws ServletException, IOException
- Specified by:
handlePageException
in classPageContext
- Throws:
ServletException
IOException