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.add(max);
ft = tester.newFormTester("form");
ft.setValue("name", "999999999");
ft.submit();
assertEquals(1, new FeedbackCollector(page).collect().size());
// WICKET-5115 variables in default message are not substituted (was the case in 1.5.x)
assertEquals("MAX ${len}", 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.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.name.remove(min);
ft = tester.newFormTester("form");
ft.setValue("name", "22");
ft.submit();
assertEquals(0, new FeedbackCollector(page).collect().size());
page.name.remove(max);
ft = tester.newFormTester("form");
ft.setValue("name", "999999999");
ft.submit();
assertEquals(0, new FeedbackCollector(page).collect().size());
}