Package org.springframework.mock.web
Class MockFilterChain
java.lang.Object
org.springframework.mock.web.MockFilterChain
- All Implemented Interfaces:
FilterChain
Mock implementation of the
FilterChain
interface.
A MockFilterChain
can be configured with one or more filters and a
Servlet to invoke. The first time the chain is called, it invokes all filters
and the Servlet, and saves the request and response. Subsequent invocations
raise an IllegalStateException
unless reset()
is called.
- Since:
- 2.0.3
- Author:
- Juergen Hoeller, Rob Winch, Rossen Stoyanchev
- See Also:
-
Constructor Summary
ConstructorDescriptionRegister a single do-nothingFilter
implementation.MockFilterChain
(Servlet servlet) Create a FilterChain with a Servlet.MockFilterChain
(Servlet servlet, Filter... filters) Create aFilterChain
with Filter's and a Servlet. -
Method Summary
Modifier and TypeMethodDescriptionvoid
doFilter
(ServletRequest request, ServletResponse response) Return the request thatdoFilter(jakarta.servlet.ServletRequest, jakarta.servlet.ServletResponse)
has been called with.Return the response thatdoFilter(jakarta.servlet.ServletRequest, jakarta.servlet.ServletResponse)
has been called with.void
reset()
Reset theMockFilterChain
allowing it to be invoked again.
-
Constructor Details
-
MockFilterChain
public MockFilterChain()Register a single do-nothingFilter
implementation. The first invocation saves the request and response. Subsequent invocations raise anIllegalStateException
unlessreset()
is called. -
MockFilterChain
Create a FilterChain with a Servlet.- Parameters:
servlet
- the Servlet to invoke- Since:
- 3.2
-
MockFilterChain
Create aFilterChain
with Filter's and a Servlet.- Parameters:
servlet
- theServlet
to invoke in thisFilterChain
filters
- theFilter
's to invoke in thisFilterChain
- Since:
- 3.2
-
-
Method Details
-
getRequest
Return the request thatdoFilter(jakarta.servlet.ServletRequest, jakarta.servlet.ServletResponse)
has been called with. -
getResponse
Return the response thatdoFilter(jakarta.servlet.ServletRequest, jakarta.servlet.ServletResponse)
has been called with. -
doFilter
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException - Specified by:
doFilter
in interfaceFilterChain
- Throws:
IOException
ServletException
-
reset
public void reset()Reset theMockFilterChain
allowing it to be invoked again.
-