public class MockFilterChain
extends java.lang.Object
Mock implementation of the javax.servlet.FilterChain
interface. Used
for testing the web framework; also useful for testing custom
javax.servlet.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 <code>IllegalStateException</code> unless reset()
is called.
MockFilterConfig
,
PassThroughFilterChain
Modifier and Type | Class and Description |
---|---|
private static class |
MockFilterChain.ServletFilterProxy
A filter that simply delegates to a Servlet.
|
Modifier and Type | Field and Description |
---|---|
private java.util.List<Filter> |
filters |
private java.util.Iterator<Filter> |
iterator |
private ServletRequest |
request |
private ServletResponse |
response |
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)
Invoke registered
Filter s and/or Servlet also saving the
request and response. |
ServletRequest |
getRequest()
Return the request that
doFilter(ServletRequest, ServletResponse) has been called with. |
ServletResponse |
getResponse()
Return the response that
doFilter(ServletRequest, ServletResponse) has been called with. |
private static java.util.List<Filter> |
initFilterList(Servlet servlet,
Filter... filters) |
void |
reset()
Reset the
MockFilterChain allowing it to be invoked again. |
private ServletRequest request
private ServletResponse response
private final java.util.List<Filter> filters
private java.util.Iterator<Filter> iterator
public MockFilterChain()
Filter
implementation. The first
invocation saves the request and response. Subsequent invocations raise
an <code>IllegalStateException</code> 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 FilterChain
filters
- the Filter
's to invoke in this FilterChain
private static java.util.List<Filter> initFilterList(Servlet servlet, Filter... filters)
public ServletRequest getRequest()
doFilter(ServletRequest, ServletResponse)
has been called with.public ServletResponse getResponse()
doFilter(ServletRequest, ServletResponse)
has been called with.public void doFilter(ServletRequest request, ServletResponse response) throws java.io.IOException, ServletException
Filter
s and/or Servlet
also saving the
request and response.java.io.IOException
ServletException
public void reset()
MockFilterChain
allowing it to be invoked again.