use of org.apache.tapestry5.commons.MessageFormatter in project tapestry-5 by apache.
the class FieldValidatorSourceImpl method createValidator.
private FieldValidator createValidator(Field field, ValidatorSpecification spec, String overrideId, Messages overrideMessages) {
String validatorType = spec.getValidatorType();
assert InternalUtils.isNonBlank(validatorType);
Validator validator = validators.get(validatorType);
if (validator == null)
throw new IllegalArgumentException(String.format("Unknown validator type '%s'. Configured validators are %s.", validatorType, InternalUtils.join(InternalUtils.sortedKeys(validators))));
// I just have this thing about always treating parameters as finals, so
// we introduce a second variable to treat a mutable.
String formValidationid = formSupport.getFormValidationId();
Object coercedConstraintValue = computeConstraintValue(validatorType, validator, spec.getConstraintValue(), formValidationid, overrideId, overrideMessages);
MessageFormatter formatter = findMessageFormatter(formValidationid, overrideId, overrideMessages, validatorType, validator);
return new FieldValidatorImpl(field, coercedConstraintValue, formatter, validator, formSupport);
}
use of org.apache.tapestry5.commons.MessageFormatter in project tapestry-5 by apache.
the class EmailTest method input_mismatch.
@Test
public void input_mismatch() throws Exception {
Field field = mockField();
MessageFormatter formatter = mockMessageFormatter();
Html5Support html5Support = mockHtml5Support();
replay();
Email validator = new Email(null, html5Support);
try {
validator.validate(field, null, formatter, "invalid_email");
unreachable();
} catch (ValidationException ex) {
}
try {
validator.validate(field, null, formatter, "@mail.com");
unreachable();
} catch (ValidationException ex) {
}
// TAP5-2282
try {
validator.validate(field, null, formatter, "aaa@bbb/cc");
unreachable();
} catch (ValidationException ex) {
}
verify();
}
use of org.apache.tapestry5.commons.MessageFormatter in project tapestry-5 by apache.
the class MaxLengthTest method short_enough.
@Test
public void short_enough() throws Exception {
Field field = mockField();
MessageFormatter formatter = mockMessageFormatter();
String value = "Now the student has become the master.";
replay();
MaxLength validator = new MaxLength(null);
validator.validate(field, value.length(), formatter, value);
verify();
}
use of org.apache.tapestry5.commons.MessageFormatter 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.commons.MessageFormatter 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();
}
Aggregations