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

天大地大妈咪最大 提交于 2019-12-10 15:26:37

问题


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);

回答1:


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);  


来源:https://stackoverflow.com/questions/8415330/how-to-test-ajaxeventbehavioronclick-for-apache-wicket-radio-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!