2009/05/20 - Apache Shale has been retired.
For more information, please explore the Attic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shale.remoting.impl;
19
20 import java.util.Locale;
21 import javax.faces.component.UIViewRoot;
22 import junit.framework.Test;
23 import junit.framework.TestSuite;
24 import org.apache.shale.remoting.Constants;
25 import org.apache.shale.test.base.AbstractJsfTestCase;
26
27 /***
28 * <p>Test case for <code>org.apache.shale.remoting.impl.MappingImpl</code>.</p>
29 */
30 public class MappingImplTestCase extends AbstractJsfTestCase {
31
32
33
34
35
36
37 public MappingImplTestCase(String name) {
38 super(name);
39 }
40
41
42
43
44
45
46 protected void setUp() throws Exception {
47
48 super.setUp();
49 facesContext.setViewRoot(new UIViewRoot());
50 mappings = new MappingsImpl();
51 mappings.setExtension(".jsp");
52 mappings.setPatterns(new String[] { "*.faces" });
53 mapping = new MappingImpl();
54 mapping.setMappings(mappings);
55 mappings.addMapping(mapping);
56 facesContext.getExternalContext().getApplicationMap().
57 put(Constants.MAPPINGS_ATTR, mappings);
58 facesContext.getViewRoot().setLocale(Locale.getDefault());
59 request.setPathElements("/webapp", "/foo", null, null);
60
61 }
62
63
64
65 public static Test suite() {
66
67 return (new TestSuite(MappingImplTestCase.class));
68
69 }
70
71
72
73 protected void tearDown() throws Exception {
74
75 mapping = null;
76 mappings = null;
77 super.tearDown();
78
79 }
80
81
82
83
84
85
86 private MappingImpl mapping = null;
87
88
89
90 private MappingsImpl mappings = null;
91
92
93
94
95
96
97 public void testExtension() {
98
99 mapping.setPattern("*.foo");
100 facesContext.getViewRoot().setViewId("foo");
101 assertNull(mapping.mapViewId(facesContext));
102 facesContext.getViewRoot().setViewId(".foo");
103 assertNull(mapping.mapViewId(facesContext));
104 facesContext.getViewRoot().setViewId("/foo");
105 assertNull(mapping.mapViewId(facesContext));
106 facesContext.getViewRoot().setViewId("/foo.bar");
107 assertNull(mapping.mapViewId(facesContext));
108 facesContext.getViewRoot().setViewId("/bar.foo");
109 assertEquals("/bar", mapping.mapViewId(facesContext));
110 facesContext.getViewRoot().setViewId("/bar/baz.foo");
111 assertEquals("/bar/baz", mapping.mapViewId(facesContext));
112 facesContext.getViewRoot().setViewId("/foo/bar.foo" + mappings.getExtension());
113 assertEquals("/foo/bar", mapping.mapViewId(facesContext));
114
115 }
116
117
118
119
120 public void testExtensionExtra() {
121
122 mapping.setPattern("*.bop");
123 facesContext.getViewRoot().setViewId("/foo/bar.bop" + mappings.getPatterns()[0].substring(1));
124 assertEquals("/foo/bar", mapping.mapViewId(facesContext));
125
126 }
127
128
129
130 public void testInvalid() {
131
132 try {
133 mapping.setPattern("");
134 fail("Should have thrown IllegalArgumentException");
135 } catch (IllegalArgumentException e) {
136 ;
137 }
138
139 try {
140 mapping.setPattern("foo");
141 fail("Should have thrown IllegalArgumentException");
142 } catch (IllegalArgumentException e) {
143 ;
144 }
145
146 try {
147 mapping.setPattern("/foo");
148 fail("Should have thrown IllegalArgumentException");
149 } catch (IllegalArgumentException e) {
150 ;
151 }
152
153 try {
154 mapping.setPattern("/foo/");
155 fail("Should have thrown IllegalArgumentException");
156 } catch (IllegalArgumentException e) {
157 ;
158 }
159
160 try {
161 mapping.setPattern(".foo");
162 fail("Should have thrown IllegalArgumentException");
163 } catch (IllegalArgumentException e) {
164 ;
165 }
166
167 try {
168 mapping.setPattern("*.foo.");
169 fail("Should have thrown IllegalArgumentException");
170 } catch (IllegalArgumentException e) {
171 ;
172 }
173
174 try {
175 mapping.setPattern("*.foo.bar");
176 fail("Should have thrown IllegalArgumentException");
177 } catch (IllegalArgumentException e) {
178 ;
179 }
180
181 }
182
183
184
185 public void testPrefix() {
186
187 mapping.setPattern("/foo/*");
188 facesContext.getViewRoot().setViewId("foo");
189 assertNull(mapping.mapViewId(facesContext));
190 facesContext.getViewRoot().setViewId("/bar");
191 assertNull(mapping.mapViewId(facesContext));
192 facesContext.getViewRoot().setViewId("/bar/foo");
193 assertNull(mapping.mapViewId(facesContext));
194 facesContext.getViewRoot().setViewId("/foo");
195 assertNull(mapping.mapViewId(facesContext));
196 facesContext.getViewRoot().setViewId("/foo/bar");
197 assertEquals("/bar", mapping.mapViewId(facesContext));
198 facesContext.getViewRoot().setViewId("/foo/bar.baz");
199 assertEquals("/bar.baz", mapping.mapViewId(facesContext));
200 facesContext.getViewRoot().setViewId("/foo/bar/baz");
201 assertEquals("/bar/baz", mapping.mapViewId(facesContext));
202 facesContext.getViewRoot().setViewId("/foo/bar/baz.bop");
203 assertEquals("/bar/baz.bop", mapping.mapViewId(facesContext));
204
205 }
206
207
208
209 public void testPristine() {
210
211 assertNull(mapping.getMechanism());
212 assertNull(mapping.getPattern());
213 assertNull(mapping.getProcessor());
214
215 }
216
217
218
219 public void testResourceIdentifiers() throws Exception {
220
221 String resourceId = "/foo/bar.baz";
222
223
224 mappings.setPatterns(new String[] { "/faces/*" });
225 mapping.setPattern("/bop/*");
226 assertEquals("/webapp/faces/bop/foo/bar.baz",
227 mapping.mapResourceId(facesContext, resourceId));
228
229
230 mappings.setPatterns(new String[] { "/faces/*" });
231 mapping.setPattern("*.bop");
232 assertEquals("/webapp/faces/foo/bar.baz.bop",
233 mapping.mapResourceId(facesContext, resourceId));
234
235
236 mappings.setPatterns(new String[] { "*.faces" });
237 mapping.setPattern("/bop/*");
238 assertEquals("/webapp/bop/foo/bar.baz.faces",
239 mapping.mapResourceId(facesContext, resourceId));
240
241
242 mappings.setPatterns(new String[] { "*.faces" });
243 mapping.setPattern("*.bop");
244 assertEquals("/webapp/foo/bar.baz.bop.faces",
245 mapping.mapResourceId(facesContext, resourceId));
246
247 }
248
249
250
251
252
253
254 }