[
https://issues.apache.org/jira/browse/WICKET-7095?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
John Tal updated WICKET-7095:
-----------------------------
Summary: WicketTester MockHttpServletRequest parameters are unobtainable
via ServletWebRequest (was: WicketTester MockHttpServletRequest parameters are
unobtainable)
> WicketTester MockHttpServletRequest parameters are unobtainable via
> ServletWebRequest
> -------------------------------------------------------------------------------------
>
> Key: WICKET-7095
> URL: https://issues.apache.org/jira/browse/WICKET-7095
> Project: Wicket
> Issue Type: Improvement
> Components: wicket-core, wicket-tester
> Affects Versions: 9.15.0, 10.0.0-M2
> Reporter: John Tal
> Priority: Major
>
> 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 add to the existing getRequestParameters method
> the parameters inside of this.httpServletRequest such as below pseudocode
> (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.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)