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

Junit plugin does not push ACTION_MAPPING into the context resulting in NPE

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.5.25
    • Fix Version/s: 2.5.26, 2.6
    • Component/s: Plugin - JUnit
    • Labels:
      None

      Description

      org.apache.struts2.StrutsJUnit4TestCase is not pushing the ACTION_MAPPING into the context which results in the following NPE when testing a Struts action and using the struts-rest plugin.

       java.lang.NullPointerException
      	at org.apache.struts2.rest.RestWorkflowInterceptor.doIntercept(RestWorkflowInterceptor.java:205)

      The issue can be replicated with this sample github project

      https://github.com/zepernick/struts25-rest-junit

      The current work around is to override the org.apache.struts2.StrutsJUnit4TestCase#getActionProxy and add

              ActionMapping mapping = getActionMapping(request);
              ServletActionContext.getContext().put(ServletActionContext.ACTION_MAPPING, mapping);
      

      Also see this discussion on the struts mailing list

      http://struts.1045723.n5.nabble.com/NPE-when-running-unit-test-with-struts-rest-plugin-tp5724974p5724986.html

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                zep.devs Paul Zepernick
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 0.5h
                  0.5h