use of org.apache.tapestry5.upload.services.UploadedFile 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.upload.services.UploadedFile 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.upload.services.UploadedFile 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();
}
use of org.apache.tapestry5.upload.services.UploadedFile in project tapestry-5 by apache.
the class UploadTest method process_submission_calls_validator.
@SuppressWarnings("unchecked")
@Test
public void process_submission_calls_validator() throws Exception {
MultipartDecoder decoder = mockMultipartDecoder();
UploadedFile uploadedFile = mockUploadedFile();
FieldValidator<Object> validate = mockFieldValidator();
ComponentResources resources = mockComponentResources();
FieldValidationSupport support = mockFieldValidationSupport();
Upload component = new Upload(null, validate, decoder, null, resources, support);
expect(decoder.getFileUpload("test")).andReturn(uploadedFile);
expect(uploadedFile.getFileName()).andReturn("test").atLeastOnce();
support.validate(uploadedFile, resources, validate);
replay();
component.processSubmission("test");
verify();
}
use of org.apache.tapestry5.upload.services.UploadedFile in project tapestry-5 by apache.
the class Upload method processSubmission.
@SuppressWarnings({ "unchecked" })
@Override
protected void processSubmission(String controlName) {
UploadedFile uploaded = decoder.getFileUpload(controlName);
if (uploaded != null && (uploaded.getFileName() == null || uploaded.getFileName().length() == 0)) {
uploaded = null;
}
try {
fieldValidationSupport.validate(uploaded, resources, validate);
} catch (ValidationException ex) {
validationTracker.recordError(this, ex.getMessage());
}
value = uploaded;
}
Aggregations