use of org.apache.tapestry5.Validator in project tapestry-5 by apache.
the class MaxTest method small_enough.
@Test
public void small_enough() throws Exception {
Field field = mockField();
MessageFormatter formatter = mockMessageFormatter();
Long constraint = 50L;
Max validator = new Max(null, mockHtml5Support());
replay();
for (int value = 48; value <= 50; value++) validator.validate(field, constraint, formatter, value);
verify();
}
use of org.apache.tapestry5.Validator in project tapestry-5 by apache.
the class MinLengthTest method short_value.
@Test
public void short_value() throws Exception {
String label = "My Field";
Field field = mockFieldWithLabel(label);
MessageFormatter formatter = mockMessageFormatter();
String value = "Now the student has become the master.";
String message = "{message}";
Integer constraint = value.length() + 1;
train_format(formatter, message, constraint, label);
replay();
MinLength validator = new MinLength(null);
try {
validator.validate(field, constraint, formatter, value);
unreachable();
} catch (ValidationException ex) {
assertEquals(ex.getMessage(), message);
}
verify();
}
use of org.apache.tapestry5.Validator in project tapestry-5 by apache.
the class MinTest method large_enough.
@Test
public void large_enough() throws Exception {
Field field = mockField();
MessageFormatter formatter = mockMessageFormatter();
Long constraint = 50L;
Min validator = new Min(null, mockHtml5Support());
replay();
for (int value = 50; value < 52; value++) validator.validate(field, constraint, formatter, value);
verify();
}
use of org.apache.tapestry5.Validator in project tapestry-5 by apache.
the class MinTest method value_too_small.
@Test
public void value_too_small() throws Exception {
String label = "My Field";
Field field = mockFieldWithLabel(label);
MessageFormatter formatter = mockMessageFormatter();
String message = "{message}";
Long constraint = 100l;
Number value = 99;
train_format(formatter, message, constraint, label);
Min validator = new Min(null, mockHtml5Support());
replay();
try {
validator.validate(field, constraint, formatter, value);
unreachable();
} catch (ValidationException ex) {
assertEquals(ex.getMessage(), message);
}
verify();
}
use of org.apache.tapestry5.Validator in project tapestry-5 by apache.
the class RegexpTest method matching_pattern.
@Test
public void matching_pattern() throws Exception {
Field field = mockField();
MessageFormatter formatter = mockMessageFormatter();
Pattern constraint = Pattern.compile("\\d{4}");
replay();
Regexp validator = new Regexp(null);
validator.validate(field, constraint, formatter, "1234");
verify();
}
Aggregations