1 15 package org.apache.tapestry.multipart; 16 17 import java.io.IOException ; 18 19 import javax.servlet.ServletException ; 20 import javax.servlet.http.HttpServletRequest ; 21 import javax.servlet.http.HttpServletResponse ; 22 23 import org.apache.hivemind.test.HiveMindTestCase; 24 import org.apache.tapestry.services.ServletRequestServicer; 25 import org.easymock.MockControl; 26 27 33 public class TestMultipartDecoderFilter extends HiveMindTestCase 34 { 35 private static class MockServicer implements ServletRequestServicer 36 { 37 HttpServletRequest _request; 38 39 public void service(HttpServletRequest request, HttpServletResponse response) 40 throws IOException , ServletException 41 { 42 _request = request; 43 } 44 } 45 46 private HttpServletRequest newRequest(String contentType) 47 { 48 MockControl control = newControl(HttpServletRequest .class); 49 HttpServletRequest request = (HttpServletRequest ) control.getMock(); 50 51 request.getContentType(); 52 control.setReturnValue(contentType); 53 54 return request; 55 } 56 57 private HttpServletResponse newResponse() 58 { 59 return (HttpServletResponse ) newMock(HttpServletResponse .class); 60 } 61 62 public void testNormalRequest() throws Exception 63 { 64 HttpServletRequest request = newRequest("application/x-www-form-urlencoded"); 65 HttpServletResponse response = newResponse(); 66 67 MockServicer servicer = new MockServicer(); 68 69 replayControls(); 70 71 MultipartDecoderFilter f = new MultipartDecoderFilter(); 72 73 f.service(request, response, servicer); 74 75 assertSame(request, servicer._request); 76 77 verifyControls(); 78 } 79 80 public void testUploadRequest() throws Exception 81 { 82 HttpServletRequest request = newRequest("multipart/form-data"); 83 HttpServletResponse response = newResponse(); 84 HttpServletRequest decoded = (HttpServletRequest ) newMock(HttpServletRequest .class); 85 86 MockControl control = newControl(MultipartDecoder.class); 87 MultipartDecoder decoder = (MultipartDecoder) control.getMock(); 88 89 decoder.decode(request); 90 control.setReturnValue(decoded); 91 92 decoder.cleanup(); 93 94 MockServicer servicer = new MockServicer(); 95 96 replayControls(); 97 98 MultipartDecoderFilter f = new MultipartDecoderFilter(); 99 f.setDecoder(decoder); 100 101 f.service(request, response, servicer); 102 103 assertSame(decoded, servicer._request); 104 105 verifyControls(); 106 } 107 } | Popular Tags |