1   /*
2    * Copyright 2004-2008 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.cubby.controller.impl;
17  
18  import java.util.Map;
19  
20  import org.seasar.cubby.controller.RequestParser;
21  import org.seasar.extension.unit.S2TestCase;
22  import org.seasar.framework.mock.servlet.MockHttpServletRequest;
23  
24  public class MultipartRequestParserImplTest extends S2TestCase {
25  
26  	public RequestParser requestParser;
27  
28  	@Override
29  	protected void setUp() throws Exception {
30  		super.setUp();
31  		include(this.getClass().getName().replaceAll("\\.", "/") + ".dicon");
32  	}
33  
34  	public void testGetEmptyParameterMap() throws Throwable {
35  		MockHttpServletRequest request = getRequest();
36  		Map<String, Object[]> parameterMap = requestParser
37  				.getParameterMap(request);
38  		assertEquals("parameterMap.size()", 0, parameterMap.size());
39  	}
40  
41  	public void testGetParameterMap() throws Throwable {
42  		MockHttpServletRequest request = getRequest();
43  		request.setParameter("a", "12345");
44  		request.setParameter("b", new String[] { "abc", "def" });
45  		Map<String, Object[]> parameterMap = requestParser
46  				.getParameterMap(request);
47  		assertEquals("parameterMap.size()", 2, parameterMap.size());
48  		Object[] a = parameterMap.get("a");
49  		assertEquals("a.length", 1, a.length);
50  		assertEquals("a[0]", "12345", a[0]);
51  		Object[] b = parameterMap.get("b");
52  		assertEquals("b.length", 2, b.length);
53  		assertEquals("b[0]", "abc", b[0]);
54  		assertEquals("b[1]", "def", b[1]);
55  	}
56  
57  	public void testIsParsable() {
58  		MockHttpServletRequest request = getRequest();
59  
60  		request.setContentType("application/x-www-form-urlencoded");
61  		assertFalse(requestParser.isParsable(request));
62  
63  		request.setContentType("multipart/form-data");
64  		assertTrue(requestParser.isParsable(request));
65  
66  		request.setContentType("application/atom+xml");
67  		assertFalse(requestParser.isParsable(request));
68  	}
69  
70  	public void testPriority() {
71  		assertEquals(DefaultRequestParserImpl.DEFAULT_PRIORITY - 1,
72  				requestParser.getPriority());
73  	}
74  
75  }