1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.myfaces.config.impl.digister;
17
18 import java.util.List;
19
20 import junit.framework.TestCase;
21
22 import org.apache.myfaces.config.impl.digester.DigesterFacesConfigUnmarshallerImpl;
23 import org.apache.myfaces.config.element.Application;
24 import org.apache.myfaces.config.element.ContractMapping;
25 import org.apache.myfaces.config.element.FacesConfig;
26 import org.apache.myfaces.config.element.FacesConfigNameSlot;
27 import org.apache.myfaces.config.element.FacesFlowCall;
28 import org.apache.myfaces.config.element.FacesFlowDefinition;
29 import org.apache.myfaces.config.element.FacesFlowMethodCall;
30 import org.apache.myfaces.config.element.FacesFlowParameter;
31 import org.apache.myfaces.config.element.FacesFlowReturn;
32 import org.apache.myfaces.config.element.FacesFlowSwitch;
33 import org.apache.myfaces.config.element.FacesFlowView;
34 import org.apache.myfaces.config.element.LocaleConfig;
35 import org.apache.myfaces.config.element.NavigationCase;
36 import org.apache.myfaces.config.element.NavigationRule;
37 import org.apache.myfaces.config.element.OrderSlot;
38
39
40
41
42
43 public class DigesterFacesConfigUnmarshallerImplTest extends TestCase
44 {
45 private DigesterFacesConfigUnmarshallerImpl _impl;
46
47 protected void setUp() throws Exception
48 {
49 _impl = new DigesterFacesConfigUnmarshallerImpl(null);
50 }
51
52 public void testEmptyConfig() throws Exception
53 {
54 FacesConfig cfg = _impl.getFacesConfig(getClass().getResourceAsStream(
55 "empty-config.xml"), "empty-config.xml");
56 assertNotNull(cfg);
57 assertTrue(cfg.getApplications().isEmpty());
58 assertTrue(cfg.getComponents().isEmpty());
59 assertTrue(cfg.getConverters().isEmpty());
60 assertTrue(cfg.getFactories().isEmpty());
61 assertTrue(cfg.getLifecyclePhaseListener().isEmpty());
62 assertTrue(cfg.getManagedBeans().isEmpty());
63 assertTrue(cfg.getNavigationRules().isEmpty());
64 assertTrue(cfg.getRenderKits().isEmpty());
65 assertTrue(cfg.getValidators().isEmpty());
66 }
67
68 public void testApplicationConfig() throws Exception
69 {
70 FacesConfig cfg = _impl.getFacesConfig(getClass().getResourceAsStream(
71 "application-config.xml"), "application-config.xml");
72 assertNotNull(cfg);
73 assertEquals(1, cfg.getApplications().size());
74 Application app = cfg.getApplications().get(0);
75 assertEquals(2, app.getActionListener().size());
76 assertEquals("action-listener1", app.getActionListener().get(0));
77 assertEquals("action-listener2", app.getActionListener().get(1));
78 assertEquals(1, app.getDefaultRenderkitId().size());
79 assertEquals("default-render-kit-id", app.getDefaultRenderkitId()
80 .get(0));
81 assertLocaleConfig(app.getLocaleConfig());
82 assertEquals(1, app.getMessageBundle().size());
83 assertEquals("message-bundle", app.getMessageBundle().get(0));
84 assertEquals(1, app.getNavigationHandler().size());
85 assertEquals("navigation-handler", app.getNavigationHandler().get(0));
86 assertEquals(1, app.getPropertyResolver().size());
87 assertEquals("property-resolver", app.getPropertyResolver().get(0));
88
89 assertEquals(1, app.getStateManager().size());
90 assertEquals("state-manager", app.getStateManager().get(0));
91
92 assertEquals(1, app.getVariableResolver().size());
93 assertEquals("variable-resolver", app.getVariableResolver().get(0));
94
95 assertEquals(1, app.getViewHandler().size());
96 assertEquals("view-handler", app.getViewHandler().get(0));
97
98 assertEquals(1, app.getElResolver().size());
99 assertEquals("el-resolver", app.getElResolver().get(0));
100
101 assertEquals(1, app.getResourceBundle().size());
102 assertEquals("base-name", app.getResourceBundle().get(0).getBaseName());
103 assertEquals("var", app.getResourceBundle().get(0).getVar());
104 }
105
106
107
108
109 private void assertLocaleConfig(List<LocaleConfig> localeConfig)
110 {
111 assertEquals(1, localeConfig.size());
112 LocaleConfig cfg = localeConfig.get(0);
113 assertEquals("aa", cfg.getDefaultLocale());
114 assertEquals(2, cfg.getSupportedLocales().size());
115 assertEquals("aa", cfg.getSupportedLocales().get(0));
116 assertEquals("bb", cfg.getSupportedLocales().get(1));
117 }
118
119 public void testAbsoluteOrderingConfig() throws Exception
120 {
121 FacesConfig cfg = _impl.getFacesConfig(getClass().getResourceAsStream(
122 "absolute-ordering-config.xml"), "absolute-ordering-config.xml");
123 assertNotNull(cfg);
124 assertEquals("true", cfg.getMetadataComplete());
125 assertEquals("a",cfg.getName());
126
127 List<OrderSlot> orderList = cfg.getAbsoluteOrdering().getOrderList();
128
129 assertEquals("b", ((FacesConfigNameSlot) orderList.get(0)).getName());
130 assertEquals("c", ((FacesConfigNameSlot) orderList.get(1)).getName());
131 assertEquals(org.apache.myfaces.config.impl.digester.elements.ConfigOthersSlotImpl.class, orderList.get(2).getClass());
132 assertEquals("d", ((FacesConfigNameSlot) orderList.get(3)).getName());
133
134 assertTrue(cfg.getApplications().isEmpty());
135 assertTrue(cfg.getComponents().isEmpty());
136 assertTrue(cfg.getConverters().isEmpty());
137 assertTrue(cfg.getFactories().isEmpty());
138 assertTrue(cfg.getLifecyclePhaseListener().isEmpty());
139 assertTrue(cfg.getManagedBeans().isEmpty());
140 assertTrue(cfg.getNavigationRules().isEmpty());
141 assertTrue(cfg.getRenderKits().isEmpty());
142 assertTrue(cfg.getValidators().isEmpty());
143 }
144
145 public void testOrderingConfig() throws Exception
146 {
147 FacesConfig cfg = _impl.getFacesConfig(getClass().getResourceAsStream(
148 "ordering-config.xml"), "ordering-config.xml");
149 assertNotNull(cfg);
150 assertEquals("a",cfg.getName());
151
152 List<OrderSlot> orderList = cfg.getOrdering().getBeforeList();
153 assertEquals("b", ((FacesConfigNameSlot) orderList.get(0)).getName());
154 assertEquals("c", ((FacesConfigNameSlot) orderList.get(1)).getName());
155 assertEquals(org.apache.myfaces.config.impl.digester.elements.ConfigOthersSlotImpl.class, orderList.get(2).getClass());
156
157 orderList = cfg.getOrdering().getAfterList();
158 assertEquals("d", ((FacesConfigNameSlot) orderList.get(0)).getName());
159
160 assertTrue(cfg.getApplications().isEmpty());
161 assertTrue(cfg.getComponents().isEmpty());
162 assertTrue(cfg.getConverters().isEmpty());
163 assertTrue(cfg.getFactories().isEmpty());
164 assertTrue(cfg.getLifecyclePhaseListener().isEmpty());
165 assertTrue(cfg.getManagedBeans().isEmpty());
166 assertTrue(cfg.getNavigationRules().isEmpty());
167 assertTrue(cfg.getRenderKits().isEmpty());
168 assertTrue(cfg.getValidators().isEmpty());
169 }
170
171 public void testFacesFlowConfig() throws Exception
172 {
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238 }
239
240 public void testCsrf() throws Exception
241 {
242 FacesConfig cfg = _impl.getFacesConfig(getClass().getResourceAsStream(
243 "csrf-and-contracts.xml"), "csrf-and-contracts.xml");
244
245 assertNotNull(cfg);
246 assertEquals(2, cfg.getProtectedViewsUrlPatternList().size());
247 assertEquals("/files/*.xhtml", cfg.getProtectedViewsUrlPatternList().get(0));
248 assertEquals("/files2/*.xhtml", cfg.getProtectedViewsUrlPatternList().get(1));
249
250
251 }
252
253 public void testContracts() throws Exception
254 {
255 FacesConfig cfg = _impl.getFacesConfig(getClass().getResourceAsStream(
256 "csrf-and-contracts.xml"), "csrf-and-contracts.xml");
257
258 assertNotNull(cfg);
259
260 Application app = cfg.getApplications().get(0);
261 assertNotNull(app);
262 assertEquals(1, app.getResourceLibraryContractMappings().size());
263
264 ContractMapping mapping = app.getResourceLibraryContractMappings().get(0);
265 assertEquals("/files/*.xhtml", mapping.getUrlPatternList().get(0));
266 assertEquals("contractA contractB", mapping.getContractList().get(0));
267 }
268
269 public void testContracts2() throws Exception
270 {
271 FacesConfig cfg = _impl.getFacesConfig(getClass().getResourceAsStream(
272 "contracts2.xml"), "contracts2.xml");
273
274 assertNotNull(cfg);
275
276 Application app = cfg.getApplications().get(0);
277 assertNotNull(app);
278 assertEquals(1, app.getResourceLibraryContractMappings().size());
279
280 ContractMapping mapping = app.getResourceLibraryContractMappings().get(0);
281 assertTrue(mapping.getUrlPatternList().contains("/files/*.xhtml"));
282 assertTrue(mapping.getUrlPatternList().contains("/files2/*.xhtml"));
283 assertTrue(mapping.getContractList().contains("contractA"));
284 assertTrue(mapping.getContractList().contains("contractB"));
285 }
286 }