如何测试AjaxEventBehavior("的onClick")的Apache Wicket的单选按钮? [英] How to test AjaxEventBehavior("onClick") for Apache Wicket radio button?
问题描述
我使用的Apache Wicket的,我碰到有关测试AjaxEventBehavior一个单选按钮的麻烦。其实我想测试的onClick事件就像我的情况下,当我选择/点击一个单选按钮从RadioGroup中一个specif页面的呈现方式。
code片断:
RadioGroup中<布尔> selectPageRadioGroup =
新RadioGroup中<布尔>(selectPageRadioGroup,新的模式和LT;布尔>(Boolean.TRUE));
selectPageRadioGroup.setDefaultModel(新型号:LT;布尔>(Boolean.TRUE));
最后的广播LT;布尔> radioButton1 =
新的广播LT;布尔>(radioButton1,新的模式和LT;布尔>(Boolean.FALSE));
radioButton1.add(新AjaxEventBehavior(onclick事件){
@覆盖
保护无效的onEvent(AjaxRequestTarget目标){
setResponsePage(MyWebPage.class);
}
});
selectPageRadioGroup.add(radioButton1);
假设你已经做了
WicketTester测试仪=新WicketTester();
tester.startPage(PageContainingRadioButton.class);
或类似的 startPanel
(检票1.4)或者 startComponent
(检票1.5),让您的测试已经呈现包含按钮在已知路径页面,你应该能够使WicketTester模拟像
tester.executeAjaxEvent(布拉布拉:形式:selectPageRadioGroup:radioButton1,onclick事件);
(你需要调整,当然这条道路。)
,然后检查它是否做了正确的事与
tester.assertRenderedPage(MyWebPage.class);
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);
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);
这篇关于如何测试AjaxEventBehavior(&QUOT;的onClick&QUOT;)的Apache Wicket的单选按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!