use of org.apache.wicket.util.tester.FormTester in project wicket by apache.
the class Signin2Test method testSignIn2.
/**
* Test page.
*/
@Test
public void testSignIn2() {
WicketTester tester = new WicketTester(new SignIn2Application());
try {
tester.startPage(Home.class);
tester.assertRenderedPage(SignIn2.class);
FormTester formTester = tester.newFormTester("signInPanel:signInForm");
formTester.setValue("username", "wicket");
formTester.setValue("password", "wicket");
formTester.setValue("rememberMeContainer:rememberMe", "true");
formTester.submit();
tester.assertRenderedPage(Home.class);
// a) With wicket submitting a form will result in a temporary redirect,
// with the redirect setting the Cookie.
// b) jWebUnits Cookie test methods are all using the http response
// object only
// c) Like a browser, jwebunit will automatically handle the redirect
// request
// Hence dumpCookie will not print an Cookie and assertCookiePresent
// will
// fail.
// The only mean available is to indirectly test the cookies. Indirectly
// because
// the screen flow depends on the cookies.
// this.dumpCookies(System.err);
// this.assertCookiePresent("signInPanel.signInForm.username");
// this.assertCookiePresent("signInPanel.signInForm.password");
Collection<Cookie> cookies = tester.getLastResponse().getCookies();
for (Cookie cookie : cookies) {
if ("signInPanel.signInForm.username".equals(cookie.getName())) {
assertEquals("wicket", cookie.getValue());
}
}
tester.startPage(SignOut.class);
tester.assertRenderedPage(SignOut.class);
tester.startPage(Home.class);
tester.assertRenderedPage(SignIn2.class);
} finally {
tester.destroy();
}
}
use of org.apache.wicket.util.tester.FormTester in project wicket by apache.
the class GuestbookTest method test_1.
/**
* Test page.
*
* @throws Exception
*/
@Test
public void test_1() throws Exception {
tester.startPage(GuestBook.class);
tester.assertContains("Wicket Examples - guestbook");
// check if the list of comments is empty
tester.assertListView("comments", new ArrayList<>());
tester.assertComponent("commentForm", Form.class);
FormTester formTester = tester.newFormTester("commentForm");
formTester.setValue("text", "test-1");
formTester.submit();
tester.assertModelValue("comments:0:text", "test-1");
formTester = tester.newFormTester("commentForm");
formTester.setValue("text", "test-2");
formTester.submit();
tester.assertModelValue("comments:0:text", "test-2");
tester.assertModelValue("comments:1:text", "test-1");
formTester = tester.newFormTester("commentForm");
formTester.setValue("text", "test-3");
formTester.setValue("comment", "test-3");
formTester.submit();
tester.assertModelValue("comments:0:text", "test-2");
tester.assertModelValue("comments:1:text", "test-1");
tester.assertErrorMessages("Caught a spammer!!!");
}
use of org.apache.wicket.util.tester.FormTester in project wicket by apache.
the class LibraryTest method test_1.
/**
* Test page.
*
* @throws Exception
*/
@Test
public void test_1() throws Exception {
WicketTester tester = new WicketTester(new LibraryApplication());
try {
tester.startPage(SignIn.class);
tester.assertContains("Wicket Examples - library");
tester.assertContains("Username and password are both");
FormTester formTester = tester.newFormTester("signInPanel:signInForm");
formTester.setValue("username", "wicket");
formTester.setValue("password", "wicket");
formTester.submit();
tester.assertRenderedPage(Home.class);
tester.assertContains("Wicket Examples - library");
tester.assertLabel("books:0:author", "Effective Java (Joshua Bloch)");
} finally {
tester.destroy();
}
}
use of org.apache.wicket.util.tester.FormTester in project wicket by apache.
the class InsertContactTest method testErrorMessagesInsertContact.
@Test
public void testErrorMessagesInsertContact() {
Class<InsertContact> pageClass = InsertContact.class;
getWicketTester().startPage(pageClass);
getWicketTester().assertRenderedPage(pageClass);
FormTester formTester = getWicketTester().newFormTester(INSERT_FORM);
formTester.submit();
getWicketTester().assertErrorMessages(NAME_IS_REQUIRED, EMAIL_IS_REQUIRED);
log.info("Required Messages: " + NAME_IS_REQUIRED + " and " + EMAIL_IS_REQUIRED);
getWicketTester().assertRenderedPage(pageClass);
}
use of org.apache.wicket.util.tester.FormTester in project wicket by apache.
the class FormDispatchEventTest method dropDownEvent.
/**
* @throws Exception
*/
@Test
public void dropDownEvent() throws Exception {
tester.startPage(MockPageWithForm.class);
FormTester formTester = tester.newFormTester("form");
formTester.select("dropdown", 0);
formTester.submit();
MockPageWithForm page = (MockPageWithForm) tester.getLastRenderedPage();
assertTrue("Form.onSubmit() should have been called", page.isSubmitted());
assertTrue("DropDownChoice.onSelectionChanged() should have been called", page.isSelected());
}
Aggregations