use of org.apache.wicket.util.tester.MockPageWithFormAndAjaxFormSubmitBehavior.Pojo in project wicket by apache.
the class WicketTesterTest method submittingFormWithAjaxEventSubmitsFormValues.
/**
*/
@Test
public void submittingFormWithAjaxEventSubmitsFormValues() {
tester.startPage(MockPageWithFormAndAjaxFormSubmitBehavior.class);
FormTester form = tester.newFormTester("form");
form.setValue("name", "New name");
tester.executeAjaxEvent(MockPageWithFormAndAjaxFormSubmitBehavior.EVENT_COMPONENT, "click");
MockPageWithFormAndAjaxFormSubmitBehavior page = (MockPageWithFormAndAjaxFormSubmitBehavior) tester.getLastRenderedPage();
Pojo pojo = page.getPojo();
assertEquals("New name", pojo.getName());
}
use of org.apache.wicket.util.tester.MockPageWithFormAndAjaxFormSubmitBehavior.Pojo in project wicket by apache.
the class WicketTesterTest method executeAjaxEvent_ajaxFormSubmitLink.
/**
* Test that the executeAjaxEvent "submits" the form if the event is a AjaxFormSubmitBehavior.
*/
@Test
public void executeAjaxEvent_ajaxFormSubmitLink() {
tester.startPage(MockPageWithFormAndAjaxFormSubmitBehavior.class);
// Get the page
MockPageWithFormAndAjaxFormSubmitBehavior page = (MockPageWithFormAndAjaxFormSubmitBehavior) tester.getLastRenderedPage();
Pojo pojo = page.getPojo();
assertEquals("Mock name", pojo.getName());
TextField<?> name = (TextField<?>) tester.getComponentFromLastRenderedPage("form:name");
assertEquals("Mock name", name.getValue());
assertFalse(page.isExecuted());
tester.getRequest().getPostParameters().setParameterValue(name.getInputName(), "Mock name");
// Execute the ajax event
tester.executeAjaxEvent(MockPageWithFormAndAjaxFormSubmitBehavior.EVENT_COMPONENT, "click");
assertTrue("AjaxFormSubmitBehavior.onSubmit() has not been executed in " + MockPageWithFormAndAjaxFormSubmitBehavior.class, page.isExecuted());
assertEquals("Mock name", ((TextField<?>) tester.getComponentFromLastRenderedPage("form:name")).getValue());
// The name of the pojo should still be the same. If the
// executeAjaxEvent weren't submitting the form the name would have been
// reset to null, because the form would have been updated but there
// wouldn't be any data to update it with.
assertNotNull("executeAjaxEvent() did not properly submit the form", pojo.getName());
assertEquals("Mock name", pojo.getName());
}