Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-3724

HttpSession Map not set on invocation ActionContext in StrutsTestCase during getActionProxy

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.2.3.1
    • 2.3.12
    • Unit Tests
    • Patch

    Description

      I expected that when I set attributes on the MockHttpSession from MockHttpRequest in StrutsTestCase they would be available in the invocation ActionContext.

      Instead, getActionProxy does not set a SessionMap on the invocation ActionContext. This affects testing of Actions that use SessionAware and other ServletConfigInterceptor Interfaces.

      Workaround:

      public void testSomething() throws Exception {     
        ActionProxy proxy = getActionProxy("/something");
        proxy.getInvocation().getInvocationContext().setSession(new SessionMap(request));
      }
      

      Tiny patch to fix it:

      struts-2.2.3.1/src/plugins/junit/src/main/java/org/apache/struts2/StrutsTestCase.java
      39a40
      > import org.apache.struts2.dispatcher.SessionMap;
      141a143
      >         invocationContext.setSession(new SessionMap(request));
      

      Attachments

        Activity

          People

            lukaszlenart Lukasz Lenart
            donabrams Donald Abrams
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 5m
                5m
                Remaining:
                Remaining Estimate - 5m
                5m
                Logged:
                Time Spent - Not Specified
                Not Specified