Search in sources :

Example 21 with FormTester

use of org.apache.wicket.util.tester.FormTester in project wicket by apache.

the class InterceptTest method formSubmit.

/**
 */
@Test
public void formSubmit() {
    // same as above but uses different technique to login
    tester.startPage(tester.getApplication().getHomePage());
    MockLoginPage loginPage = (MockLoginPage) tester.getLastRenderedPage();
    assertEquals(((MyMockWebApplication) tester.getApplication()).getLoginPage(), loginPage.getClass());
    FormTester form = tester.newFormTester("form");
    form.setValue("username", "admin");
    form.submit();
    assertEquals(tester.getApplication().getHomePage(), tester.getLastRenderedPage().getClass());
}
Also used : FormTester(org.apache.wicket.util.tester.FormTester) Test(org.junit.Test)

Example 22 with FormTester

use of org.apache.wicket.util.tester.FormTester in project wicket by apache.

the class InterceptTest method clickLink2.

/**
 */
@Test
public void clickLink2() {
    // same as above but uses different technique to login
    tester.startPage(tester.getApplication().getHomePage());
    MockLoginPage loginPage = (MockLoginPage) tester.getLastRenderedPage();
    assertEquals(((MyMockWebApplication) tester.getApplication()).getLoginPage(), loginPage.getClass());
    // bypass formTester completely to login but continue to intercept page
    FormTester formTester = tester.newFormTester("form");
    formTester.setValue("username", "admin");
    formTester.submit();
    tester.startPage(tester.getApplication().getHomePage());
    assertEquals(tester.getApplication().getHomePage(), tester.getLastRenderedPage().getClass());
    tester.clickLink(tester.getLastRenderedPage().get("link"));
    assertEquals(PageA.class, tester.getLastRenderedPage().getClass());
}
Also used : FormTester(org.apache.wicket.util.tester.FormTester) Test(org.junit.Test)

Example 23 with FormTester

use of org.apache.wicket.util.tester.FormTester in project wicket by apache.

the class AjaxFormSubmitBehaviorTest method innerFormSubmit.

/**
 * https://issues.apache.org/jira/browse/WICKET-6455
 */
@Test
public void innerFormSubmit() {
    tester.startPage(NestedFormTestPage.class);
    NestedFormTestPage homePage = (NestedFormTestPage) tester.getLastRenderedPage();
    assertFalse(homePage.innerSubmitted);
    FormTester formTester = tester.newFormTester("outer:inner");
    formTester.submit("submit");
    assertTrue(homePage.innerSubmitted);
}
Also used : FormTester(org.apache.wicket.util.tester.FormTester) Test(org.junit.Test)

Example 24 with FormTester

use of org.apache.wicket.util.tester.FormTester in project wicket by apache.

the class AjaxFormSubmitTest method submit.

@Test
public void submit() {
    AjaxFormSubmitTestPage page = new AjaxFormSubmitTestPage(true);
    tester.startPage(page);
    tester.assertRenderedPage(page.getClass());
    FormTester form = tester.newFormTester("form");
    form.setValue("txt1", "txt1");
    form.setValue("txt2", "txt2");
    // mark the button as the one being pressed. there is a 'p::' infront of name because wicket
    // escapes "submit" input names as they break browsers
    tester.getRequest().getPostParameters().setParameterValue("p::submit", "x");
    tester.submitForm(form.getForm());
    tester.assertRenderedPage(page.getClass());
    assertTrue((page.getFormSubmitted() & AjaxFormSubmitTestPage.FORM_SUBMIT) > 0);
    assertFalse((page.getFormSubmitted() & AjaxFormSubmitTestPage.FORM_ERROR) > 0);
    assertTrue((page.getFormSubmitted() & AjaxFormSubmitTestPage.BUTTON_SUBMIT) > 0);
    assertFalse((page.getFormSubmitted() & AjaxFormSubmitTestPage.BUTTON_ERROR) > 0);
    assertEquals("txt1", tester.getComponentFromLastRenderedPage("form:txt1").getDefaultModelObject());
    assertEquals("txt2", tester.getComponentFromLastRenderedPage("form:txt2").getDefaultModelObject());
}
Also used : FormTester(org.apache.wicket.util.tester.FormTester) Test(org.junit.Test)

Example 25 with FormTester

use of org.apache.wicket.util.tester.FormTester in project wicket by apache.

the class TestHomePage method testRenderMyPage.

@Test
public void testRenderMyPage() {
    // start and render the test page
    tester.startPage(HomePage.class);
    // assert rendered page class
    tester.assertRenderedPage(HomePage.class);
    FormTester formTester = tester.newFormTester("bookingForm");
    formTester.submit();
    tester.assertErrorMessages("Name is required");
}
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