Package org.apache.struts2.junit
Class StrutsTestCase
java.lang.Object
junit.framework.Assert
junit.framework.TestCase
org.apache.struts2.XWorkTestCase
org.apache.struts2.junit.StrutsTestCase
- All Implemented Interfaces:
- junit.framework.Test
- Direct Known Subclasses:
- StrutsSpringTestCase
Base test case for JUnit testing Struts.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected Dispatcherprotected org.springframework.mock.web.MockPageContextprotected org.springframework.mock.web.MockHttpServletRequestprotected org.springframework.core.io.DefaultResourceLoaderprotected org.springframework.mock.web.MockHttpServletResponseprotected org.springframework.mock.web.MockServletContextFields inherited from class org.apache.struts2.XWorkTestCaseactionProxyFactory, configuration, configurationManager, container
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidapplyAdditionalParams(ActionContext context) Can be overwritten in subclass to provide additional context's params and settings used during action invocationprotected <T> TcreateAction(Class<T> clazz) A helper method which allows instantiate an action if this action extendsActionSupportor any other action class that requires framework's dependencies injection.protected StringexecuteAction(String uri) Executes an action and returns it's output (not the result returned from execute()), but the actual output that would be written to the response.protected Objectgets an object from the stack after an action is executedprotected ActionMappinggetActionMapping(jakarta.servlet.http.HttpServletRequest request) Finds an ActionMapping for a given requestprotected ActionMappinggetActionMapping(String url) Finds an ActionMapping for a given urlprotected ActionProxygetActionProxy(String uri) Creates an action proxy for a request, and sets parameters of the ActionInvocation to the passed parameters.protected voidinitActionContext(ActionContext actionContext) protected DispatcherinitDispatcher(Map<String, String> params) protected voidprotected voidinitSession(ActionContext actionContext) protected voidinjectStrutsDependencies(Object object) Injects dependencies on an Object using Struts internal IoC containerprotected voidsetUp()Sets up the configuration settings, XWork configuration, and message resourcesprotected voidsetupAfterInitDispatcher(Dispatcher dispatcher) protected voidprotected voidtearDown()Methods inherited from class org.apache.struts2.XWorkTestCasecreateContextWithLocale, loadButAdd, loadButAdd, loadButSet, loadConfigurationProviders, setStrutsConstant, setStrutsConstantMethods inherited from class junit.framework.TestCaseassertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runBare, runTest, setName, toString
- 
Field Details- 
responseprotected org.springframework.mock.web.MockHttpServletResponse response
- 
requestprotected org.springframework.mock.web.MockHttpServletRequest request
- 
pageContextprotected org.springframework.mock.web.MockPageContext pageContext
- 
servletContextprotected org.springframework.mock.web.MockServletContext servletContext
- 
dispatcherInitParams
- 
dispatcher
- 
resourceLoaderprotected org.springframework.core.io.DefaultResourceLoader resourceLoader
 
- 
- 
Constructor Details- 
StrutsTestCasepublic StrutsTestCase()
 
- 
- 
Method Details- 
findValueAfterExecutegets an object from the stack after an action is executed
- 
executeActionprotected String executeAction(String uri) throws jakarta.servlet.ServletException, UnsupportedEncodingException Executes an action and returns it's output (not the result returned from execute()), but the actual output that would be written to the response. For this to work the configured result for the action needs to be FreeMarker, or Velocity (JSPs can be used with the Embedded JSP plugin)- Throws:
- jakarta.servlet.ServletException
- UnsupportedEncodingException
 
- 
getActionProxyCreates an action proxy for a request, and sets parameters of the ActionInvocation to the passed parameters. Make sure to set the request parameters in the protected "request" object before calling this method.
- 
createActionA helper method which allows instantiate an action if this action extendsActionSupportor any other action class that requires framework's dependencies injection.
- 
initActionContext
- 
initSession
- 
applyAdditionalParamsCan be overwritten in subclass to provide additional context's params and settings used during action invocation- Parameters:
- context- current- ActionContext
 
- 
getActionMappingFinds an ActionMapping for a given request
- 
getActionMappingFinds an ActionMapping for a given url
- 
injectStrutsDependenciesInjects dependencies on an Object using Struts internal IoC container
- 
setUpSets up the configuration settings, XWork configuration, and message resources- Overrides:
- setUpin class- XWorkTestCase
- Throws:
- Exception
 
- 
setupBeforeInitDispatcher- Throws:
- Exception
 
- 
setupAfterInitDispatcher
- 
initServletMockObjectsprotected void initServletMockObjects()
- 
initDispatcher
- 
tearDown- Overrides:
- tearDownin class- XWorkTestCase
- Throws:
- Exception
 
 
-