You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "Stefan.Holzmueller" <St...@brandad-systems.de> on 2010/11/02 13:14:09 UTC

how to pass initial request parameters with WicketTester

Hello,

we are wondering about a valid test setup - perhaps somebody is able to help us with it. Our approaches to write a test failed because our WebApplication's newSession() seem to be called whenever we create a WicketTester and before we are able to set any request parameters.

Our setting is as follows: The application is started by a link that contains an HTTP GET parameter. We have extended SwarmWebApplication and implemented its newSession() so that the request's parameters are evaluated. The return value of this method is our custom Session that stores the initial parameter.

Now we have a test like this:

----------------
Map<String, String[]> params = new HashMap<String, String[]>();
params.put("id", "1234567");
WicketTester wicketTester = new WicketTester(ourApplication); // seems to call newSession() already
wicketTester.setParametersForNextRequest(params);
wicketTester.startPage(HomePage.class);
----------------

And the application code looks like this:
----------------
public class OurWebApplication extends SwarmWebApplication {

[...]

  @Override
  public NewsletterSession newSession(Request request, Response response) {
    String id = request.getParameter("id"); // is null in test setting, otherwise it works
    [...]
  }
}
----------------

Any clue on how to pass the initial request parameters to WicketTester? The productive code seems to work (checked that with some logging output), but we'd like to create a valid test case.

Your advice would be very much appreciated. We are probably not aware of some pitfalls in WicketTester and how to deal with them.

Cheers,
Björn and Stefan


-- 
BRANDAD Systems AG
Gebhardtstraße 5 
90762 Fürth

Fon +49 (0) 911 756658 - 0 
Fax +49 (0) 911 756658 - 88 
www.brandad-systems.de

Vorstand: Joachim Stelzer
Vorsitzender des Aufsichtsrats: Dr. Ottheinz Jung-Senssfelder
Registergericht Fürth, Handelsregister-Nummer: HRB 11435



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


AW: how to pass initial request parameters with WicketTester

Posted by "Stefan.Holzmueller" <St...@brandad-systems.de>.
Hello again,

thanks for the response. And I'm sorry that the code snippet got messed up somehow.

Anyways, the problem is that the request parameter is strictly required (we throw an exception if it is not there). So we want to make sure that there is a non-null parameter when starting a new session. For some reason, WicketTester seems to start a session (= call newSession() ) in its initialization phase, i.e. before we explicitly start any page, or are able to set the parameters.

We are certainly out of clues right now. Any pointer in the right direction is welcome.

Cheers,
Björn and Stefan


-----Ursprüngliche Nachricht-----
Von: Martin Grigorov [mailto:mgrigorov@apache.org] 
Gesendet: Dienstag, 2. November 2010 13:20
An: users@wicket.apache.org
Betreff: Re: how to pass initial request parameters with WicketTester

Try with org.apache.wicket.util.tester.BaseWicketTester.startPage(Class<C>,
PageParameters)
Put all parameters in the PageParameters instance

On Tue, Nov 2, 2010 at 1:14 PM, Stefan.Holzmueller <
Stefan.Holzmueller@brandad-systems.de> wrote:

> Hello,
>
> we are wondering about a valid test setup - perhaps somebody is able to
> help us with it. Our approaches to write a test failed because our
> WebApplication's newSession() seem to be called whenever we create a
> WicketTester and before we are able to set any request parameters.
>
> Our setting is as follows: The application is started by a link that
> contains an HTTP GET parameter. We have extended SwarmWebApplication and
> implemented its newSession() so that the request's parameters are evaluated.
> The return value of this method is our custom Session that stores the
> initial parameter.
>
> Now we have a test like this:
>
> ----------------
> Map<String, String[]> params = new HashMap<String, String[]>();
> params.put("id", "1234567");
> WicketTester wicketTester = new WicketTester(ourApplication); // seems to
> call newSession() already
> wicketTester.setParametersForNextRequest(params);
> wicketTester.startPage(HomePage.class);
> ----------------
>
> And the application code looks like this:
> ----------------
> public class OurWebApplication extends SwarmWebApplication {
>
> [...]
>
>  @Override
>  public NewsletterSession newSession(Request request, Response response) {
>    String id = request.getParameter("id"); // is null in test setting,
> otherwise it works
>    [...]
>  }
> }
> ----------------
>
> Any clue on how to pass the initial request parameters to WicketTester? The
> productive code seems to work (checked that with some logging output), but
> we'd like to create a valid test case.
>
> Your advice would be very much appreciated. We are probably not aware of
> some pitfalls in WicketTester and how to deal with them.
>
> Cheers,
> Björn and Stefan
>
>
> --
> BRANDAD Systems AG
> Gebhardtstraße 5
> 90762 Fürth
>
> Fon +49 (0) 911 756658 - 0
> Fax +49 (0) 911 756658 - 88
> www.brandad-systems.de
>
> Vorstand: Joachim Stelzer
> Vorsitzender des Aufsichtsrats: Dr. Ottheinz Jung-Senssfelder
> Registergericht Fürth, Handelsregister-Nummer: HRB 11435
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: how to pass initial request parameters with WicketTester

Posted by Martin Grigorov <mg...@apache.org>.
Try with org.apache.wicket.util.tester.BaseWicketTester.startPage(Class<C>,
PageParameters)
Put all parameters in the PageParameters instance

On Tue, Nov 2, 2010 at 1:14 PM, Stefan.Holzmueller <
Stefan.Holzmueller@brandad-systems.de> wrote:

> Hello,
>
> we are wondering about a valid test setup - perhaps somebody is able to
> help us with it. Our approaches to write a test failed because our
> WebApplication's newSession() seem to be called whenever we create a
> WicketTester and before we are able to set any request parameters.
>
> Our setting is as follows: The application is started by a link that
> contains an HTTP GET parameter. We have extended SwarmWebApplication and
> implemented its newSession() so that the request's parameters are evaluated.
> The return value of this method is our custom Session that stores the
> initial parameter.
>
> Now we have a test like this:
>
> ----------------
> Map<String, String[]> params = new HashMap<String, String[]>();
> params.put("id", "1234567");
> WicketTester wicketTester = new WicketTester(ourApplication); // seems to
> call newSession() already
> wicketTester.setParametersForNextRequest(params);
> wicketTester.startPage(HomePage.class);
> ----------------
>
> And the application code looks like this:
> ----------------
> public class OurWebApplication extends SwarmWebApplication {
>
> [...]
>
>  @Override
>  public NewsletterSession newSession(Request request, Response response) {
>    String id = request.getParameter("id"); // is null in test setting,
> otherwise it works
>    [...]
>  }
> }
> ----------------
>
> Any clue on how to pass the initial request parameters to WicketTester? The
> productive code seems to work (checked that with some logging output), but
> we'd like to create a valid test case.
>
> Your advice would be very much appreciated. We are probably not aware of
> some pitfalls in WicketTester and how to deal with them.
>
> Cheers,
> Björn and Stefan
>
>
> --
> BRANDAD Systems AG
> Gebhardtstraße 5
> 90762 Fürth
>
> Fon +49 (0) 911 756658 - 0
> Fax +49 (0) 911 756658 - 88
> www.brandad-systems.de
>
> Vorstand: Joachim Stelzer
> Vorsitzender des Aufsichtsrats: Dr. Ottheinz Jung-Senssfelder
> Registergericht Fürth, Handelsregister-Nummer: HRB 11435
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>