use of org.apache.tapestry5.Validator in project tapestry-5 by apache.
the class UploadTest method begin_render_writes_input_tag.
@Test
public void begin_render_writes_input_tag() throws Exception {
MarkupWriter writer = createMarkupWriter();
writer.element("form");
FormSupport formSupport = mockFormSupport();
ComponentResources resources = mockComponentResources();
FieldValidator validator = mockFieldValidator();
Request request = mockRequest();
train_isXHR(request, false);
formSupport.setEncodingType(Upload.MULTIPART_ENCTYPE);
validator.render(writer);
resources.renderInformalParameters(writer);
replay();
Upload component = new Upload(null, null, null, null, resources, null);
component.injectDecorator(new BaseValidationDecorator()).injectFormSupport(formSupport).injectFieldValidator(validator).injectRequest(request);
component.beginRender(writer);
Element element = writer.getElement();
assertNotNull(element);
assertEquals(element.getName(), "input");
assertEquals(element.getAttribute("type"), "file");
// assertEquals(element.getAttribute("name"),null);
// assertEquals(element.getAttribute("id"),null);
verify();
}
use of org.apache.tapestry5.Validator in project tapestry-5 by apache.
the class UploadTest method validation_decorator_invoked_inside_begin_render.
@Test
public void validation_decorator_invoked_inside_begin_render() throws Exception {
getMocksControl().checkOrder(true);
ComponentResources resources = mockComponentResources();
Upload component = new Upload(null, null, null, null, resources, null);
MarkupWriter writer = createMarkupWriter();
writer.element("form");
FieldValidator validator = mockFieldValidator();
Request request = mockRequest();
FormSupport formSupport = mockFormSupport();
formSupport.setEncodingType(Upload.MULTIPART_ENCTYPE);
component.injectFormSupport(formSupport).injectRequest(request);
ValidationDecorator decorator = mockValidationDecorator();
component.injectDecorator(decorator).injectFieldValidator(validator);
validator.render(writer);
resources.renderInformalParameters(writer);
decorator.insideField(component);
train_isXHR(request, false);
replay();
component.beginRender(writer);
verify();
}
use of org.apache.tapestry5.Validator 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.Validator 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.Validator 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();
}
Aggregations