1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.view.facelets.pss.acid;
20
21 import javax.faces.application.StateManager;
22 import javax.faces.component.UICommand;
23 import javax.faces.component.UIComponent;
24 import javax.faces.component.UIInput;
25 import javax.faces.component.UIPanel;
26 import javax.faces.component.html.HtmlDataTable;
27
28 import junit.framework.Assert;
29
30 import org.apache.myfaces.mc.test.core.AbstractMyFacesRequestTestCase;
31 import org.apache.myfaces.shared.config.MyfacesConfig;
32 import org.apache.myfaces.view.facelets.pss.acid.managed.ResourceDependencyBean;
33 import org.junit.Test;
34
35 public class AcidMyFacesRequestTestCase extends AbstractMyFacesRequestTestCase
36 {
37
38 @Override
39 protected boolean isScanAnnotations()
40 {
41 return true;
42 }
43
44 @Override
45 protected void setUpWebConfigParams() throws Exception
46 {
47 super.setUpWebConfigParams();
48 servletContext.addInitParameter("org.apache.myfaces.annotation.SCAN_PACKAGES","org.apache.myfaces.view.facelets.pss.acid");
49 servletContext.addInitParameter("javax.faces.FACELETS_LIBRARIES", "/WEB-INF/testcomponent.taglib.xml");
50 servletContext.addInitParameter(StateManager.STATE_SAVING_METHOD_PARAM_NAME, StateManager.STATE_SAVING_METHOD_CLIENT);
51 servletContext.addInitParameter("javax.faces.PARTIAL_STATE_SAVING", "true");
52 servletContext.addInitParameter(MyfacesConfig.INIT_PARAM_REFRESH_TRANSIENT_BUILD_ON_PSS, "auto");
53 }
54
55 @Test
56 public void testIndex() throws Exception
57 {
58 setupRequest("/index.xhtml");
59 processLifecycleExecuteAndRender();
60
61 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:component");
62 Assert.assertEquals(1, comp.getChildCount());
63 Assert.assertEquals("Dynamically added child", comp.getChildren().get(0).getAttributes().get("value"));
64
65
66
67
68
69
70
71
72
73
74
75
76 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
77 submit(button);
78 processLifecycleExecuteAndRender();
79
80 comp = facesContext.getViewRoot().findComponent("mainForm:component");
81 Assert.assertEquals(1, comp.getChildCount());
82 Assert.assertEquals("Dynamically added child", comp.getChildren().get(0).getAttributes().get("value"));
83
84
85
86
87
88
89
90
91
92
93
94 tearDownRequest();
95 }
96
97 @Test
98 public void testInput() throws Exception
99 {
100 setupRequest("/input.xhtml");
101 processLifecycleExecuteAndRender();
102 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:component");
103
104 Assert.assertEquals(1, comp.getChildCount());
105 Assert.assertEquals(1, comp.getChildren().get(0).getChildCount());
106 Assert.assertEquals("mainForm:input", comp.getChildren().get(0).getChildren().get(0).getClientId(facesContext));
107
108
109
110
111
112
113
114
115
116
117
118
119
120 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
121 submit(button);
122 processLifecycleExecuteAndRender();
123
124 comp = facesContext.getViewRoot().findComponent("mainForm:component");
125 Assert.assertEquals(1, comp.getChildCount());
126 Assert.assertEquals(1, comp.getChildren().get(0).getChildCount());
127 Assert.assertEquals("mainForm:input", comp.getChildren().get(0).getChildren().get(0).getClientId(facesContext));
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142 }
143
144 @Test
145 public void testRecursive() throws Exception
146 {
147 setupRequest("/recursive.xhtml");
148 processLifecycleExecuteAndRender();
149 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:component");
150 Assert.assertEquals(2, comp.getChildCount());
151 Assert.assertEquals("Dynamically added child", comp.getChildren().get(0).getAttributes().get("value"));
152 Assert.assertEquals(1, comp.getChildren().get(1).getChildCount());
153 Assert.assertEquals("Dynamically added child", comp.getChildren().get(1).getChildren().get(0).getAttributes().get("value"));
154
155 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
156 submit(button);
157 processLifecycleExecuteAndRender();
158
159 comp = facesContext.getViewRoot().findComponent("mainForm:component");
160 Assert.assertEquals(2, comp.getChildCount());
161 Assert.assertEquals("Dynamically added child", comp.getChildren().get(0).getAttributes().get("value"));
162 Assert.assertEquals(1, comp.getChildren().get(1).getChildCount());
163 Assert.assertEquals("Dynamically added child", comp.getChildren().get(1).getChildren().get(0).getAttributes().get("value"));
164
165 tearDownRequest();
166 }
167
168 @Test
169 public void testStable() throws Exception
170 {
171 setupRequest("/stable.xhtml");
172 processLifecycleExecuteAndRender();
173 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:component");
174 Assert.assertEquals(3, comp.getChildCount());
175 Assert.assertEquals("1", comp.getChildren().get(0).getAttributes().get("value"));
176 Assert.assertEquals("2", comp.getChildren().get(1).getAttributes().get("value"));
177 Assert.assertEquals("text3", comp.getChildren().get(2).getId());
178
179 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
180 submit(button);
181 processLifecycleExecuteAndRender();
182
183 comp = facesContext.getViewRoot().findComponent("mainForm:component");
184 Assert.assertEquals(3, comp.getChildCount());
185 Assert.assertEquals("1", comp.getChildren().get(0).getAttributes().get("value"));
186 Assert.assertEquals("2", comp.getChildren().get(1).getAttributes().get("value"));
187 Assert.assertEquals("text3", comp.getChildren().get(2).getId());
188
189 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
190 submit(button);
191 processLifecycleExecuteAndRender();
192
193 comp = facesContext.getViewRoot().findComponent("mainForm:component");
194 Assert.assertEquals(3, comp.getChildCount());
195 Assert.assertEquals("1", comp.getChildren().get(0).getAttributes().get("value"));
196 Assert.assertEquals("2", comp.getChildren().get(1).getAttributes().get("value"));
197 Assert.assertEquals("text3", comp.getChildren().get(2).getId());
198
199 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
200 UIInput input = (UIInput) facesContext.getViewRoot().findComponent("mainForm:text3");
201 inputText(input, "3");
202 submit(button);
203 processLifecycleExecuteAndRender();
204
205 comp = facesContext.getViewRoot().findComponent("mainForm:component");
206 Assert.assertEquals(3, comp.getChildCount());
207 Assert.assertEquals("1", comp.getChildren().get(0).getAttributes().get("value"));
208 Assert.assertEquals("2", comp.getChildren().get(1).getAttributes().get("value"));
209 Assert.assertEquals("text3", comp.getChildren().get(2).getId());
210
211 }
212
213 @Test
214 public void testTable() throws Exception
215 {
216 setupRequest("/table.xhtml");
217 processLifecycleExecuteAndRender();
218
219 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:component");
220 Assert.assertEquals(1, comp.getChildCount());
221 HtmlDataTable dataTable = (HtmlDataTable) comp.getChildren().get(0);
222 Assert.assertEquals(1, dataTable.getChildCount());
223
224 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
225 submit(button);
226 processLifecycleExecuteAndRender();
227
228 comp = facesContext.getViewRoot().findComponent("mainForm:component");
229 Assert.assertEquals(1, comp.getChildCount());
230 dataTable = (HtmlDataTable) comp.getChildren().get(0);
231 Assert.assertEquals(1, dataTable.getChildCount());
232 }
233
234 @Test
235 public void testToggle() throws Exception
236 {
237 setupRequest("/toggle.xhtml");
238 processLifecycleExecuteAndRender();
239
240 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:component");
241 Assert.assertEquals(2, comp.getChildCount());
242 Assert.assertEquals("Manually added child 2<br/>", comp.getChildren().get(0).getAttributes().get("value"));
243 Assert.assertEquals("Manually added child 1<br/>", comp.getChildren().get(1).getAttributes().get("value"));
244
245 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
246 submit(button);
247 processLifecycleExecuteAndRender();
248
249 comp = facesContext.getViewRoot().findComponent("mainForm:component");
250 Assert.assertEquals(2, comp.getChildCount());
251 Assert.assertEquals("Manually added child 1<br/>", comp.getChildren().get(0).getAttributes().get("value"));
252 Assert.assertEquals("Manually added child 2<br/>", comp.getChildren().get(1).getAttributes().get("value"));
253
254 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
255 submit(button);
256 processLifecycleExecuteAndRender();
257
258 comp = facesContext.getViewRoot().findComponent("mainForm:component");
259 Assert.assertEquals(2, comp.getChildCount());
260 Assert.assertEquals("Manually added child 2<br/>", comp.getChildren().get(0).getAttributes().get("value"));
261 Assert.assertEquals("Manually added child 1<br/>", comp.getChildren().get(1).getAttributes().get("value"));
262
263 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
264 submit(button);
265 processLifecycleExecuteAndRender();
266
267 comp = facesContext.getViewRoot().findComponent("mainForm:component");
268 Assert.assertEquals(2, comp.getChildCount());
269 Assert.assertEquals("Manually added child 1<br/>", comp.getChildren().get(0).getAttributes().get("value"));
270 Assert.assertEquals("Manually added child 2<br/>", comp.getChildren().get(1).getAttributes().get("value"));
271
272 }
273
274 @Test
275 public void testInclude() throws Exception
276 {
277 setupRequest("/include.xhtml");
278 processLifecycleExecute();
279
280 facesContext.getApplication().getViewHandler().getViewDeclarationLanguage(
281 facesContext, facesContext.getViewRoot().getViewId()).buildView(facesContext, facesContext.getViewRoot());
282
283 UIComponent component = facesContext.getViewRoot().findComponent("mainForm:component1");
284 component.getAttributes().put("test", "test1");
285 processRender();
286
287 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:page1");
288 submit(button);
289 processLifecycleExecute();
290
291 component = facesContext.getViewRoot().findComponent("mainForm:component1");
292 Assert.assertEquals("test1", component.getAttributes().get("test"));
293 processRender();
294
295 component = facesContext.getViewRoot().findComponent("mainForm:component1");
296 Assert.assertEquals("test1", component.getAttributes().get("test"));
297
298
299 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:page2");
300 submit(button);
301
302 processLifecycleExecute();
303 component = facesContext.getViewRoot().findComponent("mainForm:component1");
304
305 Assert.assertEquals("test1", component.getAttributes().get("test"));
306
307
308 facesContext.getApplication().getViewHandler().getViewDeclarationLanguage(
309 facesContext, facesContext.getViewRoot().getViewId()).buildView(facesContext, facesContext.getViewRoot());
310
311
312 component = facesContext.getViewRoot().findComponent("mainForm:component2");
313 Assert.assertNull(component.getAttributes().get("test"));
314
315 component.getAttributes().put("test", "test2");
316 processRender();
317
318 component = facesContext.getViewRoot().findComponent("mainForm:component2");
319 Assert.assertEquals("test2", component.getAttributes().get("test"));
320
321 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:page2");
322 submit(button);
323
324 processLifecycleExecute();
325 component = facesContext.getViewRoot().findComponent("mainForm:component2");
326
327 Assert.assertNotNull("mainForm:component2 was not restored correctly",component);
328 Assert.assertEquals("test2", component.getAttributes().get("test"));
329
330
331 facesContext.getApplication().getViewHandler().getViewDeclarationLanguage(
332 facesContext, facesContext.getViewRoot().getViewId()).buildView(facesContext, facesContext.getViewRoot());
333
334
335 component = facesContext.getViewRoot().findComponent("mainForm:component2");
336 Assert.assertEquals("test2", component.getAttributes().get("test"));
337
338 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:page2");
339 submit(button);
340
341 processLifecycleExecute();
342 component = facesContext.getViewRoot().findComponent("mainForm:component2");
343
344 Assert.assertEquals("test2", component.getAttributes().get("test"));
345 }
346
347
348
349
350
351
352
353 @Test
354 public void testInclude2() throws Exception
355 {
356 setupRequest("/include.xhtml");
357 processLifecycleExecute();
358
359 facesContext.getApplication().getViewHandler().getViewDeclarationLanguage(
360 facesContext, facesContext.getViewRoot().getViewId()).buildView(facesContext, facesContext.getViewRoot());
361
362 UIComponent component = facesContext.getViewRoot().findComponent("mainForm:component1");
363 Assert.assertNotNull(component);
364 processRender();
365
366 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:page1");
367 submit(button);
368
369 processLifecycleExecute();
370
371 component = facesContext.getViewRoot().findComponent("mainForm:component1");
372 Assert.assertNotNull(component);
373 processRender();
374
375 component = facesContext.getViewRoot().findComponent("mainForm:component1");
376 Assert.assertNotNull(component);
377
378
379 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:page2");
380 submit(button);
381
382 processLifecycleExecute();
383 component = facesContext.getViewRoot().findComponent("mainForm:component1");
384
385 Assert.assertNotNull(component);
386
387
388 facesContext.getApplication().getViewHandler().getViewDeclarationLanguage(
389 facesContext, facesContext.getViewRoot().getViewId()).buildView(facesContext, facesContext.getViewRoot());
390
391
392 component = facesContext.getViewRoot().findComponent("mainForm:component2");
393 Assert.assertNotNull(component);
394 processRender();
395
396 component = facesContext.getViewRoot().findComponent("mainForm:component2");
397 Assert.assertNotNull(component);
398
399 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:page2");
400 submit(button);
401
402 processLifecycleExecute();
403 component = facesContext.getViewRoot().findComponent("mainForm:component2");
404
405 Assert.assertNotNull(component);
406
407
408 facesContext.getApplication().getViewHandler().getViewDeclarationLanguage(
409 facesContext, facesContext.getViewRoot().getViewId()).buildView(facesContext, facesContext.getViewRoot());
410
411
412 component = facesContext.getViewRoot().findComponent("mainForm:component2");
413 Assert.assertNotNull(component);
414
415 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:page2");
416 submit(button);
417
418 processLifecycleExecute();
419 component = facesContext.getViewRoot().findComponent("mainForm:component2");
420
421 Assert.assertNotNull(component);
422 }
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441 @Test
442 public void testComponentBinding() throws Exception
443 {
444 setupRequest("/componentBinding1.xhtml");
445 processLifecycleExecuteAndRender();
446
447 UIComponent comp = facesContext.getViewRoot().findComponent("panel");
448 Assert.assertNotNull(comp);
449 Assert.assertEquals(1, comp.getChildCount());
450
451 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
452 submit(button);
453 processLifecycleExecuteAndRender();
454
455 comp = facesContext.getViewRoot().findComponent("panel");
456
457 Assert.assertEquals("value1", comp.getAttributes().get("attr1"));
458 Assert.assertEquals("value2", comp.getChildren().get(0).getAttributes().get("attr2"));
459
460 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
461 submit(button);
462 processLifecycleExecuteAndRender();
463
464 comp = facesContext.getViewRoot().findComponent("panel");
465
466 Assert.assertEquals("value1", comp.getAttributes().get("attr1"));
467 Assert.assertEquals("value2", comp.getChildren().get(0).getAttributes().get("attr2"));
468
469 tearDownRequest();
470 }
471
472 @Test
473 public void testResourceDependency() throws Exception
474 {
475 setupRequest("/resourceDependency1.xhtml");
476 processLifecycleExecute();
477
478 executeBeforeRender(facesContext);
479 executeBuildViewCycle(facesContext);
480
481 UIPanel headPanel = (UIPanel) facesContext.getViewRoot().getFacet("head");
482 Assert.assertNotNull(headPanel);
483 Assert.assertEquals(1, headPanel.getChildCount());
484
485 String nextUniqueId = facesContext.getViewRoot().createUniqueId(facesContext, null);
486
487 executeViewHandlerRender(facesContext);
488 executeAfterRender(facesContext);
489
490 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
491 submit(button);
492
493 processLifecycleExecute();
494
495 ResourceDependencyBean bean = facesContext.getApplication().evaluateExpressionGet(
496 facesContext, "#{resourceDependencyBean}", ResourceDependencyBean.class);
497 bean.setIncludeContent(true);
498
499 executeBeforeRender(facesContext);
500 executeBuildViewCycle(facesContext);
501
502 headPanel = (UIPanel) facesContext.getViewRoot().getFacet("head");
503 Assert.assertNotNull(headPanel);
504 Assert.assertEquals(1, headPanel.getChildCount());
505 Assert.assertNotSame(nextUniqueId, headPanel.getChildren().get(0).getId());
506
507 executeViewHandlerRender(facesContext);
508 executeAfterRender(facesContext);
509 }
510
511 @Test
512 public void testResourceDependency2() throws Exception
513 {
514 setupRequest("/resourceDependency2.xhtml");
515 processLifecycleExecute();
516
517 executeBeforeRender(facesContext);
518 executeBuildViewCycle(facesContext);
519
520 UIPanel headPanel = (UIPanel) facesContext.getViewRoot().getFacet("head");
521 Assert.assertNull(headPanel);
522
523 String nextUniqueId = facesContext.getViewRoot().createUniqueId(facesContext, null);
524
525 executeViewHandlerRender(facesContext);
526 executeAfterRender(facesContext);
527
528 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
529 submit(button);
530
531 processLifecycleExecute();
532
533 ResourceDependencyBean bean = facesContext.getApplication().evaluateExpressionGet(
534 facesContext, "#{resourceDependencyBean}", ResourceDependencyBean.class);
535 bean.setIncludeContent(true);
536
537 executeBeforeRender(facesContext);
538 executeBuildViewCycle(facesContext);
539
540 headPanel = (UIPanel) facesContext.getViewRoot().getFacet("head");
541 Assert.assertNotNull(headPanel);
542 Assert.assertTrue(1 >= headPanel.getChildCount());
543 Assert.assertNotSame(nextUniqueId, headPanel.getChildren().get(0).getId());
544
545 executeViewHandlerRender(facesContext);
546 executeAfterRender(facesContext);
547
548 UICommand button2 = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
549 submit(button2);
550
551 processLifecycleExecute();
552
553 bean = facesContext.getApplication().evaluateExpressionGet(
554 facesContext, "#{resourceDependencyBean}", ResourceDependencyBean.class);
555 bean.setIncludeContent(false);
556
557 executeBeforeRender(facesContext);
558 executeBuildViewCycle(facesContext);
559
560 headPanel = (UIPanel) facesContext.getViewRoot().getFacet("head");
561 Assert.assertNotNull(headPanel);
562 Assert.assertTrue(1 >= headPanel.getChildCount());
563
564
565 executeViewHandlerRender(facesContext);
566 executeAfterRender(facesContext);
567
568 UICommand button3 = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
569 submit(button3);
570
571 processLifecycleExecute();
572
573 bean = facesContext.getApplication().evaluateExpressionGet(
574 facesContext, "#{resourceDependencyBean}", ResourceDependencyBean.class);
575 bean.setIncludeContent(true);
576
577 executeBeforeRender(facesContext);
578 executeBuildViewCycle(facesContext);
579
580 headPanel = (UIPanel) facesContext.getViewRoot().getFacet("head");
581 Assert.assertNotNull(headPanel);
582 Assert.assertTrue(1 >= headPanel.getChildCount());
583
584
585 executeViewHandlerRender(facesContext);
586 executeAfterRender(facesContext);
587
588 UICommand button4 = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
589 submit(button4);
590
591 processLifecycleExecute();
592
593 bean = facesContext.getApplication().evaluateExpressionGet(
594 facesContext, "#{resourceDependencyBean}", ResourceDependencyBean.class);
595 bean.setIncludeContent(false);
596
597 executeBeforeRender(facesContext);
598 executeBuildViewCycle(facesContext);
599
600 headPanel = (UIPanel) facesContext.getViewRoot().getFacet("head");
601 Assert.assertNotNull(headPanel);
602 Assert.assertTrue(1 >= headPanel.getChildCount());
603
604
605 executeViewHandlerRender(facesContext);
606 executeAfterRender(facesContext);
607 }
608
609 }