Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-7095

WicketTester MockHttpServletRequest parameters are unobtainable via ServletWebRequest

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Cannot Reproduce
    • 9.15.0, 10.0.0-M2
    • None
    • wicket-core, wicket-tester
    • None

    Description

      Background from reading the Wicket code:

       

      In a TC, using WicketTester, set a parameter: 
       
      wicketTester.getRequest()
      .setParameter(Apponstants.FOO_PARAMETER_NAME, "foo");
       
      Next, try to read that parameter in another class during the running of a test. 
      This seems to be an issue with the parameter not being found.
       
      ServletWebRequest contains a MockHttpServletRequest through member variable httpServletRequest.
       
      But the method ServletWebRequest.getParameters() ignores the member MockHttpServletRequest.parameters, where 'foo' is located, and instead does this:
       
      public IRequestParameters getRequestParameters()

      { return new CombinedRequestParametersAdapter(new IRequestParameters[]

      {this.getPostParameters(), this.getQueryParameters()}

      );
      }
       
      You can get to this 'foo' parameter with an explicit cast of ServletWebRequest to (MockHttpServletRequest).  But mainline web code should not cast to Mocks of Wicket Tester.
       
      Looking at the getCookies implementation in ServletWebRequest, it goes to a deeper level (into the httpServletRequest):
       
      public List<Cookie> getCookies()

      { Cookie[] cookies = this.httpServletRequest.getCookies(); List<Cookie> result = cookies == null ? Collections.emptyList() : Arrays.asList(cookies); return Collections.unmodifiableList(result); }

       
      Proposed Solutions: 
       
      A) Modify HttpServletRequest to override getRequestParameters so it can retrieve it's own parameters
       
      OR
       
      B) Modify ServletWebRequest to add to the existing getRequestParameters method the parameters inside of this.httpServletRequest such as mockup below (needs work to bring in the map correctly):
       
      public IRequestParameters getRequestParameters()

      { return new CombinedRequestParametersAdapter(new IRequestParameters[]

      {this.getPostParameters(), this.getQueryParameters(),  this.httpServletRequest.getParameterMap()}

      );
      }
       
      Please let me know if there is another combination of API that do allow WicketTester to set Request Parameters in a way readible during TCs through ServletWebRequest.

      Attachments

        Activity

          People

            Unassigned Unassigned
            bodhione John Tal
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: