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 javax.servlet.http.HttpServletRequest;
21  
22  import org.seasar.extension.unit.S2TestCase;
23  import org.seasar.framework.mock.servlet.MockHttpServletRequest;
24  
25  public class DefaultRequestParserImplTest extends S2TestCase {
26  
27  	public HttpServletRequest request;
28  
29  	public DefaultRequestParserImpl requestParser;
30  
31  	@Override
32  	protected void setUp() throws Exception {
33  		super.setUp();
34  		include(this.getClass().getName().replaceAll("\\.", "/") + ".dicon");
35  	}
36  
37  	public void testGetEmptyParameterMap() throws Throwable {
38  		Map<String, Object[]> parameterMap = requestParser
39  				.getParameterMap(request);
40  		assertEquals("parameterMap.size()", 0, parameterMap.size());
41  	}
42  
43  	public void testGetParameterMap() throws Throwable {
44  		MockHttpServletRequest mock = (MockHttpServletRequest) request;
45  		mock.setParameter("a", "12345");
46  		mock.setParameter("b", new String[] { "abc", "def" });
47  		Map<String, Object[]> parameterMap = requestParser
48  				.getParameterMap(request);
49  		assertEquals("parameterMap.size()", 2, parameterMap.size());
50  		Object[] a = parameterMap.get("a");
51  		assertEquals("a.length", 1, a.length);
52  		assertEquals("a[0]", "12345", a[0]);
53  		Object[] b = parameterMap.get("b");
54  		assertEquals("b.length", 2, b.length);
55  		assertEquals("b[0]", "abc", b[0]);
56  		assertEquals("b[1]", "def", b[1]);
57  	}
58  
59  	public void testIsParsable() {
60  		MockHttpServletRequest request = getRequest();
61  
62  		request.setContentType("application/x-www-form-urlencoded");
63  		assertTrue(requestParser.isParsable(request));
64  
65  		request.setContentType("multipart/form-data");
66  		assertTrue(requestParser.isParsable(request));
67  
68  		request.setContentType("application/atom+xml");
69  		assertTrue(requestParser.isParsable(request));
70  	}
71  
72  	public void testPriority() {
73  		assertEquals(DefaultRequestParserImpl.DEFAULT_PRIORITY,
74  				requestParser.getPriority());
75  	}
76  
77  }