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`

public abstract class StrutsTestCase extends XWorkTestCase
Base test case for JUnit testing Struts.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected Dispatcher`
  `dispatcher`
  `protected Map<String,String>`
  `dispatcherInitParams`
  `protected org.springframework.mock.web.MockPageContext`
  `pageContext`
  `protected org.springframework.mock.web.MockHttpServletRequest`
  `request`
  `protected org.springframework.core.io.DefaultResourceLoader`
  `resourceLoader`
  `protected org.springframework.mock.web.MockHttpServletResponse`
  `response`
  `protected org.springframework.mock.web.MockServletContext`
  `servletContext`

  ### Fields inherited from class org.apache.struts2.XWorkTestCase

  `actionProxyFactory, configuration, configurationManager, container`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `StrutsTestCase()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected void`
  `applyAdditionalParams(ActionContext context)`
  Can be overwritten in subclass to provide additional context's params and settings used during action invocation
  `protected <T> T`
  `createAction(Class<T> clazz)`
  A helper method which allows instantiate an action if this action extends `ActionSupport` or any other action class that requires framework's dependencies injection.
  `protected String`
  `executeAction(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 Object`
  `findValueAfterExecute(String key)`
  gets an object from the stack after an action is executed
  `protected ActionMapping`
  `getActionMapping(jakarta.servlet.http.HttpServletRequest request)`
  Finds an ActionMapping for a given request
  `protected ActionMapping`
  `getActionMapping(String url)`
  Finds an ActionMapping for a given url
  `protected ActionProxy`
  `getActionProxy(String uri)`
  Creates an action proxy for a request, and sets parameters of the ActionInvocation to the passed parameters.
  `protected void`
  `initActionContext(ActionContext actionContext)`
  `protected Dispatcher`
  `initDispatcher(Map<String,String> params)`
  `protected void`
  `initServletMockObjects()`
  `protected void`
  `initSession(ActionContext actionContext)`
  `protected void`
  `injectStrutsDependencies(Object object)`
  Injects dependencies on an Object using Struts internal IoC container
  `protected void`
  `setUp()`
  Sets up the configuration settings, XWork configuration, and message resources
  `protected void`
  `setupAfterInitDispatcher(Dispatcher dispatcher)`
  `protected void`
  `setupBeforeInitDispatcher()`
  `protected void`
  `tearDown()`

  ### Methods inherited from class org.apache.struts2.XWorkTestCase

  `createContextWithLocale, loadButAdd, loadButAdd, loadButSet, loadConfigurationProviders, setStrutsConstant, setStrutsConstant`

  ### Methods inherited from class junit.framework.TestCase

  `assertEquals, 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`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### response

    protected org.springframework.mock.web.MockHttpServletResponse response

  - ### request

    protected org.springframework.mock.web.MockHttpServletRequest request

  - ### pageContext

    protected org.springframework.mock.web.MockPageContext pageContext

  - ### servletContext

    protected org.springframework.mock.web.MockServletContext servletContext

  - ### dispatcherInitParams

    protected Map<String,String> dispatcherInitParams

  - ### dispatcher

    protected Dispatcher dispatcher

  - ### resourceLoader

    protected org.springframework.core.io.DefaultResourceLoader resourceLoader

- ## Constructor Details

  - ### StrutsTestCase

    public StrutsTestCase()

- ## Method Details

  - ### findValueAfterExecute

    protected Object findValueAfterExecute(String key)
    gets an object from the stack after an action is executed

  - ### executeAction

    protected 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`

  - ### getActionProxy

    protected ActionProxy getActionProxy(String uri)
    Creates 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.

  - ### createAction

    protected <T> T createAction(Class<T> clazz)
    A helper method which allows instantiate an action if this action extends `ActionSupport` or any other action class that requires framework's dependencies injection.

  - ### initActionContext

    protected void initActionContext(ActionContext actionContext)

  - ### initSession

    protected void initSession(ActionContext actionContext)

  - ### applyAdditionalParams

    protected void applyAdditionalParams(ActionContext context)
    Can be overwritten in subclass to provide additional context's params and settings used during action invocation
    Parameters:
      `context` - current `ActionContext`

  - ### getActionMapping

    protected ActionMapping getActionMapping(jakarta.servlet.http.HttpServletRequest request)
    Finds an ActionMapping for a given request

  - ### getActionMapping

    protected ActionMapping getActionMapping(String url)
    Finds an ActionMapping for a given url

  - ### injectStrutsDependencies

    protected void injectStrutsDependencies(Object object)
    Injects dependencies on an Object using Struts internal IoC container

  - ### setUp

    protected void setUp() throws Exception
    Sets up the configuration settings, XWork configuration, and message resources
    Overrides:
      `setUp` in class `XWorkTestCase`
    Throws:
      `Exception`

  - ### setupBeforeInitDispatcher

    protected void setupBeforeInitDispatcher() throws Exception
    Throws:
      `Exception`

  - ### setupAfterInitDispatcher

    protected void setupAfterInitDispatcher(Dispatcher dispatcher)

  - ### initServletMockObjects

    protected void initServletMockObjects()

  - ### initDispatcher

    protected Dispatcher initDispatcher(Map<String,String> params)

  - ### tearDown

    protected void tearDown() throws Exception
    Overrides:
      `tearDown` in class `XWorkTestCase`
    Throws:
      `Exception`