Package org.springframework.mock.web
Class MockPageContext
java.lang.Object
jakarta.servlet.jsp.JspContext
jakarta.servlet.jsp.PageContext
org.springframework.mock.web.MockPageContext
Mock implementation of the
PageContext
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, or handlePageException
calls.
- Since:
- 1.0.2
- Author:
- Juergen Hoeller
-
Field Summary
Fields inherited from class jakarta.servlet.jsp.PageContext
APPLICATION, APPLICATION_SCOPE, CONFIG, EXCEPTION, OUT, PAGE, PAGE_SCOPE, PAGECONTEXT, REQUEST, REQUEST_SCOPE, RESPONSE, SESSION, SESSION_SCOPE
-
Constructor Summary
ConstructorDescriptionCreate 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
Modifier and TypeMethodDescriptionfindAttribute
(String name) void
getAttribute
(String name) getAttribute
(String name, int scope) getAttributeNamesInScope
(int scope) int
getAttributesScope
(String name) byte[]
Deprecated.getOut()
getPage()
Deprecated.void
void
void
void
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 jakarta.servlet.jsp.PageContext
getErrorData, pushBody
Methods inherited from class jakarta.servlet.jsp.JspContext
popBody, pushBody
-
Constructor Details
-
MockPageContext
public MockPageContext()Create new MockPageContext with a defaultMockServletContext
,MockHttpServletRequest
,MockHttpServletResponse
,MockServletConfig
. -
MockPageContext
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 Details
-
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
- Specified by:
setAttribute
in classJspContext
-
setAttribute
- Specified by:
setAttribute
in classJspContext
-
getAttribute
- Specified by:
getAttribute
in classJspContext
-
getAttribute
- Specified by:
getAttribute
in classJspContext
-
findAttribute
- Specified by:
findAttribute
in classJspContext
-
removeAttribute
- Specified by:
removeAttribute
in classJspContext
-
removeAttribute
- Specified by:
removeAttribute
in classJspContext
-
getAttributesScope
- Specified by:
getAttributesScope
in classJspContext
-
getAttributeNames
-
getAttributeNamesInScope
- Specified by:
getAttributeNamesInScope
in classJspContext
-
getOut
- Specified by:
getOut
in classJspContext
-
getExpressionEvaluator
Deprecated.- Specified by:
getExpressionEvaluator
in classJspContext
-
getELContext
- Specified by:
getELContext
in classJspContext
-
getVariableResolver
Deprecated.- Specified by:
getVariableResolver
in classJspContext
-
getSession
- Specified by:
getSession
in classPageContext
-
getPage
- Specified by:
getPage
in classPageContext
-
getRequest
- Specified by:
getRequest
in classPageContext
-
getResponse
- Specified by:
getResponse
in classPageContext
-
getException
- Specified by:
getException
in classPageContext
-
getServletConfig
- Specified by:
getServletConfig
in classPageContext
-
getServletContext
- Specified by:
getServletContext
in classPageContext
-
forward
- Specified by:
forward
in classPageContext
- Throws:
ServletException
IOException
-
include
- Specified by:
include
in classPageContext
- Throws:
ServletException
IOException
-
include
- Specified by:
include
in classPageContext
- Throws:
ServletException
IOException
-
getContentAsByteArray
public byte[] getContentAsByteArray() -
getContentAsString
- Throws:
UnsupportedEncodingException
-
handlePageException
- Specified by:
handlePageException
in classPageContext
- Throws:
ServletException
IOException
-
handlePageException
- Specified by:
handlePageException
in classPageContext
- Throws:
ServletException
IOException
-