This turns out to be somewhat painful, at least in Wicket 1.4 (I have not tried with 1.5).
Through a web search, I found tips on Mischa Dasberg's blog . Basically, you cannot use the BaseWicketTester.executeAjaxEvent((String componentPath, String event)
method because the behavior you are using is not AjaxEventBehavior
and you cannot use BaseWicketTester.executeBehavior(final AbstractAjaxBehavior behavior)
because it destroys request parameters.
Mischa's solution was to implement his own executeBehavior
method in a parent test case that worked for his situation, but not for my need, as he suggested that the request parameter identifier was the same as the full path to the component.
I did something similar by implementing my own executeAjaxBehavior
in the WicketTester
extension, but assuming (as it was in my case) that the request parameter is the last ":" section of the separated component
public void executeAjaxBehavior(String path, String value) { AbstractAjaxBehavior behavior = (AbstractAjaxBehavior) getComponentFromLastRenderedPage(path).getBehaviors().get(0); CharSequence url = behavior.getCallbackUrl(false); WebRequestCycle cycle = setupRequestAndResponse(true); getServletRequest().setRequestToRedirectString(url.toString()); String[] ids = path.split(":"); String id = ids[ids.length-1]; getServletRequest().setParameter(id, value); processRequestCycle(cycle); }
Both his decision and mine (based on it) also suggest that behavior is the first (or only) component.
It's a bit awkward, but something like this might work for you.
Perhaps it would be better if the identifiers and behavior were obtained separately and passed as parameters, and, of course, you could find the first behavior, which was actually AjaxFormChoiceComponentUpdatingBehavior
instead of blithely assuming that this was the first behavior, but this is the beginning.
This is also similar code to what is inside the BaseWicketTester
class for other behavior testing methods that might be worth a look.
Don roby
source share