|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.mockrunner.base.WebTestModule com.mockrunner.base.HTMLOutputModule com.mockrunner.servlet.ServletTestModule
public class ServletTestModule
Module for servlet and filter tests. Can test single servlets and filters and simulate a filter chain.
Constructor Summary | |
---|---|
ServletTestModule(WebMockObjectFactory mockFactory)
|
Method Summary | |
---|---|
void |
addFilter(javax.servlet.Filter filter)
Adds the specified filter to the filter chain without initializing it. |
void |
addFilter(javax.servlet.Filter filter,
boolean doInit)
Adds the specified filter it to the filter chain. |
void |
clearOutput()
Clears the output content |
javax.servlet.Filter |
createFilter(java.lang.Class filterClass)
Creates a filter, initializes it and adds it to the filter chain. |
javax.servlet.http.HttpServlet |
createServlet(java.lang.Class servletClass)
Creates a servlet and initializes it. |
void |
doDelete()
Calls the current servlets doDelete method. |
void |
doFilter()
Loops through the filter chain and calls the current servlets service method at the end (only if a current servlet
is set). |
void |
doGet()
Calls the current servlets doGet method. |
void |
doHead()
Calls the current servlets doHead method. |
void |
doOptions()
Calls the current servlets doOptions method. |
void |
doPost()
Calls the current servlets doPost method. |
void |
doPut()
Calls the current servlets doPut method. |
void |
doTrace()
Calls the current servlets doTrace method. |
javax.servlet.ServletRequest |
getFilteredRequest()
Returns the last request from the filter chain. |
javax.servlet.ServletResponse |
getFilteredResponse()
Returns the last response from the filter chain. |
java.lang.String |
getOutput()
Returns the servlet output as a string. |
javax.servlet.http.HttpServlet |
getServlet()
Returns the current servlet. |
void |
init()
Calls the current servlets init method. |
void |
releaseFilters()
Deletes all filters in the filter chain. |
void |
service()
Calls the current servlets service method. |
void |
setDoChain(boolean doChain)
If doChain is set to true
(default is false ) every call of
one of the servlet methods will go through the filter chain
before calling the servlet method. |
void |
setServlet(javax.servlet.http.HttpServlet servlet)
Sets the specified servlet as the current servlet without initializing it. |
void |
setServlet(javax.servlet.http.HttpServlet servlet,
boolean doInit)
Sets the specified servlet as the current servlet. |
Methods inherited from class com.mockrunner.base.HTMLOutputModule |
---|
getOutputAsBufferedReader, getOutputAsJDOMDocument, getOutputAsW3CDocument, getOutputAsWellformedXML, setCaseSensitive, verifyOutput, verifyOutputContains, verifyOutputRegularExpression |
Methods inherited from class com.mockrunner.base.WebTestModule |
---|
addRequestParameter, addRequestParameter, addRequestParameter, getRequestAttribute, getRequestParameter, getSessionAttribute, setRequestAttribute, setSessionAttribute |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ServletTestModule(WebMockObjectFactory mockFactory)
Method Detail |
---|
public javax.servlet.http.HttpServlet createServlet(java.lang.Class servletClass)
servletClass
must
be of the type HttpServlet
, otherwise a
RuntimeException
will be thrown.
Sets the specified servlet as the current servlet and
initializes the filter chain with it.
servletClass
- the class of the servlet
HttpServlet
java.lang.RuntimeException
- if servletClass
is not an
instance of HttpServlet
public void setServlet(javax.servlet.http.HttpServlet servlet)
ServletConfig
on your own.
Usually you can use
WebMockObjectFactory.getMockServletConfig()
.
servlet
- the servletpublic void setServlet(javax.servlet.http.HttpServlet servlet, boolean doInit)
doInit
is true
.
servlet
- the servletdoInit
- should init
be calledpublic javax.servlet.http.HttpServlet getServlet()
public javax.servlet.Filter createFilter(java.lang.Class filterClass)
filterClass
must be of the type
Filter
, otherwise a RuntimeException
will be thrown. You can loop through the filter chain with
doFilter()
. If you set doChain
to
true
every call of one of the servlet methods
will go through the filter chain before calling the servlet
method.
filterClass
- the class of the filter
Filter
java.lang.RuntimeException
- if filterClass
is not an
instance of Filter
public void addFilter(javax.servlet.Filter filter)
FilterConfig
on your own.
Usually you can use
WebMockObjectFactory.getMockFilterConfig()
.
filter
- the filterpublic void addFilter(javax.servlet.Filter filter, boolean doInit)
doInit
is true
.
filter
- the filterdoInit
- should init
be calledpublic void releaseFilters()
public void setDoChain(boolean doChain)
doChain
is set to true
(default is false
) every call of
one of the servlet methods will go through the filter chain
before calling the servlet method.
doChain
- true
if the chain should be calledpublic void doFilter()
service
method at the end (only if a current servlet
is set). You can use it to test single filters or the interaction
of filters and servlets.
If you set doChain to true
(use setDoChain(boolean)
),
this method is called before any call of a servlet method. If a filter
does not call it's chains doFilter
method, the chain
breaks and the servlet will not be called (just like it in the
real container).
public void init()
init
method. Is automatically
done when calling createServlet(java.lang.Class)
.
public void doDelete()
doDelete
method.
If you set doChain to true
(use setDoChain(boolean)
),
the filter chain will be called before doDelete
.
public void doGet()
doGet
method.
If you set doChain to true
(use setDoChain(boolean)
),
the filter chain will be called before doGet
.
public void doOptions()
doOptions
method.
If you set doChain to true
(use setDoChain(boolean)
),
the filter chain will be called before doOptions
.
public void doPost()
doPost
method.
If you set doChain to true
(use setDoChain(boolean)
),
the filter chain will be called before doPost
.
public void doPut()
doPut
method.
If you set doChain to true
(use setDoChain(boolean)
),
the filter chain will be called before doPut
.
public void doTrace()
doTrace
method.
If you set doChain to true
(use setDoChain(boolean)
),
the filter chain will be called before doTrace
.
public void doHead()
doHead
method.
If you set doChain to true
(use setDoChain(boolean)
),
the filter chain will be called before doHead
.
public void service()
service
method.
If you set doChain to true
(use setDoChain(boolean)
),
the filter chain will be called before service
.
public javax.servlet.ServletRequest getFilteredRequest()
doFilter()
or
after calling one servlet method with doChain
set to true
.
public javax.servlet.ServletResponse getFilteredResponse()
doFilter()
or
after calling one servlet method with doChain
set to true
.
public java.lang.String getOutput()
getOutput
in class HTMLOutputModule
public void clearOutput()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |