|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object ServletTestCase servletunit.struts.CactusStrutsTestCase
CactusStrutsTestCase is an extension of the Cactus ServletTestCase
base class that provides additional methods to aid in testing
Struts Action objects. It uses an in-container approach to run
the servlet container, and tests the execution of Action objects as they
are actually run through the Struts ActionServlet. CactusStrutsTestCase
provides methods that set up the request path, request parameters
for ActionForm subclasses, as well as methods that can verify
that the correct ActionForward was used and that the proper
ActionError messages were supplied.
Please note that this class is meant to run in the Cactus
framework, and you must configure your test environment
accordingly. Please see http://jakarta.apache.org/cactus
for more details.
Field Summary | |
protected ActionServlet |
actionServlet
|
protected boolean |
actionServletIsInitialized
|
protected boolean |
isInitialized
|
protected static Log |
logger
|
protected java.lang.String |
moduleName
|
protected boolean |
requestPathIsSet
|
protected HttpServletRequestWrapper |
requestWrapper
|
protected HttpServletResponseWrapper |
responseWrapper
|
protected java.lang.String |
servletMapping
|
Constructor Summary | |
CactusStrutsTestCase()
Default constructor. |
|
CactusStrutsTestCase(java.lang.String testName)
Constructor that takes test name parameter, for backwards compatibility with older versions on JUnit. |
Method Summary | |
void |
actionPerform()
Executes the Action instance to be tested. |
void |
addRequestParameter(java.lang.String parameterName,
java.lang.String parameterValue)
Adds an HttpServletRequest parameter to be used in setting up the ActionForm instance to be used in this test. |
void |
addRequestParameter(java.lang.String parameterName,
java.lang.String[] parameterValues)
Adds an HttpServletRequest parameter that is an array of String values to be used in setting up the ActionForm instance to be used in this test. |
void |
clearRequestParameters()
Clears all request parameters previously set. |
ActionForm |
getActionForm()
Returns the ActionForm instance stored in either the request or session. |
ActionServlet |
getActionServlet()
Returns the ActionServlet controller used in this test. |
protected java.lang.String |
getActualForward()
Returns the forward sent to RequestDispatcher. |
HttpServletRequest |
getRequest()
Returns an HttpServletRequest object that can be used in this test. |
HttpServletRequestWrapper |
getRequestWrapper()
Returns a HttpServletRequestWrapper object that can be used in this test. |
HttpServletResponse |
getResponse()
Returns an HttpServletResponse object that can be used in this test. |
HttpServletResponseWrapper |
getResponseWrapper()
Returns an HttpServletResponseWrapper object that can be used in this test. |
HttpSession |
getSession()
Returns an HttpSession object that can be used in this test. |
void |
processRequest(boolean flag)
Instructs StrutsTestCase to fully process a forward request. |
void |
setActionForm(ActionForm form)
Sets an ActionForm instance to be used in this test. |
void |
setActionServlet(ActionServlet servlet)
Sets the ActionServlet to be used in this test execution. |
void |
setConfigFile(java.lang.String pathname)
Sets the location of the Struts configuration file for the default module. |
void |
setConfigFile(java.lang.String moduleName,
java.lang.String pathname)
Sets the struts configuration file for a given sub-application. |
void |
setInitParameter(java.lang.String key,
java.lang.String value)
Sets an initialization parameter on the ActionServlet. |
void |
setRequestPathInfo(java.lang.String pathInfo)
Sets the request path instructing the ActionServlet to used a particual ActionMapping. |
void |
setRequestPathInfo(java.lang.String moduleName,
java.lang.String pathInfo)
Sets the request path instructing the ActionServlet to used a particual ActionMapping. |
void |
setRequestWrapper(HttpServletRequestWrapper wrapper)
Set this TestCase to use a given HttpServletRequestWrapper class when calling Action.execute(). |
void |
setResponseWrapper(HttpServletResponseWrapper wrapper)
Set this TestCase to use a given HttpServletResponseWrapper class when calling Action.execute(). |
void |
setServletMapping(java.lang.String servletMapping)
Sets the servlet mapping used to map requests to the Struts controller. |
protected void |
setUp()
Sets up the test fixture for this test. |
protected void |
tearDown()
|
void |
verifyActionErrors(java.lang.String[] errorNames)
Verifies if the ActionServlet controller sent these error messages. |
void |
verifyActionMessages(java.lang.String[] messageNames)
Verifies if the ActionServlet controller sent these action messages. |
void |
verifyForward(java.lang.String forwardName)
Verifies if the ActionServlet controller used this forward. |
void |
verifyForwardPath(java.lang.String forwardPath)
Verifies if the ActionServlet controller used this actual path as a forward. |
void |
verifyInputForward()
Verifies if the ActionServlet controller forwarded to the defined input path. |
void |
verifyInputTilesForward(java.lang.String definitionName)
Verifies that the ActionServlet controller forwarded to the defined input Tiles definition. |
void |
verifyNoActionErrors()
Verifies that the ActionServlet controller sent no error messages upon executing an Action object. |
void |
verifyNoActionMessages()
Verifies that the ActionServlet controller sent no action messages upon executing an Action object. |
void |
verifyTilesForward(java.lang.String forwardName,
java.lang.String definitionName)
Verifies that the ActionServlet controller used this forward and Tiles definition. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected ActionServlet actionServlet
protected HttpServletRequestWrapper requestWrapper
protected HttpServletResponseWrapper responseWrapper
protected boolean isInitialized
protected boolean actionServletIsInitialized
protected boolean requestPathIsSet
protected java.lang.String moduleName
protected java.lang.String servletMapping
protected static Log logger
Constructor Detail |
public CactusStrutsTestCase()
public CactusStrutsTestCase(java.lang.String testName)
Method Detail |
protected void setUp() throws java.lang.Exception
java.lang.Exception
public void setServletMapping(java.lang.String servletMapping)
servletMapping
- protected void tearDown() throws java.lang.Exception
java.lang.Exception
public HttpServletRequest getRequest()
public HttpServletRequestWrapper getRequestWrapper()
setRequestWrapper(HttpServletRequestWrapper)
has not been
called, this method will return an instance of
javax.servlet.http.HttpServletRequestWrapper.
public void setRequestWrapper(HttpServletRequestWrapper wrapper)
wrapper
- an HttpServletRequestWrapper object to be
used when calling Action.execute().public HttpServletResponse getResponse()
public HttpServletResponseWrapper getResponseWrapper()
setResponseWrapper(HttpServletResponseWrapper)
has not been
called, this method will return an instance of
javax.servlet.http.HttpServletResponseWrapper.
public void setResponseWrapper(HttpServletResponseWrapper wrapper)
wrapper
- an HttpServletResponseWrapper object to be
used when calling Action.execute().public HttpSession getSession()
public void addRequestParameter(java.lang.String parameterName, java.lang.String parameterValue)
public void addRequestParameter(java.lang.String parameterName, java.lang.String[] parameterValues)
public void clearRequestParameters()
public void setRequestPathInfo(java.lang.String pathInfo)
pathInfo
- the request path to be processed. This should
correspond to a particular action mapping, as would normally
appear in an HTML or JSP source file.public void setRequestPathInfo(java.lang.String moduleName, java.lang.String pathInfo)
moduleName
- the name of the Struts sub-application with
which this request is associated, or null if it is the default
application.pathInfo
- the request path to be processed. This should
correspond to a particular action mapping, as would normally
appear in an HTML or JSP source file. If this request is part
of a sub-application, the module name should not appear in the
request path.public void setInitParameter(java.lang.String key, java.lang.String value)
key
- the name of the initialization parametervalue
- the value of the intialization parameterpublic void setConfigFile(java.lang.String pathname)
public void setConfigFile(java.lang.String moduleName, java.lang.String pathname)
moduleName
- the name of the sub-application, or null if this is the default applicationpathname
- the location of the configuration file for this sub-applicationpublic ActionServlet getActionServlet()
public void setActionServlet(ActionServlet servlet)
public void actionPerform()
junit.framework.AssertionFailedError
- if there are any execution
errors while calling Action.execute() or ActionForm.validate().protected java.lang.String getActualForward()
public void verifyForward(java.lang.String forwardName) throws junit.framework.AssertionFailedError
forwardName
- the logical name of a forward, as defined
in the Struts configuration file. This can either refer to a
global forward, or one local to the ActionMapping.
junit.framework.AssertionFailedError
- if the ActionServlet controller
used a different forward than forwardName
after
executing an Action object.public void verifyForwardPath(java.lang.String forwardPath) throws junit.framework.AssertionFailedError
forwardPath
- an absolute pathname to which the request
is to be forwarded.
junit.framework.AssertionFailedError
- if the ActionServlet controller
used a different forward path than forwardPath
after
executing an Action object.public void verifyInputForward()
junit.framework.AssertionFailedError
- if the ActionServlet controller
used a different forward than the defined input path after
executing an Action object.public void verifyTilesForward(java.lang.String forwardName, java.lang.String definitionName)
forwardName
- the logical name of a forward, as defined
in the Struts configuration file. This can either refer to a
global forward, or one local to the ActionMapping.definitionName
- the name of a Tiles definition, as defined
in the Tiles configuration file.
junit.framework.AssertionFailedError
- if the ActionServlet controller
used a different forward or tiles definition than those given after
executing an Action object.public void verifyInputTilesForward(java.lang.String definitionName)
definitionName
- the name of a Tiles definition, as defined
in the Tiles configuration file.
junit.framework.AssertionFailedError
- if the ActionServlet controller
used a different forward than the defined input path after
executing an Action object.public void verifyActionErrors(java.lang.String[] errorNames)
errorNames
- a String array containing the error message keys
to be verified, as defined in the application resource properties
file.
junit.framework.AssertionFailedError
- if the ActionServlet controller
sent different error messages than those in errorNames
after executing an Action object.public void verifyNoActionErrors()
junit.framework.AssertionFailedError
- if the ActionServlet controller
sent any error messages after excecuting and Action object.public void verifyActionMessages(java.lang.String[] messageNames)
messageNames
- a String array containing the action message keys
to be verified, as defined in the application resource properties
file.
junit.framework.AssertionFailedError
- if the ActionServlet controller
sent different action messages than those in messageNames
after executing an Action object.public void verifyNoActionMessages()
junit.framework.AssertionFailedError
- if the ActionServlet controller
sent any action messages after excecuting and Action object.public ActionForm getActionForm()
public void setActionForm(ActionForm form)
form
- the ActionForm instance to be used in this test.public void processRequest(boolean flag)
flag
- set to true to fully process forward requests
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |