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

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.5.25
    • 2.5.26, 6.0.0
    • Plugin - JUnit
    • 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

              Unassigned Unassigned
              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