Class MockPageContext
java.lang.Object
jakarta.servlet.jsp.JspContext
jakarta.servlet.jsp.PageContext
org.springframework.mock.web.MockPageContext
public class MockPageContext
extends jakarta.servlet.jsp.PageContext
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
ConstructorsConstructorDescriptionCreate new MockPageContext with a defaultMockServletContext
,MockHttpServletRequest
,MockHttpServletResponse
,MockServletConfig
.MockPageContext
(@Nullable jakarta.servlet.ServletContext servletContext) Create new MockPageContext with a defaultMockHttpServletRequest
,MockHttpServletResponse
,MockServletConfig
.MockPageContext
(@Nullable jakarta.servlet.ServletContext servletContext, @Nullable jakarta.servlet.http.HttpServletRequest request) Create new MockPageContext with a MockHttpServletResponse, MockServletConfig.MockPageContext
(@Nullable jakarta.servlet.ServletContext servletContext, @Nullable jakarta.servlet.http.HttpServletRequest request, @Nullable jakarta.servlet.http.HttpServletResponse response) Create new MockPageContext with a MockServletConfig.MockPageContext
(@Nullable jakarta.servlet.ServletContext servletContext, @Nullable jakarta.servlet.http.HttpServletRequest request, @Nullable jakarta.servlet.http.HttpServletResponse response, @Nullable jakarta.servlet.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[]
@Nullable jakarta.el.ELContext
jakarta.servlet.jsp.JspWriter
getOut()
getPage()
jakarta.servlet.ServletRequest
jakarta.servlet.ServletResponse
jakarta.servlet.ServletConfig
jakarta.servlet.ServletContext
jakarta.servlet.http.HttpSession
void
void
void
void
void
initialize
(jakarta.servlet.Servlet servlet, jakarta.servlet.ServletRequest request, jakarta.servlet.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, @Nullable Object value) void
setAttribute
(String name, @Nullable 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 jakarta.servlet.ServletContext servletContext, @Nullable jakarta.servlet.http.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 jakarta.servlet.ServletContext servletContext, @Nullable jakarta.servlet.http.HttpServletRequest request, @Nullable jakarta.servlet.http.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 jakarta.servlet.ServletContext servletContext, @Nullable jakarta.servlet.http.HttpServletRequest request, @Nullable jakarta.servlet.http.HttpServletResponse response, @Nullable jakarta.servlet.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(jakarta.servlet.Servlet servlet, jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response, String errorPageURL, boolean needsSession, int bufferSize, boolean autoFlush) - Specified by:
initialize
in classjakarta.servlet.jsp.PageContext
-
release
public void release()- Specified by:
release
in classjakarta.servlet.jsp.PageContext
-
setAttribute
-
setAttribute
-
getAttribute
-
getAttribute
-
findAttribute
-
removeAttribute
- Specified by:
removeAttribute
in classjakarta.servlet.jsp.JspContext
-
removeAttribute
- Specified by:
removeAttribute
in classjakarta.servlet.jsp.JspContext
-
getAttributesScope
- Specified by:
getAttributesScope
in classjakarta.servlet.jsp.JspContext
-
getAttributeNames
-
getAttributeNamesInScope
- Specified by:
getAttributeNamesInScope
in classjakarta.servlet.jsp.JspContext
-
getOut
public jakarta.servlet.jsp.JspWriter getOut()- Specified by:
getOut
in classjakarta.servlet.jsp.JspContext
-
getELContext
- Specified by:
getELContext
in classjakarta.servlet.jsp.JspContext
-
getSession
public jakarta.servlet.http.HttpSession getSession()- Specified by:
getSession
in classjakarta.servlet.jsp.PageContext
-
getPage
- Specified by:
getPage
in classjakarta.servlet.jsp.PageContext
-
getRequest
public jakarta.servlet.ServletRequest getRequest()- Specified by:
getRequest
in classjakarta.servlet.jsp.PageContext
-
getResponse
public jakarta.servlet.ServletResponse getResponse()- Specified by:
getResponse
in classjakarta.servlet.jsp.PageContext
-
getException
-
getServletConfig
public jakarta.servlet.ServletConfig getServletConfig()- Specified by:
getServletConfig
in classjakarta.servlet.jsp.PageContext
-
getServletContext
public jakarta.servlet.ServletContext getServletContext()- Specified by:
getServletContext
in classjakarta.servlet.jsp.PageContext
-
forward
- Specified by:
forward
in classjakarta.servlet.jsp.PageContext
- Throws:
jakarta.servlet.ServletException
IOException
-
include
- Specified by:
include
in classjakarta.servlet.jsp.PageContext
- Throws:
jakarta.servlet.ServletException
IOException
-
include
public void include(String path, boolean flush) throws jakarta.servlet.ServletException, IOException - Specified by:
include
in classjakarta.servlet.jsp.PageContext
- Throws:
jakarta.servlet.ServletException
IOException
-
getContentAsByteArray
public byte[] getContentAsByteArray() -
getContentAsString
- Throws:
UnsupportedEncodingException
-
handlePageException
- Specified by:
handlePageException
in classjakarta.servlet.jsp.PageContext
- Throws:
jakarta.servlet.ServletException
IOException
-
handlePageException
- Specified by:
handlePageException
in classjakarta.servlet.jsp.PageContext
- Throws:
jakarta.servlet.ServletException
IOException
-