Currently I'm using the WicketTester's startPanel method to test my panels. Within these panels I often use PageParameters to access data, using getPage().getPageParameters(). However, the startPanel method does not initialize any page parameters for the DummyPage, nor does it offer me functionality to set page parameters.
How do I set my page parameters during panel tests?
Is that really the way to do it? The startPanel already creates a dummy page for us, but without any page parameters. Using your approach attaches the panel to two pages, which does not seem like the optimal solution to me. Right now I extended the WicketTester with a startPanel(Panel, PageParameters) function:
And created a new dummy panel page with a page parameters constrctor
It beats me why this functionality isn't just provided out of the box by Apache.
Personally, I think, getting the
PageParameters
viagetPage().getPageParameters()
is a suboptimal way to go.It introduces a dependency from your panel to your page which makes them tightly coupled and hard to test, as you can see.
If you need to access the
PageParameters
from within yourPanel
, inject them by creating a constructor accepting these, something along the lines ofThis way you can use the
Parameters
from within yourPanel
, construct thePanel
with anyPageParameters
you can imagine in your tests and you avoided the coupling that proved to be disadvantageous.You could use an anonymous (or subclass) of TestPanelSource with the page and panel already created.
If you use this a lot a subclass of TestPanelSource might be best to be able to pass the parameters into your sub-class' constructor and other configurable items of your interest.