org.apache.struts2.junit

## Class StrutsJUnit4TestCase<T>

- java.lang.Object
- - org.apache.struts2.junit.XWorkJUnit4TestCase
  - - org.apache.struts2.junit.StrutsJUnit4TestCase<T>

- Direct Known Subclasses:
    StrutsRestTestCase, StrutsSpringJUnit4TestCase

      public abstract class StrutsJUnit4TestCase<T>
      extends XWorkJUnit4TestCase

- - ### Field Summary

    Fields
    Modifier and Type | Field and 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.junit.XWorkJUnit4TestCase

      `actionProxyFactory, configuration, configurationManager, container`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `StrutsJUnit4TestCase()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected boolean` | `containsErrors()`
    `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
    `void` | `finishExecution()`
    `protected T` | `getAction()` gets an object from the stack after an action is executed
    `protected ActionMapping` | `getActionMapping(javax.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 String` | `getConfigPath()` Override this method to return a comma separated list of paths to a configuration file.
    `protected void` | `initActionContext(ActionContext actionContext)`
    `protected Dispatcher` | `initDispatcher(Map<String,String> params)`
    `protected void` | `initDispatcherParams()`
    `protected void` | `initServletMockObjects()`
    `protected void` | `initSession(ActionContext actionContext)`
    `protected void` | `injectStrutsDependencies(Object object)` Injects dependencies on an Object using Struts internal IoC container
    `void` | `setUp()` Sets up the configuration settings, XWork configuration, and message resources
    `protected void` | `setupBeforeInitDispatcher()`
    `void` | `tearDown()`

    - ### Methods inherited from class org.apache.struts2.junit.XWorkJUnit4TestCase

      `loadButAdd, loadButAdd, loadConfigurationProviders`

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

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

- - ### Field Detail

    - #### 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 Detail

    - #### StrutsJUnit4TestCase

          public StrutsJUnit4TestCase()

  - ### Method Detail

    - #### findValueAfterExecute

          protected Object findValueAfterExecute(String key)

      gets an object from the stack after an action is executed

    - #### getAction

          protected T getAction()

      gets an object from the stack after an action is executed
      Returns:
        The executed action

    - #### containsErrors

          protected boolean containsErrors()

    - #### executeAction

          protected String executeAction(String uri)
                                  throws javax.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:
        `javax.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.

    - #### initActionContext

          protected void initActionContext(ActionContext actionContext)

    - #### initSession

          protected void initSession(ActionContext actionContext)

    - #### getActionMapping

          protected ActionMapping getActionMapping(javax.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

    - #### setupBeforeInitDispatcher

          protected void setupBeforeInitDispatcher()
                                            throws Exception

      Throws:
        `Exception`

    - #### initServletMockObjects

          protected void initServletMockObjects()

    - #### finishExecution

          public void finishExecution()

    - #### setUp

          public void setUp()
                     throws Exception

      Sets up the configuration settings, XWork configuration, and message resources
      Overrides:
        `setUp` in class `XWorkJUnit4TestCase`
      Throws:
        `Exception`

    - #### initDispatcherParams

          protected void initDispatcherParams()

    - #### initDispatcher

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

    - #### getConfigPath

          protected String getConfigPath()

      Override this method to return a comma separated list of paths to a configuration file.

      The default implementation simply returns `null`.

      Returns:
        a comma separated list of config locations

    - #### tearDown

          public void tearDown()
                        throws Exception

      Overrides:
        `tearDown` in class `XWorkJUnit4TestCase`
      Throws:
        `Exception`

Copyright © 2000–2022 Apache Software Foundation. All rights reserved.