Search in sources :

Example 26 with FormTester

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();
    }
}
Also used : Cookie(javax.servlet.http.Cookie) FormTester(org.apache.wicket.util.tester.FormTester) WicketTester(org.apache.wicket.util.tester.WicketTester) SignIn2Application(org.apache.wicket.examples.authentication2.SignIn2Application) Test(org.junit.Test)

Example 27 with FormTester

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!!!");
}
Also used : FormTester(org.apache.wicket.util.tester.FormTester) Test(org.junit.Test)

Example 28 with FormTester

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();
    }
}
Also used : FormTester(org.apache.wicket.util.tester.FormTester) WicketTester(org.apache.wicket.util.tester.WicketTester) Test(org.junit.Test)

Example 29 with FormTester

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);
}
Also used : FormTester(org.apache.wicket.util.tester.FormTester) AbstractDeploymentTest(org.apache.wicket.arquillian.testing.deployment.AbstractDeploymentTest) Test(org.junit.Test)

Example 30 with FormTester

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());
}
Also used : FormTester(org.apache.wicket.util.tester.FormTester) Test(org.junit.Test)

Aggregations

FormTester (org.apache.wicket.util.tester.FormTester)207 Test (org.junit.Test)122 Test (org.junit.jupiter.api.Test)54 Component (org.apache.wicket.Component)50 WicketTester (org.apache.wicket.util.tester.WicketTester)14 AbstractInitializedGuiIntegrationTest (com.evolveum.midpoint.web.AbstractInitializedGuiIntegrationTest)9 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 Test (org.testng.annotations.Test)9 List (java.util.List)8 ListModel (org.apache.wicket.model.util.ListModel)7 ArrayList (java.util.ArrayList)6 File (org.apache.wicket.util.file.File)4 OrgType (com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)3 ButtonAjaxBehavior (com.googlecode.wicket.jquery.ui.widget.dialog.ButtonAjaxBehavior)3 LocalDate (java.time.LocalDate)3 Cookie (javax.servlet.http.Cookie)3 Page (org.apache.wicket.Page)3 LocalDateConverter (org.apache.wicket.util.convert.converter.LocalDateConverter)3 Ignore (org.junit.Ignore)3 RoleType (com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType)2