1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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¶m=2¶m=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¶m=2¶m=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 }