Class MockFilterChain
java.lang.Object
org.springframework.mock.web.MockFilterChain
- All Implemented Interfaces:
jakarta.servlet.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(jakarta.servlet.Servlet servlet) Create aMockFilterChainwith aServlet.MockFilterChain(jakarta.servlet.Servlet servlet, jakarta.servlet.Filter... filters) Create aMockFilterChainwith aServletand filters. -
Method Summary
Modifier and TypeMethodDescriptionvoiddoFilter(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response) Invoke registeredFiltersand/orServletalso saving the request and response.@Nullable jakarta.servlet.ServletRequestReturn the request thatdoFilter(ServletRequest, ServletResponse)has been called with.@Nullable jakarta.servlet.ServletResponseReturn the response thatdoFilter(ServletRequest, ServletResponse)has been called with.voidreset()Reset thisMockFilterChainallowing it to be invoked again.
-
Constructor Details
-
MockFilterChain
public MockFilterChain()Create an emptyMockFilterChainwithout any filters. -
MockFilterChain
public MockFilterChain(jakarta.servlet.Servlet servlet) Create aMockFilterChainwith aServlet.- Parameters:
servlet- theServletto invoke- Since:
- 3.2
-
MockFilterChain
public MockFilterChain(jakarta.servlet.Servlet servlet, jakarta.servlet.Filter... filters) Create aMockFilterChainwith aServletand filters.- Parameters:
servlet- theServletto invoke in thisMockFilterChainfilters- the filters to invoke in thisMockFilterChain- Since:
- 3.2
-
-
Method Details
-
getRequest
Return the request thatdoFilter(ServletRequest, ServletResponse)has been called with. -
getResponse
Return the response thatdoFilter(ServletRequest, ServletResponse)has been called with. -
doFilter
public void doFilter(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response) throws IOException, jakarta.servlet.ServletException Invoke registeredFiltersand/orServletalso saving the request and response.- Specified by:
doFilterin interfacejakarta.servlet.FilterChain- Throws:
IOExceptionjakarta.servlet.ServletException
-
reset
public void reset()Reset thisMockFilterChainallowing it to be invoked again.
-