use of org.apache.tapestry5.Validator in project tapestry-5 by apache.
the class MaxLengthTest method long_value.
@Test
public void long_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();
MaxLength validator = new MaxLength(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 MaxTest method value_too_large.
@Test
public void value_too_large() throws Exception {
String label = "My Field";
Field field = mockFieldWithLabel(label);
MessageFormatter formatter = mockMessageFormatter();
String message = "{message}";
Long constraint = 100l;
Number value = 101;
train_format(formatter, message, constraint, label);
Max validator = new Max(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 MinLengthTest method long_enough.
@Test
public void long_enough() throws Exception {
Field field = mockField();
MessageFormatter formatter = mockMessageFormatter();
String value = "Now the student has become the master.";
replay();
MinLength validator = new MinLength(null);
validator.validate(field, value.length(), formatter, value);
verify();
}
use of org.apache.tapestry5.Validator in project tapestry-5 by apache.
the class RegexpTest method input_mismatch.
@Test
public void input_mismatch() throws Exception {
String label = "My Field";
Field field = mockFieldWithLabel(label);
MessageFormatter formatter = mockMessageFormatter();
String message = "{message}";
Pattern constraint = Pattern.compile("\\d{4}");
String value = "abc";
train_format(formatter, message, constraint.toString(), label);
replay();
Regexp validator = new Regexp(null);
try {
validator.validate(field, constraint, formatter, value);
unreachable();
} catch (ValidationException ex) {
assertEquals(ex.getMessage(), message);
}
verify();
}
Aggregations