Search in sources :

Example 1 with MultipartDecoder

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();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MultipartDecoder(org.apache.tapestry5.upload.services.MultipartDecoder) HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpServletRequestHandler(org.apache.tapestry5.http.services.HttpServletRequestHandler) Test(org.testng.annotations.Test)

Example 2 with MultipartDecoder

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);
}
Also used : UploadedFile(org.apache.tapestry5.upload.services.UploadedFile) MultipartDecoder(org.apache.tapestry5.upload.services.MultipartDecoder) Test(org.testng.annotations.Test)

Example 3 with MultipartDecoder

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());
}
Also used : UploadedFile(org.apache.tapestry5.upload.services.UploadedFile) MultipartDecoder(org.apache.tapestry5.upload.services.MultipartDecoder) Test(org.testng.annotations.Test)

Example 4 with MultipartDecoder

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();
}
Also used : UploadedFile(org.apache.tapestry5.upload.services.UploadedFile) MultipartDecoder(org.apache.tapestry5.upload.services.MultipartDecoder) Test(org.testng.annotations.Test)

Example 5 with MultipartDecoder

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();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MultipartDecoder(org.apache.tapestry5.upload.services.MultipartDecoder) HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpServletRequestHandler(org.apache.tapestry5.http.services.HttpServletRequestHandler) Test(org.testng.annotations.Test)

Aggregations

MultipartDecoder (org.apache.tapestry5.upload.services.MultipartDecoder)6 Test (org.testng.annotations.Test)6 UploadedFile (org.apache.tapestry5.upload.services.UploadedFile)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 HttpServletRequestHandler (org.apache.tapestry5.http.services.HttpServletRequestHandler)2