Java Doc for MockStrutsTestCase.java in  » Testing » StrutsTestCase » servletunit » struts » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » StrutsTestCase » servletunit.struts 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


servletunit.struts.MockStrutsTestCase

All known Subclasses:   servletunit.struts.tests.TestGetActionForm,  servletunit.struts.tests.TestCustomActionMapping,  servletunit.struts.tests.TestSetActionForm,  servletunit.struts.tests.TestMultipleConfigFiles,  servletunit.struts.tests.TestDynaActionForm,  servletunit.struts.tests.TestTilesForward,  servletunit.struts.tests.TestTokenAction,  servletunit.struts.tests.TestContextParameters,  servletunit.struts.tests.TestRedirectAction,  examples.TestLoginAction,  servletunit.struts.tests.TestMultipleActions,  servletunit.struts.tests.TestMockStrutsTestCase,  servletunit.struts.tests.TestGetMockObjects,  servletunit.struts.tests.TestInputForward,  servletunit.struts.tests.TestNullPointerAction,  servletunit.struts.tests.TestBadModuleName,  servletunit.struts.tests.TestAbsolutePath,  servletunit.struts.tests.TestMessageAction,  servletunit.struts.tests.TestMessageResourceAction,  servletunit.struts.tests.TestDispatchAction,  servletunit.struts.tests.TestNoRequestPathInfo,  servletunit.struts.tests.TestSimpleForward,  servletunit.struts.tests.TestUserAction,  servletunit.struts.tests.TestNullAction,  servletunit.struts.tests.TestClearParameters,  servletunit.struts.tests.TestResponseStatus,
MockStrutsTestCase
public class MockStrutsTestCase extends TestCase (Code)
MockStrutsTestCase is an extension of the base JUnit testcase that provides additional methods to aid in testing Struts Action objects. It uses a mock object approach to simulate a servlet container, and tests the execution of Action objects as they are actually run through the Struts ActionServlet. MockStrutsTestCase 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.

NOTE: By default, the Struts ActionServlet will look for the file WEB-INF/struts-config.xml, so you must place the directory that contains WEB-INF in your CLASSPATH. If you would like to use an alternate configuration file, please see the setConfigFile() method for details on how this file is located.


Field Summary
protected  StringactionPath
    
protected  ActionServletactionServlet
    
protected  booleanactionServletIsInitialized
    
protected  ServletConfigSimulatorconfig
    
protected  ServletContextSimulatorcontext
    
protected  booleanisInitialized
    
protected static  Loglogger
    
protected  Stringregistrations
     The set of public identifiers, and corresponding resource names, for the versions of the configuration file DTDs that we know about.
protected  HttpServletRequestSimulatorrequest
    
protected  booleanrequestPathSet
    
protected  HttpServletRequestWrapperrequestWrapper
    
protected  HttpServletResponseSimulatorresponse
    
protected  HttpServletResponseWrapperresponseWrapper
    

Constructor Summary
public  MockStrutsTestCase()
     Default constructor.
public  MockStrutsTestCase(String testName)
     Constructor that takes test name parameter, for backwards compatibility with older versions on JUnit.

Method Summary
public  voidactionPerform()
     Executes the Action instance to be tested.
public  voidaddRequestParameter(String parameterName, String parameterValue)
     Adds an HttpServletRequest parameter to be used in setting up the ActionForm instance to be used in this test.
public  voidaddRequestParameter(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  voidclearRequestParameters()
     Clears all request parameters previously set.
public  ActionFormgetActionForm()
     Returns the ActionForm instance stored in either the request or session.
public  ActionServletgetActionServlet()
     Returns the ActionServlet controller used in this test.
protected  StringgetActualForward()
     Returns the forward sent to RequestDispatcher.
public  HttpServletRequestSimulatorgetMockRequest()
     Returns the mock HttpServletRequest object used in this test.
public  HttpServletResponseSimulatorgetMockResponse()
     Returns the mock HttpServletResponse object used in this test.
public  HttpServletRequestgetRequest()
     Returns an HttpServletRequest object that can be used in this test.
public  HttpServletRequestWrappergetRequestWrapper()
     Returns a HttpServletRequestWrapper object that can be used in this test.
public  HttpServletResponsegetResponse()
     Returns an HttpServletResponse object that can be used in this test.
public  HttpServletResponseWrappergetResponseWrapper()
     Returns an HttpServletResponseWrapper object that can be used in this test.
public  HttpSessiongetSession()
     Returns an HttpSession object that can be used in this test.
public  voidsetActionForm(ActionForm form)
     Sets an ActionForm instance to be used in this test.
public  voidsetActionServlet(ActionServlet servlet)
     Sets the ActionServlet to be used in this test execution.
public  voidsetConfigFile(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  voidsetConfigFile(String moduleName, String pathname)
     Sets the struts configuration file for a given sub-application.
public  voidsetContextDirectory(File contextDirectory)
     Sets the context directory to be used with the getRealPath() methods in the ServletContext and HttpServletRequest API.
public  voidsetInitParameter(String key, String value)
     Sets an initialization parameter on the ActionServlet.
public  voidsetRequestPathInfo(String pathInfo)
     Sets the request path instructing the ActionServlet to used a particual ActionMapping.
Parameters:
  pathInfo - the request path to be processed.
public  voidsetRequestPathInfo(String moduleName, String pathInfo)
     Sets the request path instructing the ActionServlet to used a particual ActionMapping.
public  voidsetRequestWrapper(HttpServletRequestWrapper wrapper)
     Set this TestCase to use a given HttpServletRequestWrapper class when calling Action.execute().
public  voidsetResponseWrapper(HttpServletResponseWrapper wrapper)
     Set this TestCase to use a given HttpServletResponseWrapper class when calling Action.execute().
public  voidsetServletConfigFile(String pathname)
     Sets the location of the web.xml configuration file to be used to set up the servlet context and configuration for this test. This method supports both init-param and context-param tags, setting the ServletConfig and ServletContext appropriately. This method can take either an absolute path, or a relative path.
protected  voidsetUp()
     Sets up the test fixture for this test.
protected  voidtearDown()
    
public  voidverifyActionErrors(String[] errorNames)
     Verifies if the ActionServlet controller sent these error messages.
public  voidverifyActionMessages(String[] messageNames)
     Verifies if the ActionServlet controller sent these action messages.
public  voidverifyForward(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  voidverifyForwardPath(String forwardPath)
     Verifies if the ActionServlet controller used this actual path as a forward.
public  voidverifyInputForward()
     Verifies if the ActionServlet controller forwarded to the defined input path.
public  voidverifyInputTilesForward(String definitionName)
     Verifies that the ActionServlet controller forwarded to the defined input Tiles definition.
public  voidverifyNoActionErrors()
     Verifies that the ActionServlet controller sent no error messages upon executing an Action object.
public  voidverifyNoActionMessages()
     Verifies that the ActionServlet controller sent no action messages upon executing an Action object.
public  voidverifyTilesForward(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.

Field Detail
actionPath
protected String actionPath(Code)



actionServlet
protected ActionServlet actionServlet(Code)



actionServletIsInitialized
protected boolean actionServletIsInitialized(Code)



config
protected ServletConfigSimulator config(Code)



context
protected ServletContextSimulator context(Code)



isInitialized
protected boolean isInitialized(Code)



logger
protected static Log logger(Code)



registrations
protected String registrations(Code)
The set of public identifiers, and corresponding resource names, for the versions of the configuration file DTDs that we know about. There MUST be an even number of Strings in this list!



request
protected HttpServletRequestSimulator request(Code)



requestPathSet
protected boolean requestPathSet(Code)



requestWrapper
protected HttpServletRequestWrapper requestWrapper(Code)



response
protected HttpServletResponseSimulator response(Code)



responseWrapper
protected HttpServletResponseWrapper responseWrapper(Code)




Constructor Detail
MockStrutsTestCase
public MockStrutsTestCase()(Code)
Default constructor.



MockStrutsTestCase
public MockStrutsTestCase(String testName)(Code)
Constructor that takes test name parameter, for backwards compatibility with older versions on JUnit.




Method Detail
actionPerform
public void actionPerform()(Code)
Executes the Action instance to be tested. This method calls the ActionServlet.doPost() method to execute the Action instance to be tested, passing along any parameters set in the HttpServletRequest object. It stores any results for further validation.
exception:
  AssertionFailedError - if there are any executionerrors while calling Action.execute()



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.



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.



getMockRequest
public HttpServletRequestSimulator getMockRequest()(Code)
Returns the mock HttpServletRequest object used in this test. This allows access to methods for setting up test preconditions that are otherwise unavailable through the normal Servlet API.



getMockResponse
public HttpServletResponseSimulator getMockResponse()(Code)
Returns the mock HttpServletResponse object used in this test. This allows access to methods for setting up test preconditions that are otherwise unavailable through the normal Servlet API.



getRequest
public HttpServletRequest getRequest()(Code)
Returns an HttpServletRequest object that can be used in this test.



getRequestWrapper
public HttpServletRequestWrapper getRequestWrapper()(Code)
Returns a HttpServletRequestWrapper object that can be used in this test. Note that if MockStrutsTestCase.setRequestWrapper has not been called, this method will return an instance of javax.servlet.http.HttpServletRequestWrapper.



getResponse
public HttpServletResponse getResponse()(Code)
Returns an HttpServletResponse object that can be used in this test.



getResponseWrapper
public HttpServletResponseWrapper getResponseWrapper()(Code)
Returns an HttpServletResponseWrapper object that can be used in this test. Note that if MockStrutsTestCase.setResponseWrapper has not been called, this method will return an instance of javax.servlet.http.HttpServletResponseWrapper.



getSession
public HttpSession getSession()(Code)
Returns an HttpSession object that can be used in this test.



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



setContextDirectory
public void setContextDirectory(File contextDirectory)(Code)
Sets the context directory to be used with the getRealPath() methods in the ServletContext and HttpServletRequest API.
Parameters:
  contextDirectory - a File object representing the root context directoryfor this 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, but is not available while testing with mock objects.
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().



setServletConfigFile
public void setServletConfigFile(String pathname)(Code)
Sets the location of the web.xml configuration file to be used to set up the servlet context and configuration for this test. This method supports both init-param and context-param tags, setting the ServletConfig and ServletContext appropriately. 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.



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 creates a mock HttpServletRequest and HttpServletResponse object to use in this test.



tearDown
protected void tearDown() throws Exception(Code)



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 errorNamesafter 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 messageNamesafter 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.



www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.