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
ConstructorDescriptionCreate an emptyMockFilterChain
without any filters.MockFilterChain
(Servlet servlet) Create aMockFilterChain
with aServlet
.MockFilterChain
(Servlet servlet, Filter... filters) -
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 thisMockFilterChain
allowing it to be invoked again.
-
Constructor Details
-
MockFilterChain
public MockFilterChain()Create an emptyMockFilterChain
without any filters. -
MockFilterChain
Create aMockFilterChain
with aServlet
.- Parameters:
servlet
- theServlet
to invoke- Since:
- 3.2
-
MockFilterChain
- Parameters:
servlet
- theServlet
to invoke in thisMockFilterChain
filters
- the filters to invoke in thisMockFilterChain
- 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 thisMockFilterChain
allowing it to be invoked again.
-