| servletunit.struts.CactusStrutsTestCase
All known Subclasses: servletunit.struts.tests.cactus.TestMultipleActions, servletunit.struts.tests.cactus.TestNullPointerAction, servletunit.struts.tests.cactus.TestNullAction, servletunit.struts.tests.cactus.TestMessageResourceAction, servletunit.struts.tests.cactus.TestTilesForward, servletunit.struts.tests.cactus.TestAbsolutePath, servletunit.struts.tests.cactus.TestBadModuleName, servletunit.struts.tests.cactus.TestUserAction, servletunit.struts.tests.cactus.TestClearParameters, servletunit.struts.tests.cactus.TestContextParameters, servletunit.struts.tests.cactus.TestNoRequestPathInfo, servletunit.struts.tests.cactus.TestInputForward, servletunit.struts.tests.cactus.TestGetRequestParameterMap, servletunit.struts.tests.cactus.TestTokenAction, servletunit.struts.tests.cactus.TestMessageAction, servletunit.struts.tests.cactus.TestDynaActionForm, servletunit.struts.tests.cactus.TestSimpleForward, servletunit.struts.tests.cactus.TestRedirectAction, examples.cactus.TestCactusLoginAction, servletunit.struts.tests.cactus.TestDispatchAction, servletunit.struts.tests.cactus.TestSetActionForm, servletunit.struts.tests.cactus.TestGetActionForm, servletunit.struts.tests.cactus.TestProcessResults,
CactusStrutsTestCase | public class CactusStrutsTestCase extends ServletTestCase (Code) | | 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.
|
Method Summary | |
public void | actionPerform() Executes the Action instance to be tested. | public void | addRequestParameter(String parameterName, String parameterValue) Adds an HttpServletRequest parameter to be used in setting up the
ActionForm instance to be used in this test. | public void | addRequestParameter(String parameterName, 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. | public void | clearRequestParameters() Clears all request parameters previously set. | public ActionForm | getActionForm() Returns the ActionForm instance stored in either the request or session. | public ActionServlet | getActionServlet() Returns the ActionServlet controller used in this
test. | protected String | getActualForward() Returns the forward sent to RequestDispatcher. | public HttpServletRequest | getRequest() Returns an HttpServletRequest object that can be used in
this test. | public HttpServletRequestWrapper | getRequestWrapper() Returns a HttpServletRequestWrapper object that can be used
in this test. | public HttpServletResponse | getResponse() Returns an HttpServletResponse object that can be used in
this test. | public HttpServletResponseWrapper | getResponseWrapper() Returns an HttpServletResponseWrapper object that can be used in
this test. | public HttpSession | getSession() Returns an HttpSession object that can be used in this
test. | public void | processRequest(boolean flag) Instructs StrutsTestCase to fully process a forward request. | public void | setActionForm(ActionForm form) Sets an ActionForm instance to be used in this test. | public void | setActionServlet(ActionServlet servlet) Sets the ActionServlet to be used in this test execution. | public void | setConfigFile(String pathname) Sets the location of the Struts configuration file for the default module.
This method can take either an absolute path, or a relative path. | public void | setConfigFile(String moduleName, String pathname) Sets the struts configuration file for a given sub-application.
This method can take either an absolute path, or a relative path. | public void | setInitParameter(String key, String value) Sets an initialization parameter on the
ActionServlet. | public void | setRequestPathInfo(String pathInfo) Sets the request path instructing the ActionServlet to used a
particual ActionMapping.
Parameters: pathInfo - the request path to be processed. | public void | setRequestPathInfo(String moduleName, String pathInfo) Sets the request path instructing the ActionServlet to used a
particual ActionMapping. | public void | setRequestWrapper(HttpServletRequestWrapper wrapper) Set this TestCase to use a given HttpServletRequestWrapper
class when calling Action.execute(). | public void | setResponseWrapper(HttpServletResponseWrapper wrapper) Set this TestCase to use a given HttpServletResponseWrapper
class when calling Action.execute(). | public void | setServletMapping(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() | public void | verifyActionErrors(String[] errorNames) Verifies if the ActionServlet controller sent these error messages. | public void | verifyActionMessages(String[] messageNames) Verifies if the ActionServlet controller sent these action messages. | public void | verifyForward(String forwardName) Verifies if the ActionServlet controller used this forward.
Parameters: forwardName - the logical name of a forward, as definedin the Struts configuration file. | public void | verifyForwardPath(String forwardPath) Verifies if the ActionServlet controller used this actual path
as a forward. | public void | verifyInputForward() Verifies if the ActionServlet controller forwarded to the defined
input path. | public void | verifyInputTilesForward(String definitionName) Verifies that the ActionServlet controller forwarded to the defined
input Tiles definition. | public void | verifyNoActionErrors() Verifies that the ActionServlet controller sent no error messages upon
executing an Action object. | public void | verifyNoActionMessages() Verifies that the ActionServlet controller sent no action messages upon
executing an Action object. | public void | verifyTilesForward(String forwardName, String definitionName) Verifies that the ActionServlet controller used this forward and Tiles definition.
Parameters: forwardName - the logical name of a forward, as definedin the Struts configuration file. |
actionServlet | protected ActionServlet actionServlet(Code) | | |
actionServletIsInitialized | protected boolean actionServletIsInitialized(Code) | | |
isInitialized | protected boolean isInitialized(Code) | | |
logger | protected static Log logger(Code) | | |
requestPathIsSet | protected boolean requestPathIsSet(Code) | | |
CactusStrutsTestCase | public CactusStrutsTestCase()(Code) | | Default constructor.
|
CactusStrutsTestCase | public CactusStrutsTestCase(String testName)(Code) | | Constructor that takes test name parameter, for backwards compatibility with older versions on JUnit.
|
actionPerform | public void actionPerform()(Code) | | Executes the Action instance to be tested. This method initializes
the ActionServlet, sets up and optionally validates the ActionForm
bean associated with the Action to be tested, and then calls the
Action.execute() method. Results are stored for further validation.
exception: AssertionFailedError - if there are any executionerrors while calling Action.execute() or ActionForm.validate(). |
addRequestParameter | public void addRequestParameter(String parameterName, String parameterValue)(Code) | | Adds an HttpServletRequest parameter to be used in setting up the
ActionForm instance to be used in this test. Each parameter added
should correspond to an attribute in the ActionForm instance used
by the Action instance being tested.
|
addRequestParameter | public void addRequestParameter(String parameterName, String[] parameterValues)(Code) | | 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.
Each parameter added should correspond to an attribute in the ActionForm
instance used by the Action instance being tested.
|
clearRequestParameters | public void clearRequestParameters()(Code) | | Clears all request parameters previously set. NOTE: This will not clear
parameters set using Cactus beginXXX methods!
|
getActionForm | public ActionForm getActionForm()(Code) | | Returns the ActionForm instance stored in either the request or session. Note
that no form will be returned if the Action being tested cleans up the form
instance.
|
getActionServlet | public ActionServlet getActionServlet()(Code) | | Returns the ActionServlet controller used in this
test.
|
getActualForward | protected String getActualForward()(Code) | | Returns the forward sent to RequestDispatcher.
|
getRequest | public HttpServletRequest getRequest()(Code) | | Returns an HttpServletRequest object that can be used in
this test.
|
getResponse | public HttpServletResponse getResponse()(Code) | | Returns an HttpServletResponse object that can be used in
this test.
|
getSession | public HttpSession getSession()(Code) | | Returns an HttpSession object that can be used in this
test.
|
processRequest | public void processRequest(boolean flag)(Code) | | Instructs StrutsTestCase to fully process a forward request. By default, StrutsTestCase
stops processing a request as soon as the forward path has been collected, in order to avoid
side effects; calling this method overrides this behavior.
Parameters: flag - set to true to fully process forward requests |
setActionForm | public void setActionForm(ActionForm form)(Code) | | Sets an ActionForm instance to be used in this test. The given ActionForm instance
will be stored in the scope specified in the Struts configuration file (ie: request
or session). Note that while this ActionForm instance is passed to the test, Struts
will still control how it is used. In particular, it will call the ActionForm.reset()
method, so if you override this method in your ActionForm subclass, you could potentially
reset attributes in the form passed through this method.
Parameters: form - the ActionForm instance to be used in this test. |
setActionServlet | public void setActionServlet(ActionServlet servlet)(Code) | | Sets the ActionServlet to be used in this test execution. This
method should only be used if you plan to use a customized
version different from that provided in the Struts distribution.
|
setConfigFile | public void setConfigFile(String pathname)(Code) | | Sets the location of the Struts configuration file for the default module.
This method can take either an absolute path, or a relative path. If an
absolute path is supplied, the configuration file will be loaded from the
underlying filesystem; otherwise, the ServletContext loader will be used.
|
setConfigFile | public void setConfigFile(String moduleName, String pathname)(Code) | | Sets the struts configuration file for a given sub-application.
This method can take either an absolute path, or a relative path. If an
absolute path is supplied, the configuration file will be loaded from the
underlying filesystem; otherwise, the ServletContext loader will be used.
Parameters: moduleName - the name of the sub-application, or null if this is the default application Parameters: pathname - the location of the configuration file for this sub-application |
setInitParameter | public void setInitParameter(String key, String value)(Code) | | Sets an initialization parameter on the
ActionServlet. Allows you to simulate an init parameter
that would normally have been found in web.xml.
Parameters: key - the name of the initialization parameter Parameters: value - the value of the intialization parameter |
setRequestPathInfo | public void setRequestPathInfo(String pathInfo)(Code) | | Sets the request path instructing the ActionServlet to used a
particual ActionMapping.
Parameters: pathInfo - the request path to be processed. This shouldcorrespond to a particular action mapping, as would normallyappear in an HTML or JSP source file. |
setRequestPathInfo | public void setRequestPathInfo(String moduleName, String pathInfo)(Code) | | Sets the request path instructing the ActionServlet to used a
particual ActionMapping. Also sets the ServletPath property
on the request.
Parameters: moduleName - the name of the Struts sub-application withwhich this request is associated, or null if it is the defaultapplication. Parameters: pathInfo - the request path to be processed. This shouldcorrespond to a particular action mapping, as would normallyappear in an HTML or JSP source file. If this request is partof a sub-application, the module name should not appear in therequest path. |
setRequestWrapper | public void setRequestWrapper(HttpServletRequestWrapper wrapper)(Code) | | Set this TestCase to use a given HttpServletRequestWrapper
class when calling Action.execute(). Note that if this
method is not called, then the normal HttpServletRequest
object is used.
Parameters: wrapper - an HttpServletRequestWrapper object to beused when calling Action.execute(). |
setResponseWrapper | public void setResponseWrapper(HttpServletResponseWrapper wrapper)(Code) | | Set this TestCase to use a given HttpServletResponseWrapper
class when calling Action.execute(). Note that if this
method is not called, then the normal HttpServletResponse
object is used.
Parameters: wrapper - an HttpServletResponseWrapper object to beused when calling Action.execute(). |
setServletMapping | public void setServletMapping(String servletMapping)(Code) | | Sets the servlet mapping used to map requests to the Struts controller. This is used to restore
proper setting after the test has been executed. By default, the stanard "*.do" mapping will be
restored, so only use this method for non-standard servlet mappings.
Parameters: servletMapping - |
setUp | protected void setUp() throws Exception(Code) | | Sets up the test fixture for this test. This method creates
an instance of the ActionServlet, initializes it to validate
forms and turn off debugging, and clears all other parameters.
|
verifyActionErrors | public void verifyActionErrors(String[] errorNames)(Code) | | Verifies if the ActionServlet controller sent these error messages.
There must be an exact match between the provided error messages, and
those sent by the controller, in both name and number.
Parameters: errorNames - a String array containing the error message keysto be verified, as defined in the application resource propertiesfile. exception: AssertionFailedError - if the ActionServlet controllersent different error messages than those in errorNames after executing an Action object. |
verifyActionMessages | public void verifyActionMessages(String[] messageNames)(Code) | | Verifies if the ActionServlet controller sent these action messages.
There must be an exact match between the provided action messages, and
those sent by the controller, in both name and number.
Parameters: messageNames - a String array containing the action message keysto be verified, as defined in the application resource propertiesfile. exception: AssertionFailedError - if the ActionServlet controllersent different action messages than those in messageNames after executing an Action object. |
verifyForward | public void verifyForward(String forwardName) throws AssertionFailedError(Code) | | Verifies if the ActionServlet controller used this forward.
Parameters: forwardName - the logical name of a forward, as definedin the Struts configuration file. This can either refer to aglobal forward, or one local to the ActionMapping. exception: AssertionFailedError - if the ActionServlet controllerused a different forward than forwardName afterexecuting an Action object. |
verifyForwardPath | public void verifyForwardPath(String forwardPath) throws AssertionFailedError(Code) | | Verifies if the ActionServlet controller used this actual path
as a forward.
Parameters: forwardPath - an absolute pathname to which the requestis to be forwarded. exception: AssertionFailedError - if the ActionServlet controllerused a different forward path than forwardPath afterexecuting an Action object. |
verifyInputForward | public void verifyInputForward()(Code) | | Verifies if the ActionServlet controller forwarded to the defined
input path.
exception: AssertionFailedError - if the ActionServlet controllerused a different forward than the defined input path afterexecuting an Action object. |
verifyInputTilesForward | public void verifyInputTilesForward(String definitionName)(Code) | | Verifies that the ActionServlet controller forwarded to the defined
input Tiles definition.
Parameters: definitionName - the name of a Tiles definition, as definedin the Tiles configuration file. exception: AssertionFailedError - if the ActionServlet controllerused a different forward than the defined input path afterexecuting an Action object. |
verifyNoActionErrors | public void verifyNoActionErrors()(Code) | | Verifies that the ActionServlet controller sent no error messages upon
executing an Action object.
exception: AssertionFailedError - if the ActionServlet controllersent any error messages after excecuting and Action object. |
verifyNoActionMessages | public void verifyNoActionMessages()(Code) | | Verifies that the ActionServlet controller sent no action messages upon
executing an Action object.
exception: AssertionFailedError - if the ActionServlet controllersent any action messages after excecuting and Action object. |
verifyTilesForward | public void verifyTilesForward(String forwardName, String definitionName)(Code) | | Verifies that the ActionServlet controller used this forward and Tiles definition.
Parameters: forwardName - the logical name of a forward, as definedin the Struts configuration file. This can either refer to aglobal forward, or one local to the ActionMapping. Parameters: definitionName - the name of a Tiles definition, as definedin the Tiles configuration file. exception: AssertionFailedError - if the ActionServlet controllerused a different forward or tiles definition than those given afterexecuting an Action object. |
|
|