use of org.apache.tapestry5.FieldValidator 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.FieldValidator in project tapestry-5 by apache.
the class UploadTest method process_submission_extracts_value_from_decoder.
@SuppressWarnings({ "unchecked" })
@Test
public void process_submission_extracts_value_from_decoder() throws Exception {
MultipartDecoder decoder = mockMultipartDecoder();
UploadedFile uploadedFile = mockUploadedFile();
ComponentResources resources = mockComponentResources();
FieldValidationSupport support = mockFieldValidationSupport();
FieldValidator validate = mockFieldValidator();
Upload component = new Upload(null, validate, decoder, null, resources, support);
expect(decoder.getFileUpload("test")).andReturn(uploadedFile);
expect(uploadedFile.getFileName()).andReturn("foo").anyTimes();
support.validate(uploadedFile, resources, validate);
replay();
component.processSubmission("test");
verify();
assertSame(component.getValue(), uploadedFile);
}
use of org.apache.tapestry5.FieldValidator in project tapestry-5 by apache.
the class UploadTest method process_submission_ignores_null_value.
@SuppressWarnings({ "unchecked" })
@Test
public void process_submission_ignores_null_value() throws Exception {
MultipartDecoder decoder = mockMultipartDecoder();
UploadedFile uploadedFile = mockUploadedFile();
ComponentResources resources = mockComponentResources();
FieldValidationSupport support = mockFieldValidationSupport();
FieldValidator validate = mockFieldValidator();
Upload component = new Upload(null, validate, decoder, null, resources, support);
expect(decoder.getFileUpload("test")).andReturn(uploadedFile);
expect(uploadedFile.getFileName()).andReturn("").atLeastOnce();
support.validate(null, resources, validate);
replay();
component.processSubmission("test");
verify();
assertNull(component.getValue());
}
use of org.apache.tapestry5.FieldValidator 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.FieldValidator in project tapestry-5 by apache.
the class UploadTest method process_submission_tracks_validator_errors.
@SuppressWarnings({ "unchecked", "ThrowableInstanceNeverThrown" })
@Test
public void process_submission_tracks_validator_errors() throws Exception {
MultipartDecoder decoder = mockMultipartDecoder();
UploadedFile uploadedFile = mockUploadedFile();
FieldValidator<Object> validate = mockFieldValidator();
ValidationTracker tracker = mockValidationTracker();
ComponentResources resources = mockComponentResources();
FieldValidationSupport support = mockFieldValidationSupport();
Upload component = new Upload(null, validate, decoder, tracker, resources, support);
expect(decoder.getFileUpload("test")).andReturn(uploadedFile);
expect(uploadedFile.getFileName()).andReturn("test").atLeastOnce();
support.validate(uploadedFile, resources, validate);
expectLastCall().andThrow(new ValidationException("an error"));
tracker.recordError(component, "an error");
replay();
component.processSubmission("test");
verify();
}
Aggregations