public class MockFilterChain extends Object implements FilterChain
Mock implementation of the FilterChain interface. Used
for testing the web framework; also useful for testing custom
Filter implementations.
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.
MockFilterConfig,
PassThroughFilterChain| Constructor and Description |
|---|
MockFilterChain()
Register a single do-nothing
Filter implementation. |
MockFilterChain(Servlet servlet)
Create a FilterChain with a Servlet.
|
MockFilterChain(Servlet servlet,
Filter... filters)
Create a
FilterChain with Filter's and a Servlet. |
| Modifier and Type | Method and Description |
|---|---|
void |
doFilter(ServletRequest request,
ServletResponse response)
|
ServletRequest |
getRequest()
Return the request that
doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse) has been called with. |
ServletResponse |
getResponse()
Return the response that
doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse) has been called with. |
void |
reset()
Reset the
MockFilterChain allowing it to be invoked again. |
public MockFilterChain()
Filter implementation. The first
invocation saves the request and response. Subsequent invocations raise
an IllegalStateException unless reset() is called.public MockFilterChain(Servlet servlet)
servlet - the Servlet to invokepublic MockFilterChain(Servlet servlet, Filter... filters)
FilterChain with Filter's and a Servlet.servlet - the Servlet to invoke in this FilterChainfilters - the Filter's to invoke in this FilterChainpublic ServletRequest getRequest()
doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse) has been called with.public ServletResponse getResponse()
doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse) has been called with.public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException
doFilter in interface FilterChainIOExceptionServletExceptionpublic void reset()
MockFilterChain allowing it to be invoked again.