KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > multipart > TestUploadFormParametersWrapper


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.multipart;
16
17 import java.util.Enumeration JavaDoc;
18 import java.util.HashMap JavaDoc;
19 import java.util.Map JavaDoc;
20
21 import javax.servlet.http.HttpServletRequest JavaDoc;
22
23 import org.apache.hivemind.test.HiveMindTestCase;
24
25 /**
26  * Tests for {@link org.apache.tapestry.multipart.UploadFormParametersWrapper}.
27  *
28  * @author Howard M. Lewis Ship
29  * @since 4.0
30  */

31 public class TestUploadFormParametersWrapper extends HiveMindTestCase
32 {
33     private HttpServletRequest JavaDoc newRequest()
34     {
35         return (HttpServletRequest JavaDoc) newMock(HttpServletRequest JavaDoc.class);
36     }
37
38     public void testMapIsNotModifiable()
39     {
40         HttpServletRequest JavaDoc request = newRequest();
41
42         replayControls();
43
44         Map JavaDoc map = new HashMap JavaDoc();
45
46         map.put("key", new String JavaDoc[]
47         { "value" });
48
49         HttpServletRequest JavaDoc r = new UploadFormParametersWrapper(request, map);
50
51         Map JavaDoc pmap = r.getParameterMap();
52
53         assertNotSame(map, pmap);
54
55         assertSame(map.get("key"), pmap.get("key"));
56
57         try
58         {
59             pmap.put("foo", "bar");
60             unreachable();
61         }
62         catch (UnsupportedOperationException JavaDoc ex)
63         {
64             // Expected.
65
}
66
67         verifyControls();
68     }
69
70     public void testGetSingleParameterWhenNull()
71     {
72         HttpServletRequest JavaDoc request = newRequest();
73
74         replayControls();
75
76         HttpServletRequest JavaDoc r = new UploadFormParametersWrapper(request, new HashMap JavaDoc());
77
78         assertNull(r.getParameter("unknown-key"));
79
80         verifyControls();
81     }
82
83     public void testGetSingleParameterWhenEmptyArray()
84     {
85         HttpServletRequest JavaDoc request = newRequest();
86
87         replayControls();
88
89         HashMap JavaDoc params = new HashMap JavaDoc();
90
91         params.put("empty-key", new String JavaDoc[0]);
92
93         HttpServletRequest JavaDoc r = new UploadFormParametersWrapper(request, params);
94
95         assertNull(r.getParameter("empty-key"));
96
97         verifyControls();
98     }
99
100     public void testGetParameterValues()
101     {
102         String JavaDoc[] values =
103         { "fred", "barney" };
104
105         HttpServletRequest JavaDoc request = newRequest();
106
107         replayControls();
108
109         HashMap JavaDoc params = new HashMap JavaDoc();
110
111         params.put("key", values);
112
113         HttpServletRequest JavaDoc r = new UploadFormParametersWrapper(request, params);
114
115         assertSame(values, r.getParameterValues("key"));
116
117         verifyControls();
118     }
119
120     public void testGetParameterNames()
121     {
122         HttpServletRequest JavaDoc request = newRequest();
123
124         replayControls();
125
126         HashMap JavaDoc params = new HashMap JavaDoc();
127
128         params.put("key", new String JavaDoc[0]);
129
130         HttpServletRequest JavaDoc r = new UploadFormParametersWrapper(request, params);
131
132         Enumeration JavaDoc e = r.getParameterNames();
133
134         assertEquals(true, e.hasMoreElements());
135         assertEquals("key", e.nextElement());
136         assertEquals(false, e.hasMoreElements());
137
138         verifyControls();
139     }
140 }
Popular Tags