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());
}
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());
}
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);
}
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);
}
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());
}
Aggregations