Reputation: 34281
I have a Wicket panel that has AbstractAjaxTimeBehavior, that I'd like to unit test. How can I trigger a ajax event during the unit test that end up calling AbstractAjaxTimeBehavior
's .onTimer(AjaxRequestTarget target)
method?
behavior = new AbstractAjaxTimerBehavior(Duration.seconds(pollingPeriodInSeconds)) {
protected void onTimer(AjaxRequestTarget target) {
// how to unit test this?
}
}
add(behavior);
Upvotes: 2
Views: 1478
Reputation: 36105
As the timer behavior won't fire itself as in the browser, you'll have to use executeBehavior(AbstractAjaxBehavior) yourself.
if (!timerBehavior.isStopped())
wicketTester.executeBehavior(timerBehavior);
Just have a look at the code of executeAllTimerBehaviors(MarkupContainer)
. Note that this method is for AjaxSelfUpdatingTimerBehavior
only.
Upvotes: 3