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.cubby.controller.CubbyConfiguration;
23  import org.seasar.cubby.controller.RequestParser;
24  import org.seasar.extension.unit.S2TestCase;
25  import org.seasar.framework.mock.servlet.MockHttpServletRequest;
26  
27  public class DefaultRequestParserImplTest extends S2TestCase {
28      
29  	public HttpServletRequest request;
30  
31  	public CubbyConfiguration cubbyConfiguration;
32  
33      @Override
34  	protected void setUp() throws Exception {
35  		super.setUp();
36  		include(this.getClass().getName().replaceAll("\\.", "/") + ".dicon");
37  	}
38  
39      public void testRequestParserType() {
40  		RequestParser requestParser = cubbyConfiguration.getRequestParser();
41  		assertTrue(DefaultRequestParserImpl.class.isAssignableFrom(requestParser.getClass()));
42      }
43  
44      public void testGetEmptyParameterMap() throws Throwable {
45  		RequestParser requestParser = cubbyConfiguration.getRequestParser();
46      	Map<String, Object[]> parameterMap = requestParser.getParameterMap(request);
47          assertEquals("parameterMap.size()", 0, parameterMap.size());
48      }
49  
50      public void testGetParameterMap() throws Throwable {
51  		RequestParser requestParser = cubbyConfiguration.getRequestParser();
52      	MockHttpServletRequest mock = (MockHttpServletRequest) request;
53      	mock.setParameter("a", "12345");
54      	mock.setParameter("b", new String[] { "abc", "def" });
55      	Map<String, Object[]> parameterMap = requestParser.getParameterMap(request);
56          assertEquals("parameterMap.size()", 2, parameterMap.size());
57          Object[] a = parameterMap.get("a");
58          assertEquals("a.length", 1, a.length);
59          assertEquals("a[0]", "12345", a[0]);
60          Object[] b = parameterMap.get("b");
61          assertEquals("b.length", 2, b.length);
62          assertEquals("b[0]", "abc", b[0]);
63          assertEquals("b[1]", "def", b[1]);
64      }
65  
66  }
67