Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test AjaxEventBehavior("onClick") for Apache Wicket radio button?

I'm using apache wicket and I run into trouble regarding testing the AjaxEventBehavior for a Radio button. Actually I want to test the "onClick" event like in my case when I select/click a radio button from a RadioGroup a specif page is rendered.

Code snippet:

RadioGroup<Boolean> selectPageRadioGroup =
        new RadioGroup<Boolean>("selectPageRadioGroup", new Model<Boolean>(Boolean.TRUE));
selectPageRadioGroup.setDefaultModel(new Model<Boolean>(Boolean.TRUE));
final Radio<Boolean> radioButton1 =
        new Radio<Boolean>("radioButton1", new Model<Boolean>(Boolean.FALSE));
radioButton1.add(new AjaxEventBehavior("onclick") {
    @Override
    protected void onEvent(AjaxRequestTarget target) {
        setResponsePage(MyWebPage.class);
    }
});
selectPageRadioGroup.add(radioButton1);
like image 399
sakhan Avatar asked Dec 07 '11 12:12

sakhan


1 Answers

Assuming you have already done

WicketTester tester = new WicketTester();
tester.startPage(PageContainingRadioButton.class);

or a similar startPanel (Wicket 1.4) or startComponent (Wicket 1.5), so that your test has rendered a page containing the button at a known path you should be able to make WicketTester simulate the ajax behavior by something like

tester.executeAjaxEvent("blabla:form:selectPageRadioGroup:radioButton1", "onclick");

(You'll need to adjust that path of course.)

and then check that it did the right thing with

tester.assertRenderedPage(MyWebPage.class);  
like image 178
Don Roby Avatar answered Oct 12 '22 23:10

Don Roby