Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test AjaxFormChoiceComponentUpdatingBehavior in WicketTester

In my Wicket application I used one radio button with "yes" and "no" options. If I select "No", I should display one dropdown choice. I wrote code using AjaxFormChoiceComponentUpdatingBehavior. How do I unittest this using WicketTester?

like image 444
Robo Avatar asked May 30 '11 13:05

Robo


3 Answers

Solution for Wicket 1.5.x:

 AbstractAjaxBehavior behavior = (AbstractAjaxBehavior)WicketTesterHelper.
          findBehavior(getTester().getComponentFromLastRenderedPage("path:to:component"),
                        AjaxFormChoiceComponentUpdatingBehavior.class);
 getTester().executeBehavior(behavior);
like image 188
Grigorichev Denis Avatar answered Sep 23 '22 00:09

Grigorichev Denis


First select the radio button that you want.

form.select("path to radio button", 0/1)

Then execute ajax behaviour:

tester.executeBehavior((AbstractAjaxBehavior)tester.getComponentFromLastRenderedPage("path to radio buttons").getBehaviors().get(0));
like image 32
elahehab Avatar answered Sep 26 '22 00:09

elahehab


Here is my piece of code which works perfectly for me with select box but should fiat as well for radio button if you change Behaviour class. Needed steps are:

  • Insert new value into form (use FormTester)
  • Find behaviour
  • Execute behaviour on change

Here is an example of code:

//simulate insert new value
FormTester formTester = tester.newFormTester(PANEL_ID + FORM); 
formTester.setValue("selectBox", "newValue");
//Find onchange behaviour
AjaxFormComponentUpdatingBehavior behavior = 
       (AjaxFormComponentUpdatingBehavior) WicketTesterHelper.findBehavior(
       tester.getComponentFromLastRenderedPage(PANEL_ID + FORM + ":" + "selectBox"), 
       ajaxFormComponentUpdatingBehavior.class);
//execute onchange
tester.executeBehavior(behavior);

I missed the par how to update form value in previous answers.

like image 34
Baca Avatar answered Sep 24 '22 00:09

Baca