You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Emanuele Gesuato <eg...@ibc.it> on 2007/09/05 11:41:10 UTC
Checking behaviour in testcase
Hi there,
I'm trying to check the presence of a behaviour in a testcase.
I have a page with a checkbox and a button, if a user click on the
button without selecting the checkbox, an alert box show a message. If i
access to the page through a browser (firefox) the page runs fine and
the alert box is correctly displayed. So, i would like to retrieve the
behaviour from the form component after submitting the form itself, but
i can't find any behaviour (the list is empty!).
Why ? Is there something wrong with the testcase ?
Here there are the testcase and the webpage (html and java).
Thanks,
Emanuele
Here is the Testcase:
********
public class TestSimplePage extends TestCase{
public void testSimplePage(){
WicketTester tester = new WicketTester();
tester.startPage(SimplePage.class);
tester.submitForm("simpleForm");
Form simpleForm = (Form)
tester.getComponentFromLastRenderedPage("simpleForm");
assertNotNull(simpleForm.getBehaviors());
assertFalse(simpleForm.getBehaviors().isEmpty());
}
}
*******
Here is the webpage:
*******
public class SimplePage extends WebPage {
private static final long serialVersionUID = 8190084597165080916L;
public SimplePage(){
CompoundPropertyModel simpleModel = new CompoundPropertyModel(new
SimpleBean());
final Form form = new Form("simpleForm", simpleModel){
private static final long serialVersionUID = 8176126527045127325L;
public void onSubmit(){
SimpleBean simple = (SimpleBean) getModelObject();
if (! simple.isSelected()){
add(new Alert("not selected"));
}
}
};
form.add(new Button("btnok"));
form.add(new CheckBox("selected"));
add(form);
}
public class Alert extends AbstractBehavior {
private static final long serialVersionUID = 3346789663630395006L;
private String msg;
public Alert(String msg) {
this.msg=msg;
}
@Override
public boolean isTemporary() {
return true;
}
@Override
public void renderHead(IHeaderResponse response) {
response.renderOnLoadJavascript("alert('"+msg+"');");
}
}
public class SimpleBean implements Serializable{
private static final long serialVersionUID = -2386033376652365201L;
private boolean selected;
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
}
}
********
and here the html page (only the form):
********
<form name="simpleForm" wicket:id="simpleForm">
<table>
<tr>
<TD><b>Select</b></TD>
<td>
<input type="checkbox" wicket:id="selected"></td>
</tr>
</table>
<br>
<input type="submit" value="OK" wicket:id="btnok">
</form>
*******
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Checking behaviour in testcase
Posted by Emanuele Gesuato <eg...@ibc.it>.
Jean-Baptiste Quenot wrote:
>
> WicketTester has not the exact same request lifecycle as in a real
> webapp. Can it be because of isTemporary() returns true?
Yes it is. Thanks.
How could i test the presence of the behaviour **AND** mantain the
isTemporary with return false ?
Is it possible ?
Thanks in advance,
Emanuele
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Checking behaviour in testcase
Posted by Jean-Baptiste Quenot <jb...@apache.org>.
* Emanuele Gesuato:
> I'm trying to check the presence of a behaviour in a testcase.
>
> I have a page with a checkbox and a button, if a user click on
> the button without selecting the checkbox, an alert box show a
> message. If i access to the page through a browser (firefox) the
> page runs fine and the alert box is correctly displayed. So, i
> would like to retrieve the behaviour from the form component
> after submitting the form itself, but i can't find any behaviour
> (the list is empty!).
>
> Why ? Is there something wrong with the testcase ?
>
> <snip/>
>
> public class Alert extends AbstractBehavior {
> private static final long serialVersionUID = 3346789663630395006L;
> private String msg;
>
> public Alert(String msg) {
> this.msg=msg;
> }
>
> @Override
> public boolean isTemporary() {
> return true;
> }
WicketTester has not the exact same request lifecycle as in a real
webapp. Can it be because of isTemporary() returns true?
--
Jean-Baptiste Quenot
aka John Banana Qwerty
http://caraldi.com/jbq/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org