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.faces;
19
20 import javax.faces.application.ViewHandler;
21
22 import junit.framework.Test;
23 import junit.framework.TestSuite;
24
25 import org.apache.shale.remoting.Constants;
26 import org.apache.shale.remoting.Mapping;
27 import org.apache.shale.remoting.Mappings;
28 import org.apache.shale.remoting.Mechanism;
29 import org.apache.shale.remoting.Processor;
30 import org.apache.shale.remoting.impl.ClassResourceProcessor;
31 import org.apache.shale.remoting.impl.FilteringProcessor;
32 import org.apache.shale.remoting.impl.MappingImpl;
33 import org.apache.shale.remoting.impl.MappingsImpl;
34 import org.apache.shale.remoting.impl.MethodBindingProcessor;
35 import org.apache.shale.remoting.impl.WebResourceProcessor;
36 import org.apache.shale.test.base.AbstractJsfTestCase;
37
38 /***
39 * <p>Test case for <code>org.apache.shale.remoting.MappingsHelper</code>.
40 * These tests focus on correct configuration, not on executable
41 * functionality.</p>
42 */
43 public class MappingsHelperTestCase extends AbstractJsfTestCase {
44
45
46
47
48
49
50 public MappingsHelperTestCase(String name) {
51 super(name);
52 }
53
54
55
56
57
58
59 protected void setUp() throws Exception {
60
61 super.setUp();
62 helper = new MappingsHelper();
63
64
65 }
66
67
68
69 public static Test suite() {
70
71 return (new TestSuite(MappingsHelperTestCase.class));
72
73 }
74
75
76
77 protected void tearDown() throws Exception {
78
79 mappings = null;
80 helper = null;
81 super.tearDown();
82
83 }
84
85
86
87
88
89
90 private MappingsHelper helper = null;
91
92
93
94 private Mapping mapping = null;
95
96
97
98 private Mappings mappings = null;
99
100
101
102 private Processor processor = null;
103
104
105
106
107
108
109 public void testInvalidExclude() {
110
111 servletContext.addInitParameter(Constants.CLASS_RESOURCES_EXCLUDES,
112 "*.class,/foo");
113 try {
114 mappings = helper.getMappings(facesContext);
115 fail("Should have thrown IllegalArgumentException");
116 } catch (IllegalArgumentException e) {
117 ;
118 }
119
120 }
121
122
123
124 public void testInvalidInclude() {
125
126 servletContext.addInitParameter(Constants.DYNAMIC_RESOURCES_INCLUDES,
127 "/bar/*,*.x.y");
128 try {
129 mappings = helper.getMappings(facesContext);
130 fail("Should have thrown IllegalArgumentException");
131 } catch (IllegalArgumentException e) {
132 ;
133 }
134
135 }
136
137
138
139 public void testInvalidMechanism() {
140
141 servletContext.addInitParameter(Constants.WEBAPP_RESOURCES_PARAM,
142 "*/*:org.apache.shale.remoting.impl.MethodBindingProcessor");
143 try {
144 mappings = helper.getMappings(facesContext);
145 fail("Should have thrown IllegalArgumentException");
146 } catch (IllegalArgumentException e) {
147 ;
148 }
149
150 }
151
152
153
154 public void testPristine() {
155
156 assertNotNull(helper);
157
158
159 mappings = helper.getMappings(facesContext);
160 assertNotNull(mappings);
161
162
163 assertTrue(mappings instanceof MappingsImpl);
164 assertEquals(ViewHandler.DEFAULT_SUFFIX, mappings.getExtension());
165 assertEquals(3, mappings.getMappings().size());
166 assertEquals(0, mappings.getPatterns().length);
167
168
169 mapping = mappings.getMapping("/static/*");
170 assertNotNull(mapping);
171 assertTrue(mapping instanceof MappingImpl);
172 assertTrue(mappings == mapping.getMappings());
173 assertEquals(Mechanism.CLASS_RESOURCE, mapping.getMechanism());
174 assertEquals("/static/*", mapping.getPattern());
175 processor = mapping.getProcessor();
176 assertNotNull(processor);
177 assertTrue(processor instanceof ClassResourceProcessor);
178 assertEquals(Constants.CLASS_RESOURCES_EXCLUDES_DEFAULT + ","
179 + Constants.CLASS_RESOURCES_EXCLUDES_DEFAULT,
180 ((FilteringProcessor) processor).getExcludes());
181 assertEquals(Constants.CLASS_RESOURCES_INCLUDES_DEFAULT,
182 ((FilteringProcessor) processor).getIncludes());
183
184
185 mapping = mappings.getMapping("/dynamic/*");
186 assertNotNull(mapping);
187 assertTrue(mapping instanceof MappingImpl);
188 assertTrue(mappings == mapping.getMappings());
189 assertEquals(Mechanism.DYNAMIC_RESOURCE, mapping.getMechanism());
190 assertEquals("/dynamic/*", mapping.getPattern());
191 processor = mapping.getProcessor();
192 assertNotNull(processor);
193 assertTrue(processor instanceof MethodBindingProcessor);
194 assertEquals(Constants.DYNAMIC_RESOURCES_EXCLUDES_DEFAULT + ","
195 + Constants.DYNAMIC_RESOURCES_EXCLUDES_DEFAULT,
196 ((FilteringProcessor) processor).getExcludes());
197 assertEquals(Constants.DYNAMIC_RESOURCES_INCLUDES_DEFAULT,
198 ((FilteringProcessor) processor).getIncludes());
199
200
201 mapping = mappings.getMapping("/webapp/*");
202 assertNotNull(mapping);
203 assertTrue(mapping instanceof MappingImpl);
204 assertTrue(mappings == mapping.getMappings());
205 assertEquals(Mechanism.WEBAPP_RESOURCE, mapping.getMechanism());
206 assertEquals("/webapp/*", mapping.getPattern());
207 processor = mapping.getProcessor();
208 assertNotNull(processor);
209 assertTrue(processor instanceof WebResourceProcessor);
210 assertEquals(Constants.WEBAPP_RESOURCES_EXCLUDES_DEFAULT + ","
211 + Constants.WEBAPP_RESOURCES_EXCLUDES_DEFAULT,
212 ((FilteringProcessor) processor).getExcludes());
213 assertEquals(Constants.WEBAPP_RESOURCES_INCLUDES_DEFAULT,
214 ((FilteringProcessor) processor).getIncludes());
215
216 }
217
218
219
220
221
222
223 }