Package org.springframework.mock.web
Class MockFilterChain
- java.lang.Object
- org.springframework.mock.web.MockFilterChain
- All Implemented Interfaces:
FilterChain
public class MockFilterChain extends Object implements FilterChain
Mock implementation of theFilterChain
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 anIllegalStateException
unlessreset()
is called.- Since:
- 2.0.3
- Author:
- Juergen Hoeller, Rob Winch, Rossen Stoyanchev
- See Also:
MockFilterConfig
,PassThroughFilterChain
Constructor Summary
Constructors Constructor Description MockFilterChain()
Register 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
doFilter(ServletRequest request, ServletResponse response)
ServletRequest
getRequest()
Return the request thatdoFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
has been called with.ServletResponse
getResponse()
Return the response thatdoFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
has been called with.void
reset()
Reset theMockFilterChain
allowing it to be invoked again.
Constructor Detail
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
public MockFilterChain(Servlet servlet)
Create a FilterChain with a Servlet.- Parameters:
servlet
- the Servlet to invoke- Since:
- 3.2
MockFilterChain
public MockFilterChain(Servlet servlet, Filter... filters)
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 Detail
getRequest
@Nullable public ServletRequest getRequest()
Return the request thatdoFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
has been called with.
getResponse
@Nullable public ServletResponse getResponse()
Return the response thatdoFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
has been called with.
doFilter
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException
- Specified by:
doFilter
in interfaceFilterChain
- Parameters:
request
- the request to pass along the chain.response
- the response to pass along the chain.- Throws:
IOException
- if an I/O related error has occurred during the processingServletException
- if an exception has occurred that interferes with the filterChain's normal operation
reset
public void reset()
Reset theMockFilterChain
allowing it to be invoked again.