01: // Copyright 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.upload.services;
16:
17: import org.apache.tapestry.services.HttpServletRequestHandler;
18: import org.apache.tapestry.test.TapestryTestCase;
19: import org.apache.tapestry.upload.services.MultipartDecoder;
20: import org.apache.tapestry.upload.services.MultipartServletRequestFilter;
21: import org.testng.annotations.Test;
22:
23: import javax.servlet.http.HttpServletRequest;
24: import javax.servlet.http.HttpServletResponse;
25:
26: public class MultipartServletRequestFilterTest extends TapestryTestCase {
27:
28: @Test
29: public void normalRequestDoesNothing() throws Exception {
30: MultipartDecoder decoder = newMock(MultipartDecoder.class);
31: HttpServletRequest request = mockHttpServletRequest();
32: HttpServletResponse response = mockHttpServletResponse();
33: HttpServletRequestHandler handler = newMock(HttpServletRequestHandler.class);
34:
35: MultipartServletRequestFilter filter = new MultipartServletRequestFilter(
36: decoder);
37:
38: expect(request.getMethod()).andReturn("get");
39:
40: expect(handler.service(request, response)).andReturn(true);
41:
42: replay();
43:
44: boolean isHandled = filter.service(request, response, handler);
45: assertTrue(isHandled);
46: verify();
47: }
48:
49: @Test
50: public void multipartRequestIsDecoded() throws Exception {
51: MultipartDecoder decoder = newMock(MultipartDecoder.class);
52: HttpServletRequest request = mockHttpServletRequest();
53: HttpServletRequest decodedRequest = mockHttpServletRequest();
54: HttpServletResponse response = mockHttpServletResponse();
55: HttpServletRequestHandler handler = newMock(HttpServletRequestHandler.class);
56:
57: MultipartServletRequestFilter filter = new MultipartServletRequestFilter(
58: decoder);
59:
60: expect(request.getMethod()).andReturn("post");
61: expect(request.getContentType()).andReturn("multipart/form");
62: expect(decoder.decode(request)).andReturn(decodedRequest);
63:
64: expect(handler.service(decodedRequest, response)).andReturn(
65: true);
66:
67: replay();
68:
69: boolean isHandled = filter.service(request, response, handler);
70: assertTrue(isHandled);
71: verify();
72: }
73: }
|