View Javadoc

1   /*
2    * $Id: pom.xml 560558 2007-07-28 15:47:10Z apetrelli $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  package org.apache.struts2.components;
22  
23  import java.util.HashMap;
24  import java.util.Map;
25  
26  import org.apache.struts2.views.jsp.AbstractTagTest;
27  
28  /***
29   * Verifies correct operation of parameter merging.
30   * 
31   * Contributed by: Daniel Uribe
32   */
33  public class URLTest extends AbstractTagTest {
34      public void testIncludeGetDuplicateRequestParams() throws Exception {
35          String body = "";
36  
37          Map parameterMap = new HashMap();
38          parameterMap.put("param", new String[] { "1", "2", "3" });
39  
40          request.setQueryString("param=1&param=2&param=3");
41          request.setScheme("http");
42          request.setParameterMap(parameterMap);
43          URL url = new URL(stack, request, response);
44          url.setIncludeParams(URL.GET);
45          url.setIncludeContext(false);
46          url.setValue("myAction.action");
47          url.setNamespace("");
48  
49          url.start(writer);
50          url.end(writer, body);
51  
52          assertEquals("myAction.action?param=1&param=2&param=3",
53              writer.toString());
54      }
55  
56      public void testIncludeAllDuplicateRequestParams() throws Exception {
57          String body = "";
58  
59          Map parameterMap = new HashMap();
60          parameterMap.put("param", new String[] { "1", "2", "3" });
61  
62          request.setQueryString("param=1&param=2&param=3");
63          request.setScheme("http");
64          request.setParameterMap(parameterMap);
65          URL url = new URL(stack, request, response);
66          url.setIncludeParams(URL.ALL);
67          url.setIncludeContext(false);
68          url.setValue("myAction.action");
69          url.setNamespace("");
70  
71          url.start(writer);
72          url.end(writer, body);
73  
74          assertEquals("myAction.action?param=1&param=2&param=3",
75              writer.toString());
76      }
77  }