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
ConstructorsConstructorDescriptionRegister a single do-nothingFilterimplementation.MockFilterChain(Servlet servlet) Create a FilterChain with a Servlet.MockFilterChain(Servlet servlet, Filter... filters) Create aFilterChainwith Filter's and a Servlet. -
Method Summary
Modifier and TypeMethodDescriptionvoiddoFilter(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.voidreset()Reset theMockFilterChainallowing it to be invoked again.
-
Constructor Details
-
MockFilterChain
public MockFilterChain()Register a single do-nothingFilterimplementation. The first invocation saves the request and response. Subsequent invocations raise anIllegalStateExceptionunlessreset()is called. -
MockFilterChain
Create a FilterChain with a Servlet.- Parameters:
servlet- the Servlet to invoke- Since:
- 3.2
-
MockFilterChain
Create aFilterChainwith Filter's and a Servlet.- Parameters:
servlet- theServletto invoke in thisFilterChainfilters- 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:
doFilterin interfaceFilterChain- Throws:
IOExceptionServletException
-
reset
public void reset()Reset theMockFilterChainallowing it to be invoked again.
-