Search in sources :

Example 11 with FormTester

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

the class MultiFileUploadFieldTest method submitMultiFileUploadFields.

/**
 * FormTester supports MultiFileUploadField
 *
 * https://issues.apache.org/jira/browse/WICKET-5346
 */
@Test
public void submitMultiFileUploadFields() {
    final AtomicBoolean submitted = new AtomicBoolean(false);
    final ListModel<FileUpload> filesModel = new ListModel<>(new ArrayList<FileUpload>());
    TestPage page = new TestPage(filesModel) {

        @Override
        protected void onSubmit() {
            super.onSubmit();
            List<FileUpload> uploads = filesModel.getObject();
            assertEquals(2, uploads.size());
            for (int i = 0; i < 2; i++) {
                FileUpload fileUpload = uploads.get(i);
                String clientFileName = fileUpload.getClientFileName();
                String id = clientFileName.replaceAll(MultiFileUploadFieldTest.class.getSimpleName() + "(\\d).txt", "$1");
                try {
                    assertEquals("Test" + id, IOUtils.toString(fileUpload.getInputStream()));
                } catch (IOException e) {
                    fail("Reading file upload '" + id + "' failed: " + e.getMessage());
                }
            }
            submitted.set(true);
        }
    };
    tester.startPage(page);
    tester.assertContainsNot("disabled=\"disabled\"");
    FormTester ft = tester.newFormTester("f");
    ft.setFile("muf", new File("target/test-classes/org/apache/wicket/markup/html/form/upload/MultiFileUploadFieldTest0.txt"), "plain/text");
    ft.setFile("muf", new File("target/test-classes/org/apache/wicket/markup/html/form/upload/MultiFileUploadFieldTest1.txt"), "plain/text");
    ft.submit();
    assertEquals("The form is not submitted", true, submitted.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ListModel(org.apache.wicket.model.util.ListModel) FormTester(org.apache.wicket.util.tester.FormTester) IOException(java.io.IOException) File(org.apache.wicket.util.file.File) Test(org.junit.Test)

Example 12 with FormTester

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

the class FormValidatorBehaviorTest method actAsValidator.

/**
 * Tests validators are treated as validators
 */
@Test
public void actAsValidator() {
    TestPage page = new TestPage();
    tester.startPage(page);
    FormTester ft = tester.newFormTester("form");
    ft.setValue("name", "999999999");
    ft.submit();
    assertEquals(0, new FeedbackCollector(page).collect().size());
    MaxLenValidator max = new MaxLenValidator(page.name);
    page.form.add(max);
    ft = tester.newFormTester("form");
    ft.setValue("name", "999999999");
    ft.submit();
    assertEquals(1, new FeedbackCollector(page).collect().size());
    assertEquals("MAX", new FeedbackCollector(page).collect().get(0).getMessage().toString());
    ft = tester.newFormTester("form");
    ft.setValue("name", "22");
    ft.submit();
    assertEquals(0, new FeedbackCollector(page).collect().size());
    MinLenValidator min = new MinLenValidator(page.name);
    page.form.add(min);
    ft = tester.newFormTester("form");
    ft.setValue("name", "22");
    ft.submit();
    assertEquals(1, new FeedbackCollector(page).collect().size());
    assertEquals("MINIMUM", new FeedbackCollector(page).collect().get(0).getMessage().toString());
    ft = tester.newFormTester("form");
    ft.setValue("name", "7777777");
    ft.submit();
    assertEquals(0, new FeedbackCollector(page).collect().size());
    page.form.remove(min);
    ft = tester.newFormTester("form");
    ft.setValue("name", "22");
    ft.submit();
    assertEquals(0, new FeedbackCollector(page).collect().size());
    page.form.remove(max);
    ft = tester.newFormTester("form");
    ft.setValue("name", "999999999");
    ft.submit();
    assertEquals(0, new FeedbackCollector(page).collect().size());
}
Also used : FormTester(org.apache.wicket.util.tester.FormTester) FeedbackCollector(org.apache.wicket.feedback.FeedbackCollector) Test(org.junit.Test)

Example 13 with FormTester

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

the class HomePageTest method withoutBorder2.

/**
 */
@Test
public void withoutBorder2() {
    FormTester formTester = tester.newFormTester("form");
    formTester.setValue("textfield1", "testxxx");
    tester.executeAjaxEvent("form:submit", "click");
    tester.assertNoErrorMessage();
    assertFalse(((HomePage) tester.getLastRenderedPage()).hitOnError);
    assertTrue(((HomePage) tester.getLastRenderedPage()).hitOnSubmit);
}
Also used : FormTester(org.apache.wicket.util.tester.FormTester) Test(org.junit.Test)

Example 14 with FormTester

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

the class NestedFormSubmitTest method assertFormSubmitInner.

private void assertFormSubmitInner(boolean expectSubmittedOuter, boolean expectSubmittedMiddle, boolean expectSubmittedInner) {
    FormTester form = tester.newFormTester(page.outer.getPageRelativePath());
    form.submit("middle:inner:submit");
    assertFormsAreSubmitted(expectSubmittedOuter, expectSubmittedMiddle, expectSubmittedInner);
}
Also used : FormTester(org.apache.wicket.util.tester.FormTester)

Example 15 with FormTester

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

the class NumberTextFieldTest method convertDouble.

/**
 * WICKET-4884, WICKET-3591
 */
@Test
public void convertDouble() {
    TestPage<Double> testPage = new TestPage<Double>();
    testPage.textField.setType(Double.class);
    testPage.textField.setMinimum(new Double("0.0"));
    testPage.textField.setMaximum(new Double("2000.0"));
    testPage.textField.setModelObject(new Double("1000.0"));
    tester.startPage(testPage);
    String response = tester.getLastResponseAsString();
    assertTrue(response.contains("<input wicket:id=\"number\" type=\"number\" value=\"1000.0\" name=\"number\" min=\"0.0\" max=\"2000.0\"/>"));
    FormTester formTester = tester.newFormTester(testPage.form.getId());
    formTester.setValue(testPage.textField.getId(), "2,000.00");
    formTester.submit();
    assertEquals(new Double("2000.00"), testPage.textField.getDefaultModelObject());
}
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