use of org.apache.tapestry5.upload.services.MultipartDecoder in project tapestry-5 by apache.
the class MultipartServletRequestFilterTest method multipartRequestIsDecoded.
@Test
public void multipartRequestIsDecoded() throws Exception {
MultipartDecoder decoder = newMock(MultipartDecoder.class);
HttpServletRequest request = mockHttpServletRequest();
HttpServletRequest decodedRequest = mockHttpServletRequest();
HttpServletResponse response = mockHttpServletResponse();
HttpServletRequestHandler handler = newMock(HttpServletRequestHandler.class);
MultipartServletRequestFilter filter = new MultipartServletRequestFilter(decoder);
expect(request.getMethod()).andReturn("post");
expect(request.getContentType()).andReturn("multipart/form");
expect(decoder.decode(request)).andReturn(decodedRequest);
expect(handler.service(decodedRequest, response)).andReturn(true);
replay();
boolean isHandled = filter.service(request, response, handler);
assertTrue(isHandled);
verify();
}
use of org.apache.tapestry5.upload.services.MultipartDecoder 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.MultipartDecoder 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.MultipartDecoder 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.MultipartDecoder in project tapestry-5 by apache.
the class MultipartServletRequestFilterTest method normalRequestDoesNothing.
@Test
public void normalRequestDoesNothing() throws Exception {
MultipartDecoder decoder = newMock(MultipartDecoder.class);
HttpServletRequest request = mockHttpServletRequest();
HttpServletResponse response = mockHttpServletResponse();
HttpServletRequestHandler handler = newMock(HttpServletRequestHandler.class);
MultipartServletRequestFilter filter = new MultipartServletRequestFilter(decoder);
expect(request.getMethod()).andReturn("get");
expect(handler.service(request, response)).andReturn(true);
replay();
boolean isHandled = filter.service(request, response, handler);
assertTrue(isHandled);
verify();
}
Aggregations