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
ConstructorsConstructorDescriptionCreate an emptyMockFilterChainwithout any filters.MockFilterChain(Servlet servlet) Create aMockFilterChainwith aServlet.MockFilterChain(Servlet servlet, Filter... filters) -
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 thisMockFilterChainallowing it to be invoked again.
-
Constructor Details
-
MockFilterChain
public MockFilterChain()Create an emptyMockFilterChainwithout any filters. -
MockFilterChain
Create aMockFilterChainwith aServlet.- Parameters:
servlet- theServletto invoke- Since:
- 3.2
-
MockFilterChain
- Parameters:
servlet- theServletto invoke in thisMockFilterChainfilters- 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:
doFilterin interfaceFilterChain- Throws:
IOExceptionServletException
-
reset
public void reset()Reset thisMockFilterChainallowing it to be invoked again.
-