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 java.util.Set;
22 import java.util.TreeSet;
23 import javax.el.ExpressionFactory;
24 import javax.faces.application.StateManager;
25 import javax.faces.component.UICommand;
26 import javax.faces.component.UIComponent;
27 import javax.faces.component.UIInput;
28 import javax.faces.component.UIOutput;
29 import javax.faces.component.UIPanel;
30 import javax.faces.component.UIViewParameter;
31 import javax.faces.component.html.HtmlDataTable;
32
33 import org.apache.myfaces.mc.test.core.AbstractMyFacesRequestTestCase;
34 import org.apache.myfaces.shared.config.MyfacesConfig;
35 import org.apache.myfaces.test.mock.MockPrintWriter;
36 import org.apache.myfaces.view.facelets.pss.acid.component.UISimpleComponent1;
37 import org.apache.myfaces.view.facelets.pss.acid.component.UISimpleComponent2;
38 import org.apache.myfaces.view.facelets.pss.acid.managed.CheckActionEventBean;
39 import org.apache.myfaces.view.facelets.pss.acid.managed.ComponentBindingBean;
40 import org.apache.myfaces.view.facelets.pss.acid.managed.ComponentBindingFormBean;
41 import org.apache.myfaces.view.facelets.pss.acid.managed.CustomSessionBean;
42 import org.apache.myfaces.view.facelets.pss.acid.managed.ForEachBean;
43 import org.apache.myfaces.view.facelets.pss.acid.managed.ResourceDependencyBean;
44 import org.apache.myfaces.view.facelets.pss.acid.managed.TestBean;
45 import org.junit.Assert;
46 import org.junit.Test;
47
48 public class AcidMyFacesRequestTestCase extends AbstractMyFacesRequestTestCase
49 {
50
51 @Override
52 protected boolean isScanAnnotations()
53 {
54 return true;
55 }
56
57 @Override
58 protected void setUpWebConfigParams() throws Exception
59 {
60 super.setUpWebConfigParams();
61 servletContext.addInitParameter("org.apache.myfaces.annotation.SCAN_PACKAGES","org.apache.myfaces.view.facelets.pss.acid");
62 servletContext.addInitParameter("javax.faces.FACELETS_LIBRARIES", "/WEB-INF/testcomponent.taglib.xml");
63 servletContext.addInitParameter(StateManager.STATE_SAVING_METHOD_PARAM_NAME, StateManager.STATE_SAVING_METHOD_CLIENT);
64 servletContext.addInitParameter("javax.faces.PARTIAL_STATE_SAVING", "true");
65 servletContext.addInitParameter(MyfacesConfig.INIT_PARAM_REFRESH_TRANSIENT_BUILD_ON_PSS, "auto");
66 }
67
68 protected ExpressionFactory createExpressionFactory()
69 {
70 return new org.apache.el.ExpressionFactoryImpl();
71 }
72
73 @Test
74 public void testIndex() throws Exception
75 {
76 startViewRequest("/index.xhtml");
77 processLifecycleExecuteAndRender();
78
79 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:component");
80 Assert.assertEquals(1, comp.getChildCount());
81 Assert.assertEquals("Dynamically added child", comp.getChildren().get(0).getAttributes().get("value"));
82
83
84
85
86
87
88
89
90
91
92
93
94 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
95 client.submit(button);
96 processLifecycleExecuteAndRender();
97
98 comp = facesContext.getViewRoot().findComponent("mainForm:component");
99 Assert.assertEquals(1, comp.getChildCount());
100 Assert.assertEquals("Dynamically added child", comp.getChildren().get(0).getAttributes().get("value"));
101
102
103
104
105
106
107
108
109
110
111
112 endRequest();
113 }
114
115 @Test
116 public void testInput() throws Exception
117 {
118 startViewRequest("/input.xhtml");
119 processLifecycleExecuteAndRender();
120 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:component");
121
122 Assert.assertEquals(1, comp.getChildCount());
123 Assert.assertEquals(1, comp.getChildren().get(0).getChildCount());
124 Assert.assertEquals("mainForm:input", comp.getChildren().get(0).getChildren().get(0).getClientId(facesContext));
125
126
127
128
129
130
131
132
133
134
135
136
137
138 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
139 client.submit(button);
140 processLifecycleExecuteAndRender();
141
142 comp = facesContext.getViewRoot().findComponent("mainForm:component");
143 Assert.assertEquals(1, comp.getChildCount());
144 Assert.assertEquals(1, comp.getChildren().get(0).getChildCount());
145 Assert.assertEquals("mainForm:input", comp.getChildren().get(0).getChildren().get(0).getClientId(facesContext));
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160 }
161
162 @Test
163 public void testRecursive() throws Exception
164 {
165 startViewRequest("/recursive.xhtml");
166 processLifecycleExecuteAndRender();
167 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:component");
168 Assert.assertEquals(2, comp.getChildCount());
169 Assert.assertEquals("Dynamically added child", comp.getChildren().get(0).getAttributes().get("value"));
170 Assert.assertEquals(1, comp.getChildren().get(1).getChildCount());
171 Assert.assertEquals("Dynamically added child", comp.getChildren().get(1).getChildren().get(0).getAttributes().get("value"));
172
173 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
174 client.submit(button);
175 processLifecycleExecuteAndRender();
176
177 comp = facesContext.getViewRoot().findComponent("mainForm:component");
178 Assert.assertEquals(2, comp.getChildCount());
179 Assert.assertEquals("Dynamically added child", comp.getChildren().get(0).getAttributes().get("value"));
180 Assert.assertEquals(1, comp.getChildren().get(1).getChildCount());
181 Assert.assertEquals("Dynamically added child", comp.getChildren().get(1).getChildren().get(0).getAttributes().get("value"));
182
183 endRequest();
184 }
185
186 @Test
187 public void testStable() throws Exception
188 {
189 startViewRequest("/stable.xhtml");
190 processLifecycleExecuteAndRender();
191 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:component");
192 Assert.assertEquals(3, comp.getChildCount());
193 Assert.assertEquals("1", comp.getChildren().get(0).getAttributes().get("value"));
194 Assert.assertEquals("2", comp.getChildren().get(1).getAttributes().get("value"));
195 Assert.assertEquals("text3", comp.getChildren().get(2).getId());
196
197 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
198 client.submit(button);
199 processLifecycleExecuteAndRender();
200
201 comp = facesContext.getViewRoot().findComponent("mainForm:component");
202 Assert.assertEquals(3, comp.getChildCount());
203 Assert.assertEquals("1", comp.getChildren().get(0).getAttributes().get("value"));
204 Assert.assertEquals("2", comp.getChildren().get(1).getAttributes().get("value"));
205 Assert.assertEquals("text3", comp.getChildren().get(2).getId());
206
207 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
208 client.submit(button);
209 processLifecycleExecuteAndRender();
210
211 comp = facesContext.getViewRoot().findComponent("mainForm:component");
212 Assert.assertEquals(3, comp.getChildCount());
213 Assert.assertEquals("1", comp.getChildren().get(0).getAttributes().get("value"));
214 Assert.assertEquals("2", comp.getChildren().get(1).getAttributes().get("value"));
215 Assert.assertEquals("text3", comp.getChildren().get(2).getId());
216
217 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
218 UIInput input = (UIInput) facesContext.getViewRoot().findComponent("mainForm:text3");
219 client.inputText(input, "3");
220 client.submit(button);
221 processLifecycleExecuteAndRender();
222
223 comp = facesContext.getViewRoot().findComponent("mainForm:component");
224 Assert.assertEquals(3, comp.getChildCount());
225 Assert.assertEquals("1", comp.getChildren().get(0).getAttributes().get("value"));
226 Assert.assertEquals("2", comp.getChildren().get(1).getAttributes().get("value"));
227 Assert.assertEquals("text3", comp.getChildren().get(2).getId());
228
229 }
230
231 @Test
232 public void testTable() throws Exception
233 {
234 startViewRequest("/table.xhtml");
235 processLifecycleExecuteAndRender();
236
237 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:component");
238 Assert.assertEquals(1, comp.getChildCount());
239 HtmlDataTable dataTable = (HtmlDataTable) comp.getChildren().get(0);
240 Assert.assertEquals(1, dataTable.getChildCount());
241
242 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
243 client.submit(button);
244 processLifecycleExecuteAndRender();
245
246 comp = facesContext.getViewRoot().findComponent("mainForm:component");
247 Assert.assertEquals(1, comp.getChildCount());
248 dataTable = (HtmlDataTable) comp.getChildren().get(0);
249 Assert.assertEquals(1, dataTable.getChildCount());
250 }
251
252 @Test
253 public void testToggle() throws Exception
254 {
255 startViewRequest("/toggle.xhtml");
256 processLifecycleExecuteAndRender();
257
258 UIComponent 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 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
264 client.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 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
273 client.submit(button);
274 processLifecycleExecuteAndRender();
275
276 comp = facesContext.getViewRoot().findComponent("mainForm:component");
277 Assert.assertEquals(2, comp.getChildCount());
278 Assert.assertEquals("Manually added child 2<br/>", comp.getChildren().get(0).getAttributes().get("value"));
279 Assert.assertEquals("Manually added child 1<br/>", comp.getChildren().get(1).getAttributes().get("value"));
280
281 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
282 client.submit(button);
283 processLifecycleExecuteAndRender();
284
285 comp = facesContext.getViewRoot().findComponent("mainForm:component");
286 Assert.assertEquals(2, comp.getChildCount());
287 Assert.assertEquals("Manually added child 1<br/>", comp.getChildren().get(0).getAttributes().get("value"));
288 Assert.assertEquals("Manually added child 2<br/>", comp.getChildren().get(1).getAttributes().get("value"));
289
290 }
291
292 @Test
293 public void testInclude() throws Exception
294 {
295 startViewRequest("/include.xhtml");
296 processLifecycleExecute();
297
298 facesContext.getApplication().getViewHandler().getViewDeclarationLanguage(
299 facesContext, facesContext.getViewRoot().getViewId()).buildView(facesContext, facesContext.getViewRoot());
300
301 UIComponent component = facesContext.getViewRoot().findComponent("mainForm:component1");
302 component.getAttributes().put("test", "test1");
303 renderResponse();
304
305 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:page1");
306 client.submit(button);
307 processLifecycleExecute();
308
309 component = facesContext.getViewRoot().findComponent("mainForm:component1");
310 Assert.assertEquals("test1", component.getAttributes().get("test"));
311 renderResponse();
312
313 component = facesContext.getViewRoot().findComponent("mainForm:component1");
314 Assert.assertEquals("test1", component.getAttributes().get("test"));
315
316
317 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:page2");
318 client.submit(button);
319
320 processLifecycleExecute();
321 component = facesContext.getViewRoot().findComponent("mainForm:component1");
322
323 Assert.assertEquals("test1", component.getAttributes().get("test"));
324
325
326 facesContext.getApplication().getViewHandler().getViewDeclarationLanguage(
327 facesContext, facesContext.getViewRoot().getViewId()).buildView(facesContext, facesContext.getViewRoot());
328
329
330 component = facesContext.getViewRoot().findComponent("mainForm:component2");
331 Assert.assertNull(component.getAttributes().get("test"));
332
333 component.getAttributes().put("test", "test2");
334 renderResponse();
335
336 component = facesContext.getViewRoot().findComponent("mainForm:component2");
337 Assert.assertEquals("test2", component.getAttributes().get("test"));
338
339 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:page2");
340 client.submit(button);
341
342 processLifecycleExecute();
343 component = facesContext.getViewRoot().findComponent("mainForm:component2");
344
345 Assert.assertNotNull("mainForm:component2 was not restored correctly",component);
346 Assert.assertEquals("test2", component.getAttributes().get("test"));
347
348
349 facesContext.getApplication().getViewHandler().getViewDeclarationLanguage(
350 facesContext, facesContext.getViewRoot().getViewId()).buildView(facesContext, facesContext.getViewRoot());
351
352
353 component = facesContext.getViewRoot().findComponent("mainForm:component2");
354 Assert.assertEquals("test2", component.getAttributes().get("test"));
355
356 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:page2");
357 client.submit(button);
358
359 processLifecycleExecute();
360 component = facesContext.getViewRoot().findComponent("mainForm:component2");
361
362 Assert.assertEquals("test2", component.getAttributes().get("test"));
363 }
364
365
366
367
368
369
370
371 @Test
372 public void testInclude2() throws Exception
373 {
374 startViewRequest("/include.xhtml");
375 processLifecycleExecute();
376
377 facesContext.getApplication().getViewHandler().getViewDeclarationLanguage(
378 facesContext, facesContext.getViewRoot().getViewId()).buildView(facesContext, facesContext.getViewRoot());
379
380 UIComponent component = facesContext.getViewRoot().findComponent("mainForm:component1");
381 Assert.assertNotNull(component);
382 renderResponse();
383
384 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:page1");
385 client.submit(button);
386
387 processLifecycleExecute();
388
389 component = facesContext.getViewRoot().findComponent("mainForm:component1");
390 Assert.assertNotNull(component);
391 renderResponse();
392
393 component = facesContext.getViewRoot().findComponent("mainForm:component1");
394 Assert.assertNotNull(component);
395
396
397 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:page2");
398 client.submit(button);
399
400 processLifecycleExecute();
401 component = facesContext.getViewRoot().findComponent("mainForm:component1");
402
403 Assert.assertNotNull(component);
404
405
406 facesContext.getApplication().getViewHandler().getViewDeclarationLanguage(
407 facesContext, facesContext.getViewRoot().getViewId()).buildView(facesContext, facesContext.getViewRoot());
408
409
410 component = facesContext.getViewRoot().findComponent("mainForm:component2");
411 Assert.assertNotNull(component);
412 renderResponse();
413
414 component = facesContext.getViewRoot().findComponent("mainForm:component2");
415 Assert.assertNotNull(component);
416
417 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:page2");
418 client.submit(button);
419
420 processLifecycleExecute();
421 component = facesContext.getViewRoot().findComponent("mainForm:component2");
422
423 Assert.assertNotNull(component);
424
425
426 facesContext.getApplication().getViewHandler().getViewDeclarationLanguage(
427 facesContext, facesContext.getViewRoot().getViewId()).buildView(facesContext, facesContext.getViewRoot());
428
429
430 component = facesContext.getViewRoot().findComponent("mainForm:component2");
431 Assert.assertNotNull(component);
432
433 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:page2");
434 client.submit(button);
435
436 processLifecycleExecute();
437 component = facesContext.getViewRoot().findComponent("mainForm:component2");
438
439 Assert.assertNotNull(component);
440 }
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459 @Test
460 public void testComponentBinding() throws Exception
461 {
462 startViewRequest("/componentBinding1.xhtml");
463 processLifecycleExecuteAndRender();
464
465 UIComponent comp = facesContext.getViewRoot().findComponent("panel");
466 Assert.assertNotNull(comp);
467 Assert.assertEquals(1, comp.getChildCount());
468
469 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
470 client.submit(button);
471 processLifecycleExecuteAndRender();
472 Assert.assertNotNull(comp);
473
474
475 Assert.assertEquals(1, comp.getChildCount());
476
477 comp = facesContext.getViewRoot().findComponent("panel");
478
479 Assert.assertEquals("value1", comp.getAttributes().get("attr1"));
480 Assert.assertEquals("value2", comp.getChildren().get(0).getAttributes().get("attr2"));
481
482 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
483 client.submit(button);
484 processLifecycleExecuteAndRender();
485
486 comp = facesContext.getViewRoot().findComponent("panel");
487 Assert.assertNotNull(comp);
488
489
490 Assert.assertEquals(1, comp.getChildCount());
491
492 Assert.assertEquals("value1", comp.getAttributes().get("attr1"));
493 Assert.assertEquals("value2", comp.getChildren().get(0).getAttributes().get("attr2"));
494
495 endRequest();
496 }
497
498 @Test
499 public void testComponentBinding2() throws Exception
500 {
501 startViewRequest("/componentBinding2.xhtml");
502 processLifecycleExecuteAndRender();
503
504 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:panel");
505 Assert.assertNotNull(comp);
506 int fieldCount = comp.getChildCount();
507 Set<String> clientIds = new TreeSet<String>();
508 for (UIComponent c : comp.getChildren())
509 {
510 clientIds.add(c.getClientId(facesContext));
511 }
512
513 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
514 client.submit(button);
515 processLifecycleExecute();
516
517 comp = facesContext.getViewRoot().findComponent("mainForm:panel");
518 Assert.assertNotNull(comp);
519
520 Assert.assertEquals(fieldCount, comp.getChildCount());
521 Set<String> clientIds2 = new TreeSet<String>();
522 for (UIComponent c : comp.getChildren())
523 {
524 clientIds2.add(c.getClientId(facesContext));
525 }
526 Assert.assertArrayEquals(clientIds.toArray(), clientIds2.toArray());
527
528 ComponentBindingFormBean formBean = facesContext.getApplication().evaluateExpressionGet(
529 facesContext, "#{componentBindingFormBean}", ComponentBindingFormBean.class);
530 formBean.forceRebuild();
531
532 processLifecycleRender();
533
534 comp = facesContext.getViewRoot().findComponent("mainForm:panel");
535 Assert.assertNotNull(comp);
536 fieldCount = comp.getChildCount();
537 clientIds.clear();
538 for (UIComponent c : comp.getChildren())
539 {
540 clientIds.add(c.getClientId(facesContext));
541 }
542
543 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
544 client.submit(button);
545
546 processLifecycleExecute();
547
548 comp = facesContext.getViewRoot().findComponent("mainForm:panel");
549 Assert.assertNotNull(comp);
550 Assert.assertEquals(fieldCount, comp.getChildCount());
551 clientIds2.clear();
552 for (UIComponent c : comp.getChildren())
553 {
554 clientIds2.add(c.getClientId(facesContext));
555 }
556 Assert.assertArrayEquals(clientIds.toArray(), clientIds2.toArray());
557
558 formBean = facesContext.getApplication().evaluateExpressionGet(
559 facesContext, "#{componentBindingFormBean}", ComponentBindingFormBean.class);
560 formBean.forceRebuild();
561
562 processLifecycleRender();
563
564 comp = facesContext.getViewRoot().findComponent("mainForm:panel");
565 Assert.assertNotNull(comp);
566 fieldCount = comp.getChildCount();
567 clientIds.clear();
568 for (UIComponent c : comp.getChildren())
569 {
570 clientIds.add(c.getClientId(facesContext));
571 }
572
573 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
574 client.submit(button);
575
576 processLifecycleExecute();
577
578 comp = facesContext.getViewRoot().findComponent("mainForm:panel");
579 Assert.assertNotNull(comp);
580 Assert.assertEquals(fieldCount, comp.getChildCount());
581 clientIds2.clear();
582 for (UIComponent c : comp.getChildren())
583 {
584 clientIds2.add(c.getClientId(facesContext));
585 }
586 Assert.assertArrayEquals(clientIds.toArray(), clientIds2.toArray());
587
588 formBean = facesContext.getApplication().evaluateExpressionGet(
589 facesContext, "#{componentBindingFormBean}", ComponentBindingFormBean.class);
590 formBean.forceRebuild();
591
592 processLifecycleRender();
593
594 comp = facesContext.getViewRoot().findComponent("mainForm:panel");
595 Assert.assertNotNull(comp);
596
597
598 endRequest();
599 }
600
601 @Test
602 public void testViewParamBinding() throws Exception
603 {
604 startViewRequest("/viewParamBinding1.xhtml");
605 processLifecycleExecuteAndRender();
606
607 UIComponent comp = facesContext.getViewRoot().findComponent("panel");
608 Assert.assertNotNull(comp);
609 Assert.assertEquals(1, comp.getChildCount());
610
611 UIViewParameter viewParam = (UIViewParameter) facesContext.getExternalContext().getRequestMap().get("foo");
612 Assert.assertNotNull(viewParam);
613 Assert.assertEquals("foo", viewParam.getName());
614 UIViewParameter viewParam2 = facesContext.getApplication().evaluateExpressionGet(
615 facesContext, "#{componentBindingBean}", ComponentBindingBean.class).getViewParam();
616 Assert.assertNotNull(viewParam2);
617 Assert.assertEquals("foo2", viewParam2.getName());
618
619 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
620 client.submit(button);
621 processLifecycleExecuteAndRender();
622 Assert.assertNotNull(comp);
623
624
625 Assert.assertEquals(1, comp.getChildCount());
626
627 comp = facesContext.getViewRoot().findComponent("panel");
628
629 Assert.assertEquals("value1", comp.getAttributes().get("attr1"));
630 Assert.assertEquals("value2", comp.getChildren().get(0).getAttributes().get("attr2"));
631
632 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
633 client.submit(button);
634 processLifecycleExecuteAndRender();
635
636 comp = facesContext.getViewRoot().findComponent("panel");
637 Assert.assertNotNull(comp);
638
639
640 Assert.assertEquals(1, comp.getChildCount());
641
642 Assert.assertEquals("value1", comp.getAttributes().get("attr1"));
643 Assert.assertEquals("value2", comp.getChildren().get(0).getAttributes().get("attr2"));
644
645 endRequest();
646 }
647
648 @Test
649 public void testDynamicForm() throws Exception
650 {
651 startViewRequest("/dynamicForm.xhtml");
652 processLifecycleExecuteAndRender();
653 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:dynPanel");
654 Assert.assertNotNull(comp);
655 int fieldCount = comp.getChildCount();
656 Set<String> clientIds = new TreeSet<String>();
657 for (UIComponent c : comp.getChildren())
658 {
659 clientIds.add(c.getClientId(facesContext));
660 }
661
662 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
663 client.submit(button);
664 processLifecycleExecute();
665 comp = facesContext.getViewRoot().findComponent("mainForm:dynPanel");
666 Assert.assertNotNull(comp);
667
668 Assert.assertEquals(fieldCount, comp.getChildCount());
669 Set<String> clientIds2 = new TreeSet<String>();
670 for (UIComponent c : comp.getChildren())
671 {
672 clientIds2.add(c.getClientId(facesContext));
673 }
674 Assert.assertArrayEquals(clientIds.toArray(), clientIds2.toArray());
675
676 processLifecycleRender();
677 comp = facesContext.getViewRoot().findComponent("mainForm:dynPanel");
678 Assert.assertNotNull(comp);
679 fieldCount = comp.getChildCount();
680 clientIds.clear();
681 for (UIComponent c : comp.getChildren())
682 {
683 clientIds.add(c.getClientId(facesContext));
684 }
685
686 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
687 client.submit(button);
688 processLifecycleExecute();
689 comp = facesContext.getViewRoot().findComponent("mainForm:dynPanel");
690 Assert.assertNotNull(comp);
691
692 Assert.assertEquals(fieldCount, comp.getChildCount());
693 clientIds2.clear();
694 for (UIComponent c : comp.getChildren())
695 {
696 clientIds2.add(c.getClientId(facesContext));
697 }
698 Assert.assertArrayEquals(clientIds.toArray(), clientIds2.toArray());
699
700
701 processLifecycleRender();
702 comp = facesContext.getViewRoot().findComponent("mainForm:dynPanel");
703 Assert.assertNotNull(comp);
704 fieldCount = comp.getChildCount();
705 clientIds.clear();
706 for (UIComponent c : comp.getChildren())
707 {
708 clientIds.add(c.getClientId(facesContext));
709 }
710
711 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
712 client.submit(button);
713 processLifecycleExecute();
714 comp = facesContext.getViewRoot().findComponent("mainForm:dynPanel");
715 Assert.assertNotNull(comp);
716
717 Assert.assertEquals(fieldCount, comp.getChildCount());
718 clientIds2.clear();
719 for (UIComponent c : comp.getChildren())
720 {
721 clientIds2.add(c.getClientId(facesContext));
722 }
723 Assert.assertArrayEquals(clientIds.toArray(), clientIds2.toArray());
724
725 processLifecycleRender();
726 comp = facesContext.getViewRoot().findComponent("mainForm:dynPanel");
727 Assert.assertNotNull(comp);
728 fieldCount = comp.getChildCount();
729 clientIds.clear();
730 for (UIComponent c : comp.getChildren())
731 {
732 clientIds.add(c.getClientId(facesContext));
733 }
734
735 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
736 client.submit(button);
737 processLifecycleExecute();
738 comp = facesContext.getViewRoot().findComponent("mainForm:dynPanel");
739 Assert.assertNotNull(comp);
740
741 Assert.assertEquals(fieldCount, comp.getChildCount());
742 clientIds2.clear();
743 for (UIComponent c : comp.getChildren())
744 {
745 clientIds2.add(c.getClientId(facesContext));
746 }
747 Assert.assertArrayEquals(clientIds.toArray(), clientIds2.toArray());
748
749 processLifecycleRender();
750 comp = facesContext.getViewRoot().findComponent("mainForm:dynPanel");
751 Assert.assertNotNull(comp);
752 fieldCount = comp.getChildCount();
753 clientIds.clear();
754 for (UIComponent c : comp.getChildren())
755 {
756 clientIds.add(c.getClientId(facesContext));
757 }
758
759 endRequest();
760 }
761
762 @Test
763 public void testResourceDependency() throws Exception
764 {
765 startViewRequest("/resourceDependency1.xhtml");
766 processLifecycleExecute();
767
768 executeBeforeRender(facesContext);
769 executeBuildViewCycle(facesContext);
770
771 UIPanel headPanel = (UIPanel) facesContext.getViewRoot().getFacet("head");
772 Assert.assertNotNull(headPanel);
773 Assert.assertEquals(1, headPanel.getChildCount());
774
775 String nextUniqueId = facesContext.getViewRoot().createUniqueId(facesContext, null);
776
777 executeViewHandlerRender(facesContext);
778 executeAfterRender(facesContext);
779
780 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
781 client.submit(button);
782
783 processLifecycleExecute();
784
785 ResourceDependencyBean bean = facesContext.getApplication().evaluateExpressionGet(
786 facesContext, "#{resourceDependencyBean}", ResourceDependencyBean.class);
787 bean.setIncludeContent(true);
788
789 executeBeforeRender(facesContext);
790 executeBuildViewCycle(facesContext);
791
792 headPanel = (UIPanel) facesContext.getViewRoot().getFacet("head");
793 Assert.assertNotNull(headPanel);
794 Assert.assertEquals(1, headPanel.getChildCount());
795 Assert.assertNotSame(nextUniqueId, headPanel.getChildren().get(0).getId());
796
797 executeViewHandlerRender(facesContext);
798 executeAfterRender(facesContext);
799 }
800
801 @Test
802 public void testResourceDependency2() throws Exception
803 {
804 startViewRequest("/resourceDependency2.xhtml");
805 processLifecycleExecute();
806
807 executeBeforeRender(facesContext);
808 executeBuildViewCycle(facesContext);
809
810 UIPanel headPanel = (UIPanel) facesContext.getViewRoot().getFacet("head");
811 Assert.assertNull(headPanel);
812
813 String nextUniqueId = facesContext.getViewRoot().createUniqueId(facesContext, null);
814
815 executeViewHandlerRender(facesContext);
816 executeAfterRender(facesContext);
817
818 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
819 client.submit(button);
820
821 processLifecycleExecute();
822
823 ResourceDependencyBean bean = facesContext.getApplication().evaluateExpressionGet(
824 facesContext, "#{resourceDependencyBean}", ResourceDependencyBean.class);
825 bean.setIncludeContent(true);
826
827 executeBeforeRender(facesContext);
828 executeBuildViewCycle(facesContext);
829
830 headPanel = (UIPanel) facesContext.getViewRoot().getFacet("head");
831 Assert.assertNotNull(headPanel);
832 Assert.assertTrue(1 >= headPanel.getChildCount());
833 Assert.assertNotSame(nextUniqueId, headPanel.getChildren().get(0).getId());
834
835 executeViewHandlerRender(facesContext);
836 executeAfterRender(facesContext);
837
838 UICommand button2 = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
839 client.submit(button2);
840
841 processLifecycleExecute();
842
843 bean = facesContext.getApplication().evaluateExpressionGet(
844 facesContext, "#{resourceDependencyBean}", ResourceDependencyBean.class);
845 bean.setIncludeContent(false);
846
847 executeBeforeRender(facesContext);
848 executeBuildViewCycle(facesContext);
849
850 headPanel = (UIPanel) facesContext.getViewRoot().getFacet("head");
851 Assert.assertNotNull(headPanel);
852 Assert.assertTrue(1 >= headPanel.getChildCount());
853
854
855 executeViewHandlerRender(facesContext);
856 executeAfterRender(facesContext);
857
858 UICommand button3 = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
859 client.submit(button3);
860
861 processLifecycleExecute();
862
863 bean = facesContext.getApplication().evaluateExpressionGet(
864 facesContext, "#{resourceDependencyBean}", ResourceDependencyBean.class);
865 bean.setIncludeContent(true);
866
867 executeBeforeRender(facesContext);
868 executeBuildViewCycle(facesContext);
869
870 headPanel = (UIPanel) facesContext.getViewRoot().getFacet("head");
871 Assert.assertNotNull(headPanel);
872 Assert.assertTrue(1 >= headPanel.getChildCount());
873
874
875 executeViewHandlerRender(facesContext);
876 executeAfterRender(facesContext);
877
878 UICommand button4 = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
879 client.submit(button4);
880
881 processLifecycleExecute();
882
883 bean = facesContext.getApplication().evaluateExpressionGet(
884 facesContext, "#{resourceDependencyBean}", ResourceDependencyBean.class);
885 bean.setIncludeContent(false);
886
887 executeBeforeRender(facesContext);
888 executeBuildViewCycle(facesContext);
889
890 headPanel = (UIPanel) facesContext.getViewRoot().getFacet("head");
891 Assert.assertNotNull(headPanel);
892 Assert.assertTrue(1 >= headPanel.getChildCount());
893
894
895 executeViewHandlerRender(facesContext);
896 executeAfterRender(facesContext);
897 }
898
899 @Test
900 public void testAddSimpleComponentVDL() throws Exception
901 {
902 startViewRequest("/addSimpleComponentVDL.xhtml");
903 processLifecycleExecuteAndRender();
904
905 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:component");
906 Assert.assertEquals(1, comp.getChildCount());
907 Assert.assertEquals("Dynamically added child", comp.getChildren().get(0).getAttributes().get("value"));
908
909 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
910 client.submit(button);
911 processLifecycleExecuteAndRender();
912
913 comp = facesContext.getViewRoot().findComponent("mainForm:component");
914 Assert.assertEquals(1, comp.getChildCount());
915 Assert.assertEquals("Dynamically added child", comp.getChildren().get(0).getAttributes().get("value"));
916
917 endRequest();
918 }
919
920 @Test
921 public void testAddSimpleIncludeVDL_1() throws Exception
922 {
923 startViewRequest("/addSimpleIncludeVDL_1.xhtml");
924 processLifecycleExecuteAndRender();
925
926 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:component");
927 Assert.assertEquals(1, comp.getChildCount());
928 UIComponent wrapper = comp.getChildren().get(0);
929 Assert.assertEquals(2, wrapper.getChildCount());
930 Assert.assertEquals("Dynamically added child", wrapper.getChildren().get(1).getAttributes().get("value"));
931 MockPrintWriter writer1 = (MockPrintWriter) response.getWriter();
932 Assert.assertTrue(new String(writer1.content()).contains("Dynamically added markup"));
933
934 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
935 client.submit(button);
936 processLifecycleExecuteAndRender();
937
938 comp = facesContext.getViewRoot().findComponent("mainForm:component");
939 Assert.assertEquals(1, comp.getChildCount());
940 wrapper = comp.getChildren().get(0);
941 Assert.assertEquals(2, wrapper.getChildCount());
942 Assert.assertEquals("Dynamically added child", wrapper.getChildren().get(1).getAttributes().get("value"));
943 MockPrintWriter writer2 = (MockPrintWriter) response.getWriter();
944 Assert.assertTrue(new String(writer2.content()).contains("Dynamically added markup"));
945
946 endRequest();
947 }
948
949 @Test
950 public void testAddSimpleIncludeVDL_2() throws Exception
951 {
952 startViewRequest("/addSimpleIncludeVDL_2.xhtml");
953 processLifecycleExecuteAndRender();
954
955 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:component");
956 Assert.assertEquals(1, comp.getChildCount());
957 UIComponent wrapper = comp.getChildren().get(0);
958 Assert.assertEquals(3, wrapper.getChildCount());
959 Assert.assertEquals("Dynamically added child", wrapper.getChildren().get(1).getAttributes().get("value"));
960 MockPrintWriter writer1 = (MockPrintWriter) response.getWriter();
961 String content = new String(writer1.content());
962 Assert.assertTrue(content.contains("Dynamically added markup"));
963 Assert.assertTrue(content.contains("Value in param1: value1"));
964 Assert.assertTrue(content.contains("Value in param2: value2"));
965
966 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
967 client.submit(button);
968 processLifecycleExecute();
969
970 TestBean bean = facesContext.getApplication().evaluateExpressionGet(
971 facesContext, "#{testBean}", TestBean.class);
972 bean.setParam2("otherValue2");
973
974 processLifecycleRender();
975
976 comp = facesContext.getViewRoot().findComponent("mainForm:component");
977 Assert.assertEquals(1, comp.getChildCount());
978 wrapper = comp.getChildren().get(0);
979 Assert.assertEquals(3, wrapper.getChildCount());
980 Assert.assertEquals("Dynamically added child", wrapper.getChildren().get(1).getAttributes().get("value"));
981 MockPrintWriter writer2 = (MockPrintWriter) response.getWriter();
982 String content2 = new String(writer2.content());
983 Assert.assertTrue(content2.contains("Dynamically added markup"));
984 Assert.assertTrue(content2.contains("Value in param1: value1"));
985 Assert.assertTrue(content2.contains("Value in param2: otherValue2"));
986
987 endRequest();
988 }
989
990 @Test
991 public void testAddSimpleCCVDL() throws Exception
992 {
993 startViewRequest("/addSimpleCCVDL.xhtml");
994 processLifecycleExecuteAndRender();
995
996 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:component");
997 Assert.assertEquals(1, comp.getChildCount());
998 UIComponent wrapper = comp.getChildren().get(0);
999 Assert.assertNotNull(wrapper);
1000 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1001 UIComponent ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1002 Assert.assertNotNull(ccContent);
1003 Assert.assertEquals(3, ccContent.getChildCount());
1004 Assert.assertEquals("Dynamically added header",
1005 ccContent.getChildren().get(0).getFacet("header").getAttributes().get("value"));
1006 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1007 MockPrintWriter writer1 = (MockPrintWriter) response.getWriter();
1008 Assert.assertTrue(new String(writer1.content()).contains("Dynamically added markup"));
1009
1010 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
1011 client.submit(button);
1012 processLifecycleExecuteAndRender();
1013
1014 comp = facesContext.getViewRoot().findComponent("mainForm:component");
1015 Assert.assertEquals(1, comp.getChildCount());
1016 wrapper = comp.getChildren().get(0);
1017 Assert.assertNotNull(wrapper);
1018 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1019 ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1020 Assert.assertNotNull(ccContent);
1021 Assert.assertEquals(3, ccContent.getChildCount());
1022 Assert.assertEquals("Dynamically added header",
1023 ccContent.getChildren().get(0).getFacet("header").getAttributes().get("value"));
1024 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1025 MockPrintWriter writer2 = (MockPrintWriter) response.getWriter();
1026 Assert.assertTrue(new String(writer2.content()).contains("Dynamically added markup"));
1027
1028 endRequest();
1029 }
1030
1031 @Test
1032 public void testAddSimpleCCVDL2() throws Exception
1033 {
1034 startViewRequest("/addSimpleCCVDL2.xhtml");
1035 processLifecycleExecuteAndRender();
1036
1037 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:component");
1038 Assert.assertEquals(1, comp.getChildCount());
1039 UIComponent wrapper = comp.getChildren().get(0);
1040 Assert.assertNotNull(wrapper);
1041 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1042 UIComponent ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1043 Assert.assertNotNull(ccContent);
1044 Assert.assertEquals(3, ccContent.getChildCount());
1045 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1046 MockPrintWriter writer1 = (MockPrintWriter) response.getWriter();
1047 String content1 = new String(writer1.content());
1048 Assert.assertTrue(content1.contains("Dynamically added header"));
1049 Assert.assertTrue(content1.contains("Dynamically added markup"));
1050
1051 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
1052 client.submit(button);
1053 processLifecycleExecuteAndRender();
1054
1055 comp = facesContext.getViewRoot().findComponent("mainForm:component");
1056 Assert.assertEquals(1, comp.getChildCount());
1057 wrapper = comp.getChildren().get(0);
1058 Assert.assertNotNull(wrapper);
1059 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1060 ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1061 Assert.assertNotNull(ccContent);
1062 Assert.assertEquals(3, ccContent.getChildCount());
1063 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1064 MockPrintWriter writer2 = (MockPrintWriter) response.getWriter();
1065 String content2 = new String(writer2.content());
1066 Assert.assertTrue(content2.contains("Dynamically added header"));
1067 Assert.assertTrue(content2.contains("Dynamically added markup"));
1068
1069 endRequest();
1070 }
1071
1072 @Test
1073 public void testAddSimpleCCVDL3() throws Exception
1074 {
1075 startViewRequest("/addSimpleCCVDL3.xhtml");
1076 processLifecycleExecuteAndRender();
1077
1078 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:component");
1079 Assert.assertEquals(1, comp.getChildCount());
1080 UIComponent wrapper = comp.getChildren().get(0);
1081 Assert.assertNotNull(wrapper);
1082 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1083 UIComponent ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1084 Assert.assertNotNull(ccContent);
1085 Assert.assertEquals(3, ccContent.getChildCount());
1086
1087
1088 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1089 MockPrintWriter writer1 = (MockPrintWriter) response.getWriter();
1090 String content1 = new String(writer1.content());
1091 Assert.assertTrue(content1.contains("Dynamically added markup"));
1092 int indexDynHeader1_1 = content1.indexOf("Start Dynamic Header");
1093 int indexDynHeader1_2 = content1.indexOf("Dynamically added header", indexDynHeader1_1);
1094 int indexDynHeader1_3 = content1.indexOf("End Dynamic Header", indexDynHeader1_2);
1095 Assert.assertNotSame(-1, indexDynHeader1_1);
1096 Assert.assertNotSame(-1, indexDynHeader1_2);
1097 Assert.assertNotSame(-1, indexDynHeader1_3);
1098
1099 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
1100 client.submit(button);
1101 processLifecycleExecuteAndRender();
1102
1103 comp = facesContext.getViewRoot().findComponent("mainForm:component");
1104 Assert.assertEquals(1, comp.getChildCount());
1105 wrapper = comp.getChildren().get(0);
1106 Assert.assertNotNull(wrapper);
1107 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1108 ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1109 Assert.assertNotNull(ccContent);
1110 Assert.assertEquals(3, ccContent.getChildCount());
1111
1112
1113 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1114 MockPrintWriter writer2 = (MockPrintWriter) response.getWriter();
1115 String content2 = new String(writer2.content());
1116 Assert.assertTrue(content2.contains("Dynamically added markup"));
1117 int indexDynHeader1 = content2.indexOf("Start Dynamic Header");
1118 int indexDynHeader2 = content2.indexOf("Dynamically added header", indexDynHeader1);
1119 int indexDynHeader3 = content2.indexOf("End Dynamic Header", indexDynHeader2);
1120 Assert.assertNotSame(-1, indexDynHeader1);
1121 Assert.assertNotSame(-1, indexDynHeader2);
1122 Assert.assertNotSame(-1, indexDynHeader3);
1123
1124 endRequest();
1125 }
1126
1127 @Test
1128 public void testAddSimpleCCVDL4() throws Exception
1129 {
1130 startViewRequest("/addSimpleCCVDL4.xhtml");
1131 processLifecycleExecuteAndRender();
1132
1133 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:component");
1134 Assert.assertEquals(1, comp.getChildCount());
1135 UIComponent wrapper = comp.getChildren().get(0);
1136 Assert.assertNotNull(wrapper);
1137 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1138 UIComponent ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1139 Assert.assertNotNull(ccContent);
1140 Assert.assertEquals(3, ccContent.getChildCount());
1141
1142
1143 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1144 MockPrintWriter writer1 = (MockPrintWriter) response.getWriter();
1145 String content1 = new String(writer1.content());
1146 Assert.assertTrue(content1.contains("Dynamically added markup"));
1147 int indexDynHeader1_1 = content1.indexOf("Start Dynamic Header");
1148 int indexDynHeader1_2 = content1.indexOf("Dynamically added header", indexDynHeader1_1);
1149 int indexDynHeader1_3 = content1.indexOf("End Dynamic Header", indexDynHeader1_2);
1150 Assert.assertNotSame(-1, indexDynHeader1_1);
1151 Assert.assertNotSame(-1, indexDynHeader1_2);
1152 Assert.assertNotSame(-1, indexDynHeader1_3);
1153
1154 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
1155 client.submit(button);
1156 processLifecycleExecuteAndRender();
1157
1158 comp = facesContext.getViewRoot().findComponent("mainForm:component");
1159 Assert.assertEquals(1, comp.getChildCount());
1160 wrapper = comp.getChildren().get(0);
1161 Assert.assertNotNull(wrapper);
1162 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1163 ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1164 Assert.assertNotNull(ccContent);
1165 Assert.assertEquals(3, ccContent.getChildCount());
1166
1167
1168 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1169 MockPrintWriter writer2 = (MockPrintWriter) response.getWriter();
1170 String content2 = new String(writer2.content());
1171 Assert.assertTrue(content2.contains("Dynamically added markup"));
1172 int indexDynHeader1 = content2.indexOf("Start Dynamic Header");
1173 int indexDynHeader2 = content2.indexOf("Dynamically added header", indexDynHeader1);
1174 int indexDynHeader3 = content2.indexOf("End Dynamic Header", indexDynHeader2);
1175 Assert.assertNotSame(-1, indexDynHeader1);
1176 Assert.assertNotSame(-1, indexDynHeader2);
1177 Assert.assertNotSame(-1, indexDynHeader3);
1178
1179 endRequest();
1180 }
1181
1182 @Test
1183 public void testAddSimpleCCVDL5() throws Exception
1184 {
1185 startViewRequest("/addSimpleCCVDL5.xhtml");
1186 processLifecycleExecuteAndRender();
1187
1188 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:component");
1189 Assert.assertEquals(1, comp.getChildCount());
1190 UIComponent wrapper = comp.getChildren().get(0);
1191 Assert.assertNotNull(wrapper);
1192 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1193 UIComponent ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1194 Assert.assertNotNull(ccContent);
1195 Assert.assertEquals(3, ccContent.getChildCount());
1196 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1197 MockPrintWriter writer1 = (MockPrintWriter) response.getWriter();
1198 String content1 = new String(writer1.content());
1199 Assert.assertTrue(content1.contains("Dynamically added markup"));
1200 int indexDynHeader1_1 = content1.indexOf("Start Dynamic Header");
1201 int indexDynHeader1_2 = content1.indexOf("Dynamically added header", indexDynHeader1_1);
1202 int indexDynHeader1_3 = content1.indexOf("End Dynamic Header", indexDynHeader1_2);
1203 Assert.assertNotSame(-1, indexDynHeader1_1);
1204 Assert.assertNotSame(-1, indexDynHeader1_2);
1205 Assert.assertNotSame(-1, indexDynHeader1_3);
1206
1207 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
1208 client.submit(button);
1209 processLifecycleExecuteAndRender();
1210
1211 comp = facesContext.getViewRoot().findComponent("mainForm:component");
1212 Assert.assertEquals(1, comp.getChildCount());
1213 wrapper = comp.getChildren().get(0);
1214 Assert.assertNotNull(wrapper);
1215 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1216 ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1217 Assert.assertNotNull(ccContent);
1218 Assert.assertEquals(3, ccContent.getChildCount());
1219 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1220 MockPrintWriter writer2 = (MockPrintWriter) response.getWriter();
1221 String content2 = new String(writer2.content());
1222 Assert.assertTrue(content2.contains("Dynamically added markup"));
1223 int indexDynHeader2_1 = content2.indexOf("Start Dynamic Header");
1224 int indexDynHeader2_2 = content2.indexOf("Dynamically added header", indexDynHeader2_1);
1225 int indexDynHeader2_3 = content2.indexOf("End Dynamic Header", indexDynHeader2_2);
1226 Assert.assertNotSame(-1, indexDynHeader2_1);
1227 Assert.assertNotSame(-1, indexDynHeader2_2);
1228 Assert.assertNotSame(-1, indexDynHeader2_3);
1229
1230
1231 endRequest();
1232 }
1233
1234 @Test
1235 public void testAddSimpleCCVDL6() throws Exception
1236 {
1237 startViewRequest("/addSimpleCCVDL6.xhtml");
1238 processLifecycleExecuteAndRender();
1239
1240 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:component");
1241 Assert.assertEquals(1, comp.getChildCount());
1242 UIComponent wrapper = comp.getChildren().get(0);
1243 Assert.assertNotNull(wrapper);
1244 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1245 UIComponent ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1246 Assert.assertNotNull(ccContent);
1247 Assert.assertEquals(3, ccContent.getChildCount());
1248 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1249 MockPrintWriter writer1 = (MockPrintWriter) response.getWriter();
1250 String content1 = new String(writer1.content());
1251 Assert.assertTrue(content1.contains("Dynamically added markup"));
1252 int indexDynHeader1_1 = content1.indexOf("Start Dynamic Header");
1253 int indexDynHeader1_2 = content1.indexOf("Dynamically added header", indexDynHeader1_1);
1254 int indexDynHeader1_3 = content1.indexOf("End Dynamic Header", indexDynHeader1_2);
1255 Assert.assertNotSame(-1, indexDynHeader1_1);
1256 Assert.assertNotSame(-1, indexDynHeader1_2);
1257 Assert.assertNotSame(-1, indexDynHeader1_3);
1258
1259 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
1260 client.submit(button);
1261 processLifecycleExecuteAndRender();
1262
1263 comp = facesContext.getViewRoot().findComponent("mainForm:component");
1264 Assert.assertEquals(1, comp.getChildCount());
1265 wrapper = comp.getChildren().get(0);
1266 Assert.assertNotNull(wrapper);
1267 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1268 ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1269 Assert.assertNotNull(ccContent);
1270 Assert.assertEquals(3, ccContent.getChildCount());
1271 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1272 MockPrintWriter writer2 = (MockPrintWriter) response.getWriter();
1273 String content2 = new String(writer2.content());
1274 Assert.assertTrue(content2.contains("Dynamically added markup"));
1275 int indexDynHeader2_1 = content2.indexOf("Start Dynamic Header");
1276 int indexDynHeader2_2 = content2.indexOf("Dynamically added header", indexDynHeader2_1);
1277 int indexDynHeader2_3 = content2.indexOf("End Dynamic Header", indexDynHeader2_2);
1278 Assert.assertNotSame(-1, indexDynHeader2_1);
1279 Assert.assertNotSame(-1, indexDynHeader2_2);
1280 Assert.assertNotSame(-1, indexDynHeader2_3);
1281
1282 endRequest();
1283 }
1284
1285 @Test
1286 public void testAddSimpleCCVDL7() throws Exception
1287 {
1288 startViewRequest("/addSimpleCCVDL7.xhtml");
1289 processLifecycleExecuteAndRender();
1290
1291 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:component");
1292 Assert.assertEquals(1, comp.getChildCount());
1293 UIComponent wrapper = comp.getChildren().get(0);
1294 Assert.assertNotNull(wrapper);
1295 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1296 UIComponent ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1297 Assert.assertNotNull(ccContent);
1298 Assert.assertEquals(3, ccContent.getChildCount());
1299
1300
1301 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1302 MockPrintWriter writer1 = (MockPrintWriter) response.getWriter();
1303 String content1 = new String(writer1.content());
1304 Assert.assertTrue(content1.contains("Dynamically added markup"));
1305 int indexDynHeader1_1 = content1.indexOf("Start Dynamic Header");
1306 int indexDynHeader1_2 = content1.indexOf("Dynamically added header", indexDynHeader1_1);
1307 int indexDynHeader1_3 = content1.indexOf("End Dynamic Header", indexDynHeader1_2);
1308 Assert.assertNotSame(-1, indexDynHeader1_1);
1309 Assert.assertNotSame(-1, indexDynHeader1_2);
1310 Assert.assertNotSame(-1, indexDynHeader1_3);
1311
1312 Assert.assertFalse(content1.contains("This is section 1"));
1313
1314 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
1315 client.submit(button);
1316 processLifecycleExecute();
1317
1318 CustomSessionBean sessionBean = facesContext.getApplication().evaluateExpressionGet(
1319 facesContext, "#{customSessionBean}", CustomSessionBean.class);
1320
1321
1322 sessionBean.setShowSection1(true);
1323
1324 renderResponse();
1325
1326 comp = facesContext.getViewRoot().findComponent("mainForm:component");
1327 Assert.assertEquals(1, comp.getChildCount());
1328 wrapper = comp.getChildren().get(0);
1329 Assert.assertNotNull(wrapper);
1330 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1331 ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1332 Assert.assertNotNull(ccContent);
1333 Assert.assertEquals(3, ccContent.getChildCount());
1334
1335
1336 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1337 MockPrintWriter writer2 = (MockPrintWriter) response.getWriter();
1338 String content2 = new String(writer2.content());
1339 Assert.assertTrue(content2.contains("Dynamically added markup"));
1340 int indexDynHeader1 = content2.indexOf("Start Dynamic Header");
1341 int indexDynHeader2 = content2.indexOf("Dynamically added header", indexDynHeader1);
1342 int indexDynHeader3 = content2.indexOf("End Dynamic Header", indexDynHeader2);
1343 Assert.assertNotSame(-1, indexDynHeader1);
1344 Assert.assertNotSame(-1, indexDynHeader2);
1345 Assert.assertNotSame(-1, indexDynHeader3);
1346
1347 Assert.assertTrue(content2.contains("This is section 1"));
1348
1349 endRequest();
1350 }
1351
1352
1353 @Test
1354 public void testComponentBindingVDL_1() throws Exception
1355 {
1356 startViewRequest("/componentBindingVDL_1.xhtml");
1357 processLifecycleExecuteAndRender();
1358
1359 UIComponent comp = facesContext.getViewRoot().findComponent("panel");
1360 Assert.assertNotNull(comp);
1361 Assert.assertEquals(2, comp.getChildCount());
1362
1363 UIComponent wrapper = comp.getChildren().get(1);
1364 Assert.assertNotNull(wrapper);
1365 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1366 UIComponent ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1367 Assert.assertNotNull(ccContent);
1368 Assert.assertEquals(3, ccContent.getChildCount());
1369 Assert.assertEquals("Dynamically added header",
1370 ccContent.getChildren().get(0).getFacet("header").getAttributes().get("value"));
1371 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1372 MockPrintWriter writer1 = (MockPrintWriter) response.getWriter();
1373 String content1 = new String(writer1.content());
1374 Assert.assertTrue(content1.contains("Dynamically added markup"));
1375
1376 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
1377 client.submit(button);
1378 processLifecycleExecute();
1379
1380 UIComponent comp2 = facesContext.getViewRoot().findComponent("panel");
1381 Assert.assertNotNull(comp2);
1382 Assert.assertEquals(2, comp2.getChildCount());
1383
1384 Assert.assertEquals("value1", comp2.getAttributes().get("attr1"));
1385 Assert.assertEquals("value2", comp2.getChildren().get(0).getAttributes().get("attr2"));
1386
1387 wrapper = comp2.getChildren().get(1);
1388 Assert.assertNotNull(wrapper);
1389 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1390 ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1391 Assert.assertNotNull(ccContent);
1392 Assert.assertEquals(3, ccContent.getChildCount());
1393 Assert.assertEquals("Dynamically added header",
1394 ccContent.getChildren().get(0).getFacet("header").getAttributes().get("value"));
1395 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1396
1397 renderResponse();
1398
1399 MockPrintWriter writer2 = (MockPrintWriter) response.getWriter();
1400 String content2 = new String(writer2.content());
1401 Assert.assertTrue(content2.contains("Dynamically added markup"));
1402
1403 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
1404 client.submit(button);
1405 processLifecycleExecuteAndRender();
1406
1407 UIComponent comp3 = facesContext.getViewRoot().findComponent("panel");
1408 Assert.assertNotNull(comp3);
1409 Assert.assertEquals(2, comp3.getChildCount());
1410
1411 Assert.assertEquals("value1", comp3.getAttributes().get("attr1"));
1412 Assert.assertEquals("value2", comp3.getChildren().get(0).getAttributes().get("attr2"));
1413
1414 wrapper = comp3.getChildren().get(1);
1415 Assert.assertNotNull(wrapper);
1416 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1417 ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1418 Assert.assertNotNull(ccContent);
1419 Assert.assertEquals(3, ccContent.getChildCount());
1420 Assert.assertEquals("Dynamically added header",
1421 ccContent.getChildren().get(0).getFacet("header").getAttributes().get("value"));
1422 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1423 MockPrintWriter writer3 = (MockPrintWriter) response.getWriter();
1424 String content3 = new String(writer3.content());
1425 Assert.assertTrue(content3.contains("Dynamically added markup"));
1426
1427 endRequest();
1428 }
1429
1430 @Test
1431 public void testComponentBindingVDL_2() throws Exception
1432 {
1433 startViewRequest("/componentBindingVDL_2.xhtml");
1434 processLifecycleExecuteAndRender();
1435
1436 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:panel");
1437 Assert.assertNotNull(comp);
1438 Assert.assertEquals(2, comp.getChildCount());
1439
1440 UIComponent wrapper = comp.getChildren().get(1);
1441 Assert.assertNotNull(wrapper);
1442 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1443 UIComponent ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1444 Assert.assertNotNull(ccContent);
1445 Assert.assertEquals(3, ccContent.getChildCount());
1446 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1447 MockPrintWriter writer1 = (MockPrintWriter) response.getWriter();
1448 String content1 = new String(writer1.content());
1449 Assert.assertTrue(content1.contains("Dynamically added header"));
1450 Assert.assertTrue(content1.contains("Dynamically added markup"));
1451
1452 UIComponent ccpanel = facesContext.getViewRoot().findComponent("mainForm:ccpanel");
1453 Assert.assertNotNull(ccpanel);
1454 UIComponent ccinnerpanel = facesContext.getViewRoot().findComponent("mainForm:ccpanel:component");
1455 Assert.assertNotNull(ccinnerpanel);
1456 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:ccpanel:component:increment");
1457 Assert.assertNotNull(button);
1458
1459 CheckActionEventBean checkBean = facesContext.getApplication().evaluateExpressionGet(facesContext,
1460 "#{checkActionEventBean}", CheckActionEventBean.class);
1461 int oldcount1 = checkBean.getActionListenerCount();
1462
1463 client.submit(button);
1464 processLifecycleExecute();
1465
1466 Assert.assertEquals("event not called", oldcount1+1, checkBean.getActionListenerCount());
1467 renderResponse();
1468
1469 Assert.assertNotNull(comp);
1470 Assert.assertEquals(2, comp.getChildCount());
1471
1472 comp = facesContext.getViewRoot().findComponent("mainForm:panel");
1473
1474 Assert.assertEquals("value1", comp.getAttributes().get("attr1"));
1475 Assert.assertEquals("value2", comp.getChildren().get(0).getAttributes().get("attr2"));
1476
1477 wrapper = comp.getChildren().get(1);
1478 Assert.assertNotNull(wrapper);
1479 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1480 ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1481 Assert.assertNotNull(ccContent);
1482 Assert.assertEquals(3, ccContent.getChildCount());
1483 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1484 MockPrintWriter writer2 = (MockPrintWriter) response.getWriter();
1485 String content2 = new String(writer2.content());
1486 Assert.assertTrue(content2.contains("Dynamically added header"));
1487 Assert.assertTrue(content2.contains("Dynamically added markup"));
1488
1489 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:ccpanel:component:increment");
1490 Assert.assertNotNull(button);
1491 int oldcount2 = checkBean.getActionListenerCount();
1492
1493 client.submit(button);
1494 processLifecycleExecute();
1495
1496 Assert.assertEquals("event not called", oldcount2+1, checkBean.getActionListenerCount());
1497
1498 renderResponse();
1499 Assert.assertNotNull(comp);
1500 Assert.assertEquals(2, comp.getChildCount());
1501
1502 comp = facesContext.getViewRoot().findComponent("mainForm:panel");
1503
1504 Assert.assertEquals("value1", comp.getAttributes().get("attr1"));
1505 Assert.assertEquals("value2", comp.getChildren().get(0).getAttributes().get("attr2"));
1506
1507 wrapper = comp.getChildren().get(1);
1508 Assert.assertNotNull(wrapper);
1509 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1510 ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1511 Assert.assertNotNull(ccContent);
1512 Assert.assertEquals(3, ccContent.getChildCount());
1513 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1514 MockPrintWriter writer3 = (MockPrintWriter) response.getWriter();
1515 String content3 = new String(writer3.content());
1516 Assert.assertTrue(content3.contains("Dynamically added header"));
1517 Assert.assertTrue(content3.contains("Dynamically added markup"));
1518
1519 endRequest();
1520 }
1521
1522 @Test
1523 public void testComponentBindingVDL_3() throws Exception
1524 {
1525 startViewRequest("/componentBindingVDL_3.xhtml");
1526 processLifecycleExecuteAndRender();
1527
1528 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:panel");
1529 Assert.assertNotNull(comp);
1530 Assert.assertEquals(2, comp.getChildCount());
1531
1532 UIComponent wrapper = comp.getChildren().get(1);
1533 Assert.assertNotNull(wrapper);
1534 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1535 UIComponent ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1536 Assert.assertNotNull(ccContent);
1537 Assert.assertEquals(3, ccContent.getChildCount());
1538
1539
1540 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1541 MockPrintWriter writer1 = (MockPrintWriter) response.getWriter();
1542 String content1 = new String(writer1.content());
1543 Assert.assertTrue(content1.contains("Dynamically added markup"));
1544 int indexDynHeader1_1 = content1.indexOf("Start Dynamic Header");
1545 int indexDynHeader1_2 = content1.indexOf("Dynamically added header", indexDynHeader1_1);
1546 int indexDynHeader1_3 = content1.indexOf("End Dynamic Header", indexDynHeader1_2);
1547 Assert.assertNotSame(-1, indexDynHeader1_1);
1548 Assert.assertNotSame(-1, indexDynHeader1_2);
1549 Assert.assertNotSame(-1, indexDynHeader1_3);
1550
1551 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
1552 client.submit(button);
1553 processLifecycleExecuteAndRender();
1554 Assert.assertNotNull(comp);
1555 Assert.assertEquals(2, comp.getChildCount());
1556
1557 comp = facesContext.getViewRoot().findComponent("mainForm:panel");
1558
1559 Assert.assertEquals("value1", comp.getAttributes().get("attr1"));
1560 Assert.assertEquals("value2", comp.getChildren().get(0).getAttributes().get("attr2"));
1561
1562 wrapper = comp.getChildren().get(1);
1563 Assert.assertNotNull(wrapper);
1564 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1565 ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1566 Assert.assertNotNull(ccContent);
1567 Assert.assertEquals(3, ccContent.getChildCount());
1568
1569
1570 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1571 MockPrintWriter writer2 = (MockPrintWriter) response.getWriter();
1572 String content2 = new String(writer2.content());
1573 Assert.assertTrue(content2.contains("Dynamically added markup"));
1574 int indexDynHeader2_1 = content2.indexOf("Start Dynamic Header");
1575 int indexDynHeader2_2 = content2.indexOf("Dynamically added header", indexDynHeader2_1);
1576 int indexDynHeader2_3 = content2.indexOf("End Dynamic Header", indexDynHeader2_2);
1577 Assert.assertNotSame(-1, indexDynHeader2_1);
1578 Assert.assertNotSame(-1, indexDynHeader2_2);
1579 Assert.assertNotSame(-1, indexDynHeader2_3);
1580
1581 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
1582 client.submit(button);
1583 processLifecycleExecuteAndRender();
1584 Assert.assertNotNull(comp);
1585 Assert.assertEquals(2, comp.getChildCount());
1586
1587 comp = facesContext.getViewRoot().findComponent("mainForm:panel");
1588
1589 Assert.assertEquals("value1", comp.getAttributes().get("attr1"));
1590 Assert.assertEquals("value2", comp.getChildren().get(0).getAttributes().get("attr2"));
1591
1592 wrapper = comp.getChildren().get(1);
1593 Assert.assertNotNull(wrapper);
1594 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1595 ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1596 Assert.assertNotNull(ccContent);
1597 Assert.assertEquals(3, ccContent.getChildCount());
1598
1599
1600 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1601 MockPrintWriter writer3 = (MockPrintWriter) response.getWriter();
1602 String content3 = new String(writer3.content());
1603 Assert.assertTrue(content3.contains("Dynamically added markup"));
1604 int indexDynHeader3_1 = content3.indexOf("Start Dynamic Header");
1605 int indexDynHeader3_2 = content3.indexOf("Dynamically added header", indexDynHeader3_1);
1606 int indexDynHeader3_3 = content3.indexOf("End Dynamic Header", indexDynHeader3_2);
1607 Assert.assertNotSame(-1, indexDynHeader3_1);
1608 Assert.assertNotSame(-1, indexDynHeader3_2);
1609 Assert.assertNotSame(-1, indexDynHeader3_3);
1610
1611 endRequest();
1612 }
1613
1614 @Test
1615 public void testComponentBindingVDL_4() throws Exception
1616 {
1617 startViewRequest("/componentBindingVDL_4.xhtml");
1618 processLifecycleExecuteAndRender();
1619
1620 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:panel");
1621 Assert.assertNotNull(comp);
1622 Assert.assertEquals(2, comp.getChildCount());
1623
1624 UIComponent wrapper = comp.getChildren().get(1);
1625 Assert.assertNotNull(wrapper);
1626 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1627 UIComponent ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1628 Assert.assertNotNull(ccContent);
1629 Assert.assertEquals(3, ccContent.getChildCount());
1630
1631
1632 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1633 MockPrintWriter writer1 = (MockPrintWriter) response.getWriter();
1634 String content1 = new String(writer1.content());
1635 Assert.assertTrue(content1.contains("Dynamically added markup"));
1636 int indexDynHeader1_1 = content1.indexOf("Start Dynamic Header");
1637 int indexDynHeader1_2 = content1.indexOf("Dynamically added header", indexDynHeader1_1);
1638 int indexDynHeader1_3 = content1.indexOf("End Dynamic Header", indexDynHeader1_2);
1639 Assert.assertNotSame(-1, indexDynHeader1_1);
1640 Assert.assertNotSame(-1, indexDynHeader1_2);
1641 Assert.assertNotSame(-1, indexDynHeader1_3);
1642
1643 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
1644 client.submit(button);
1645 processLifecycleExecuteAndRender();
1646 Assert.assertNotNull(comp);
1647 Assert.assertEquals(2, comp.getChildCount());
1648
1649 comp = facesContext.getViewRoot().findComponent("mainForm:panel");
1650
1651 Assert.assertEquals("value1", comp.getAttributes().get("attr1"));
1652 Assert.assertEquals("value2", comp.getChildren().get(0).getAttributes().get("attr2"));
1653
1654 wrapper = comp.getChildren().get(1);
1655 Assert.assertNotNull(wrapper);
1656 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1657 ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1658 Assert.assertNotNull(ccContent);
1659 Assert.assertEquals(3, ccContent.getChildCount());
1660
1661
1662 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1663 MockPrintWriter writer2 = (MockPrintWriter) response.getWriter();
1664 String content2 = new String(writer2.content());
1665 Assert.assertTrue(content2.contains("Dynamically added markup"));
1666 int indexDynHeader2_1 = content2.indexOf("Start Dynamic Header");
1667 int indexDynHeader2_2 = content2.indexOf("Dynamically added header", indexDynHeader2_1);
1668 int indexDynHeader2_3 = content2.indexOf("End Dynamic Header", indexDynHeader2_2);
1669 Assert.assertNotSame(-1, indexDynHeader2_1);
1670 Assert.assertNotSame(-1, indexDynHeader2_2);
1671 Assert.assertNotSame(-1, indexDynHeader2_3);
1672
1673 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
1674 client.submit(button);
1675 processLifecycleExecuteAndRender();
1676 Assert.assertNotNull(comp);
1677 Assert.assertEquals(2, comp.getChildCount());
1678
1679 comp = facesContext.getViewRoot().findComponent("mainForm:panel");
1680
1681 Assert.assertEquals("value1", comp.getAttributes().get("attr1"));
1682 Assert.assertEquals("value2", comp.getChildren().get(0).getAttributes().get("attr2"));
1683
1684 wrapper = comp.getChildren().get(1);
1685 Assert.assertNotNull(wrapper);
1686 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1687 ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1688 Assert.assertNotNull(ccContent);
1689 Assert.assertEquals(3, ccContent.getChildCount());
1690
1691
1692 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1693 MockPrintWriter writer3 = (MockPrintWriter) response.getWriter();
1694 String content3 = new String(writer3.content());
1695 Assert.assertTrue(content3.contains("Dynamically added markup"));
1696 int indexDynHeader3_1 = content3.indexOf("Start Dynamic Header");
1697 int indexDynHeader3_2 = content3.indexOf("Dynamically added header", indexDynHeader3_1);
1698 int indexDynHeader3_3 = content3.indexOf("End Dynamic Header", indexDynHeader3_2);
1699 Assert.assertNotSame(-1, indexDynHeader3_1);
1700 Assert.assertNotSame(-1, indexDynHeader3_2);
1701 Assert.assertNotSame(-1, indexDynHeader3_3);
1702
1703 endRequest();
1704 }
1705
1706 @Test
1707 public void testComponentBindingVDL_5() throws Exception
1708 {
1709 startViewRequest("/componentBindingVDL_5.xhtml");
1710 processLifecycleExecuteAndRender();
1711
1712 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:panel");
1713 Assert.assertNotNull(comp);
1714 Assert.assertEquals(2, comp.getChildCount());
1715
1716 UIComponent wrapper = comp.getChildren().get(1);
1717 Assert.assertNotNull(wrapper);
1718 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1719 UIComponent ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1720 Assert.assertNotNull(ccContent);
1721 Assert.assertEquals(3, ccContent.getChildCount());
1722 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1723 MockPrintWriter writer1 = (MockPrintWriter) response.getWriter();
1724 String content1 = new String(writer1.content());
1725 Assert.assertTrue(content1.contains("Dynamically added markup"));
1726 int indexDynHeader1_1 = content1.indexOf("Start Dynamic Header");
1727 int indexDynHeader1_2 = content1.indexOf("Dynamically added header", indexDynHeader1_1);
1728 int indexDynHeader1_3 = content1.indexOf("End Dynamic Header", indexDynHeader1_2);
1729 Assert.assertNotSame(-1, indexDynHeader1_1);
1730 Assert.assertNotSame(-1, indexDynHeader1_2);
1731 Assert.assertNotSame(-1, indexDynHeader1_3);
1732
1733 UIComponent ccpanel = facesContext.getViewRoot().findComponent("mainForm:ccpanel");
1734 Assert.assertNotNull(ccpanel);
1735 UIComponent ccinnerpanel = facesContext.getViewRoot().findComponent("mainForm:ccpanel:component");
1736 Assert.assertNotNull(ccinnerpanel);
1737 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:ccpanel:component:increment");
1738 Assert.assertNotNull(button);
1739
1740 CheckActionEventBean checkBean = facesContext.getApplication().evaluateExpressionGet(facesContext,
1741 "#{checkActionEventBean}", CheckActionEventBean.class);
1742 int oldcount1 = checkBean.getActionListenerCount();
1743
1744 client.submit(button);
1745 processLifecycleExecute();
1746
1747 Assert.assertEquals("event not called", oldcount1+1, checkBean.getActionListenerCount());
1748 renderResponse();
1749
1750 Assert.assertNotNull(comp);
1751 Assert.assertEquals(2, comp.getChildCount());
1752
1753 comp = facesContext.getViewRoot().findComponent("mainForm:panel");
1754
1755 Assert.assertEquals("value1", comp.getAttributes().get("attr1"));
1756 Assert.assertEquals("value2", comp.getChildren().get(0).getAttributes().get("attr2"));
1757
1758 wrapper = comp.getChildren().get(1);
1759 Assert.assertNotNull(wrapper);
1760 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1761 ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1762 Assert.assertNotNull(ccContent);
1763 Assert.assertEquals(3, ccContent.getChildCount());
1764 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1765 MockPrintWriter writer2 = (MockPrintWriter) response.getWriter();
1766 String content2 = new String(writer2.content());
1767 Assert.assertTrue(content2.contains("Dynamically added markup"));
1768 int indexDynHeader2_1 = content2.indexOf("Start Dynamic Header");
1769 int indexDynHeader2_2 = content2.indexOf("Dynamically added header", indexDynHeader2_1);
1770 int indexDynHeader2_3 = content2.indexOf("End Dynamic Header", indexDynHeader2_2);
1771 Assert.assertNotSame(-1, indexDynHeader2_1);
1772 Assert.assertNotSame(-1, indexDynHeader2_2);
1773 Assert.assertNotSame(-1, indexDynHeader2_3);
1774
1775 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:ccpanel:component:increment");
1776 Assert.assertNotNull(button);
1777 int oldcount2 = checkBean.getActionListenerCount();
1778
1779 client.submit(button);
1780 processLifecycleExecute();
1781
1782 Assert.assertEquals("event not called", oldcount2+1, checkBean.getActionListenerCount());
1783
1784 renderResponse();
1785 Assert.assertNotNull(comp);
1786 Assert.assertEquals(2, comp.getChildCount());
1787
1788 comp = facesContext.getViewRoot().findComponent("mainForm:panel");
1789
1790 Assert.assertEquals("value1", comp.getAttributes().get("attr1"));
1791 Assert.assertEquals("value2", comp.getChildren().get(0).getAttributes().get("attr2"));
1792
1793 wrapper = comp.getChildren().get(1);
1794 Assert.assertNotNull(wrapper);
1795 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1796 ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1797 Assert.assertNotNull(ccContent);
1798 Assert.assertEquals(3, ccContent.getChildCount());
1799 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1800 MockPrintWriter writer3 = (MockPrintWriter) response.getWriter();
1801 String content3 = new String(writer3.content());
1802 Assert.assertTrue(content3.contains("Dynamically added markup"));
1803 int indexDynHeader3_1 = content3.indexOf("Start Dynamic Header");
1804 int indexDynHeader3_2 = content3.indexOf("Dynamically added header", indexDynHeader3_1);
1805 int indexDynHeader3_3 = content3.indexOf("End Dynamic Header", indexDynHeader3_2);
1806 Assert.assertNotSame(-1, indexDynHeader3_1);
1807 Assert.assertNotSame(-1, indexDynHeader3_2);
1808 Assert.assertNotSame(-1, indexDynHeader3_3);
1809
1810 endRequest();
1811 }
1812
1813 @Test
1814 public void testComponentBindingVDL_6() throws Exception
1815 {
1816 startViewRequest("/componentBindingVDL_6.xhtml");
1817 processLifecycleExecuteAndRender();
1818
1819 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:panel");
1820 Assert.assertNotNull(comp);
1821 Assert.assertEquals(2, comp.getChildCount());
1822
1823 UIComponent wrapper = comp.getChildren().get(1);
1824 Assert.assertNotNull(wrapper);
1825 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1826 UIComponent ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1827 Assert.assertNotNull(ccContent);
1828 Assert.assertEquals(3, ccContent.getChildCount());
1829 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1830 MockPrintWriter writer1 = (MockPrintWriter) response.getWriter();
1831 String content1 = new String(writer1.content());
1832 Assert.assertTrue(content1.contains("Dynamically added markup"));
1833 int indexDynHeader1_1 = content1.indexOf("Start Dynamic Header");
1834 int indexDynHeader1_2 = content1.indexOf("Dynamically added header", indexDynHeader1_1);
1835 int indexDynHeader1_3 = content1.indexOf("End Dynamic Header", indexDynHeader1_2);
1836 Assert.assertNotSame(-1, indexDynHeader1_1);
1837 Assert.assertNotSame(-1, indexDynHeader1_2);
1838 Assert.assertNotSame(-1, indexDynHeader1_3);
1839
1840 UIComponent ccpanel = facesContext.getViewRoot().findComponent("mainForm:ccpanel");
1841 Assert.assertNotNull(ccpanel);
1842 UIComponent ccinnerpanel = facesContext.getViewRoot().findComponent("mainForm:ccpanel:component");
1843 Assert.assertNotNull(ccinnerpanel);
1844 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:ccpanel:component:increment");
1845 Assert.assertNotNull(button);
1846
1847 CheckActionEventBean checkBean = facesContext.getApplication().evaluateExpressionGet(facesContext,
1848 "#{checkActionEventBean}", CheckActionEventBean.class);
1849 int oldcount1 = checkBean.getActionListenerCount();
1850
1851 client.submit(button);
1852 processLifecycleExecute();
1853
1854 Assert.assertEquals("event not called", oldcount1+1, checkBean.getActionListenerCount());
1855 renderResponse();
1856
1857 Assert.assertNotNull(comp);
1858 Assert.assertEquals(2, comp.getChildCount());
1859
1860 comp = facesContext.getViewRoot().findComponent("mainForm:panel");
1861
1862 Assert.assertEquals("value1", comp.getAttributes().get("attr1"));
1863 Assert.assertEquals("value2", comp.getChildren().get(0).getAttributes().get("attr2"));
1864
1865 wrapper = comp.getChildren().get(1);
1866 Assert.assertNotNull(wrapper);
1867 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1868 ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1869 Assert.assertNotNull(ccContent);
1870 Assert.assertEquals(3, ccContent.getChildCount());
1871 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1872 MockPrintWriter writer2 = (MockPrintWriter) response.getWriter();
1873 String content2 = new String(writer2.content());
1874 Assert.assertTrue(content2.contains("Dynamically added markup"));
1875 int indexDynHeader2_1 = content2.indexOf("Start Dynamic Header");
1876 int indexDynHeader2_2 = content2.indexOf("Dynamically added header", indexDynHeader2_1);
1877 int indexDynHeader2_3 = content2.indexOf("End Dynamic Header", indexDynHeader2_2);
1878 Assert.assertNotSame(-1, indexDynHeader2_1);
1879 Assert.assertNotSame(-1, indexDynHeader2_2);
1880 Assert.assertNotSame(-1, indexDynHeader2_3);
1881
1882 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:ccpanel:component:increment");
1883 Assert.assertNotNull(button);
1884 int oldcount2 = checkBean.getActionListenerCount();
1885
1886 client.submit(button);
1887 processLifecycleExecute();
1888
1889 Assert.assertEquals("event not called", oldcount2+1, checkBean.getActionListenerCount());
1890
1891 renderResponse();
1892 Assert.assertNotNull(comp);
1893 Assert.assertEquals(2, comp.getChildCount());
1894
1895 comp = facesContext.getViewRoot().findComponent("mainForm:panel");
1896
1897 Assert.assertEquals("value1", comp.getAttributes().get("attr1"));
1898 Assert.assertEquals("value2", comp.getChildren().get(0).getAttributes().get("attr2"));
1899
1900 wrapper = comp.getChildren().get(1);
1901 Assert.assertNotNull(wrapper);
1902 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1903 ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1904 Assert.assertNotNull(ccContent);
1905 Assert.assertEquals(3, ccContent.getChildCount());
1906 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1907 MockPrintWriter writer3 = (MockPrintWriter) response.getWriter();
1908 String content3 = new String(writer3.content());
1909 Assert.assertTrue(content3.contains("Dynamically added markup"));
1910 int indexDynHeader3_1 = content3.indexOf("Start Dynamic Header");
1911 int indexDynHeader3_2 = content3.indexOf("Dynamically added header", indexDynHeader3_1);
1912 int indexDynHeader3_3 = content3.indexOf("End Dynamic Header", indexDynHeader3_2);
1913 Assert.assertNotSame(-1, indexDynHeader3_1);
1914 Assert.assertNotSame(-1, indexDynHeader3_2);
1915 Assert.assertNotSame(-1, indexDynHeader3_3);
1916
1917 endRequest();
1918 }
1919
1920 @Test
1921 public void testComponentBindingVDL_7() throws Exception
1922 {
1923 startViewRequest("/componentBindingVDL_7.xhtml");
1924 processLifecycleExecuteAndRender();
1925
1926 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:panel");
1927 Assert.assertNotNull(comp);
1928 Assert.assertEquals(2, comp.getChildCount());
1929
1930 UIComponent wrapper = comp.getChildren().get(1);
1931 Assert.assertNotNull(wrapper);
1932 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1933 UIComponent ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1934 Assert.assertNotNull(ccContent);
1935 Assert.assertEquals(3, ccContent.getChildCount());
1936
1937
1938 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1939 MockPrintWriter writer1 = (MockPrintWriter) response.getWriter();
1940 String content1 = new String(writer1.content());
1941 Assert.assertTrue(content1.contains("Dynamically added markup"));
1942 int indexDynHeader1_1 = content1.indexOf("Start Dynamic Header");
1943 int indexDynHeader1_2 = content1.indexOf("Dynamically added header", indexDynHeader1_1);
1944 int indexDynHeader1_3 = content1.indexOf("End Dynamic Header", indexDynHeader1_2);
1945 Assert.assertNotSame(-1, indexDynHeader1_1);
1946 Assert.assertNotSame(-1, indexDynHeader1_2);
1947 Assert.assertNotSame(-1, indexDynHeader1_3);
1948
1949 Assert.assertFalse(content1.contains("This is section 1"));
1950
1951 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
1952 client.submit(button);
1953 processLifecycleExecute();
1954
1955 CustomSessionBean sessionBean = facesContext.getApplication().evaluateExpressionGet(
1956 facesContext, "#{customSessionBean}", CustomSessionBean.class);
1957
1958
1959 sessionBean.setShowSection1(true);
1960
1961 renderResponse();
1962 Assert.assertNotNull(comp);
1963 Assert.assertEquals(2, comp.getChildCount());
1964
1965 comp = facesContext.getViewRoot().findComponent("mainForm:panel");
1966
1967 Assert.assertEquals("value1", comp.getAttributes().get("attr1"));
1968 Assert.assertEquals("value2", comp.getChildren().get(0).getAttributes().get("attr2"));
1969
1970 wrapper = comp.getChildren().get(1);
1971 Assert.assertNotNull(wrapper);
1972 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
1973 ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
1974 Assert.assertNotNull(ccContent);
1975 Assert.assertEquals(3, ccContent.getChildCount());
1976
1977
1978 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
1979 MockPrintWriter writer2 = (MockPrintWriter) response.getWriter();
1980 String content2 = new String(writer2.content());
1981 Assert.assertTrue(content2.contains("Dynamically added markup"));
1982 int indexDynHeader2_1 = content2.indexOf("Start Dynamic Header");
1983 int indexDynHeader2_2 = content2.indexOf("Dynamically added header", indexDynHeader2_1);
1984 int indexDynHeader2_3 = content2.indexOf("End Dynamic Header", indexDynHeader2_2);
1985 Assert.assertNotSame(-1, indexDynHeader2_1);
1986 Assert.assertNotSame(-1, indexDynHeader2_2);
1987 Assert.assertNotSame(-1, indexDynHeader2_3);
1988
1989 Assert.assertTrue(content2.contains("This is section 1"));
1990
1991 button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
1992 client.submit(button);
1993 processLifecycleExecute();
1994
1995 sessionBean.setShowSection1(false);
1996
1997 renderResponse();
1998 Assert.assertNotNull(comp);
1999 Assert.assertEquals(2, comp.getChildCount());
2000
2001 comp = facesContext.getViewRoot().findComponent("mainForm:panel");
2002
2003 Assert.assertEquals("value1", comp.getAttributes().get("attr1"));
2004 Assert.assertEquals("value2", comp.getChildren().get(0).getAttributes().get("attr2"));
2005
2006 wrapper = comp.getChildren().get(1);
2007 Assert.assertNotNull(wrapper);
2008 Assert.assertTrue(UIComponent.isCompositeComponent(wrapper));
2009 ccContent = wrapper.getFacet(UIComponent.COMPOSITE_FACET_NAME);
2010 Assert.assertNotNull(ccContent);
2011 Assert.assertEquals(3, ccContent.getChildCount());
2012
2013
2014 Assert.assertEquals("Dynamically added child", ccContent.getChildren().get(2).getAttributes().get("value"));
2015 MockPrintWriter writer3 = (MockPrintWriter) response.getWriter();
2016 String content3 = new String(writer3.content());
2017 Assert.assertTrue(content3.contains("Dynamically added markup"));
2018 int indexDynHeader3_1 = content3.indexOf("Start Dynamic Header");
2019 int indexDynHeader3_2 = content3.indexOf("Dynamically added header", indexDynHeader3_1);
2020 int indexDynHeader3_3 = content3.indexOf("End Dynamic Header", indexDynHeader3_2);
2021 Assert.assertNotSame(-1, indexDynHeader3_1);
2022 Assert.assertNotSame(-1, indexDynHeader3_2);
2023 Assert.assertNotSame(-1, indexDynHeader3_3);
2024
2025 Assert.assertFalse(content3.contains("This is section 1"));
2026
2027 endRequest();
2028 }
2029
2030 @Test
2031 public void testCForEach1() throws Exception
2032 {
2033 startViewRequest("/forEach1.xhtml");
2034 processLifecycleExecute();
2035
2036 executeBeforeRender(facesContext);
2037 executeBuildViewCycle(facesContext);
2038
2039 UIOutput itemA_1 = (UIOutput) facesContext.getViewRoot().findComponent("mainForm:item_a");
2040 Assert.assertNotNull(itemA_1);
2041 Assert.assertEquals("a", itemA_1.getValue());
2042 itemA_1.getAttributes().put("prop", "a");
2043 UIOutput itemB_1 = (UIOutput) facesContext.getViewRoot().findComponent("mainForm:item_b");
2044 Assert.assertNotNull(itemB_1);
2045 Assert.assertEquals("b", itemB_1.getValue());
2046 itemB_1.getAttributes().put("prop", "b");
2047 UIOutput itemC_1 = (UIOutput) facesContext.getViewRoot().findComponent("mainForm:item_c");
2048 Assert.assertNotNull(itemC_1);
2049 Assert.assertEquals("c", itemC_1.getValue());
2050 itemC_1.getAttributes().put("prop", "c");
2051
2052 executeViewHandlerRender(facesContext);
2053
2054 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
2055 client.submit(button);
2056
2057 processLifecycleExecute();
2058
2059 UIOutput itemA_2 = (UIOutput) facesContext.getViewRoot().findComponent("mainForm:item_a");
2060 Assert.assertNotNull(itemA_2);
2061 Assert.assertEquals("a", itemA_2.getValue());
2062 Assert.assertEquals("a", itemA_2.getAttributes().get("prop"));
2063 UIOutput itemB_2 = (UIOutput) facesContext.getViewRoot().findComponent("mainForm:item_b");
2064 Assert.assertNotNull(itemB_2);
2065 Assert.assertEquals("b", itemB_2.getValue());
2066 Assert.assertEquals("b", itemB_2.getAttributes().get("prop"));
2067 UIOutput itemC_2 = (UIOutput) facesContext.getViewRoot().findComponent("mainForm:item_c");
2068 Assert.assertNotNull(itemC_2);
2069 Assert.assertEquals("c", itemC_2.getValue());
2070 Assert.assertEquals("c", itemC_2.getAttributes().get("prop"));
2071
2072 ForEachBean bean = facesContext.getApplication().evaluateExpressionGet(facesContext, "#{forEachBean}",
2073 ForEachBean.class);
2074 bean.addFirst();
2075 bean.addMiddle();
2076 bean.removeLast();
2077
2078 executeBeforeRender(facesContext);
2079 executeBuildViewCycle(facesContext);
2080
2081 UIOutput itemA_3 = (UIOutput) facesContext.getViewRoot().findComponent("mainForm:item_a");
2082 Assert.assertNotNull(itemA_3);
2083 Assert.assertEquals("a", itemA_3.getValue());
2084 Assert.assertEquals("a", itemA_3.getAttributes().get("prop"));
2085 UIOutput itemB_3 = (UIOutput) facesContext.getViewRoot().findComponent("mainForm:item_b");
2086 Assert.assertNotNull(itemB_3);
2087 Assert.assertEquals("b", itemB_3.getValue());
2088 Assert.assertEquals("b", itemB_3.getAttributes().get("prop"));
2089 UIOutput itemC_3 = (UIOutput) facesContext.getViewRoot().findComponent("mainForm:item_c");
2090 Assert.assertNull(itemC_3);
2091 UIOutput itemZ_3 = (UIOutput) facesContext.getViewRoot().findComponent("mainForm:item_z");
2092 Assert.assertNotNull(itemZ_3);
2093 Assert.assertEquals("z", itemZ_3.getValue());
2094 Assert.assertNull(itemZ_3.getAttributes().get("prop"));
2095 UIOutput itemX_3 = (UIOutput) facesContext.getViewRoot().findComponent("mainForm:item_x");
2096 Assert.assertNotNull(itemX_3);
2097 Assert.assertEquals("x", itemX_3.getValue());
2098 Assert.assertNull(itemX_3.getAttributes().get("prop"));
2099
2100 executeViewHandlerRender(facesContext);
2101
2102 UICommand button2 = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
2103 client.submit(button2);
2104
2105 processLifecycleExecute();
2106
2107 UIOutput itemA_4 = (UIOutput) facesContext.getViewRoot().findComponent("mainForm:item_a");
2108 Assert.assertNotNull(itemA_4);
2109 Assert.assertEquals("a", itemA_4.getValue());
2110 UIOutput itemB_4 = (UIOutput) facesContext.getViewRoot().findComponent("mainForm:item_b");
2111 Assert.assertNotNull(itemB_4);
2112 Assert.assertEquals("b", itemB_4.getValue());
2113 UIOutput itemC_4 = (UIOutput) facesContext.getViewRoot().findComponent("mainForm:item_c");
2114 Assert.assertNull(itemC_4);
2115 UIOutput itemZ_4 = (UIOutput) facesContext.getViewRoot().findComponent("mainForm:item_z");
2116 Assert.assertNotNull(itemZ_4);
2117 Assert.assertEquals("z", itemZ_4.getValue());
2118 UIOutput itemX_4 = (UIOutput) facesContext.getViewRoot().findComponent("mainForm:item_x");
2119 Assert.assertNotNull(itemX_4);
2120 Assert.assertEquals("x", itemX_4.getValue());
2121
2122 endRequest();
2123 }
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134 @Test
2135 public void testSimpleComponent1() throws Exception
2136 {
2137 startViewRequest("/simpleComponent1.xhtml");
2138 processLifecycleExecuteAndRender();
2139
2140 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:component");
2141 Assert.assertNotNull(comp);
2142 Assert.assertTrue(comp instanceof UISimpleComponent1);
2143
2144
2145
2146 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
2147 client.submit(button);
2148 processLifecycleExecuteAndRender();
2149
2150 comp = facesContext.getViewRoot().findComponent("mainForm:component");
2151 Assert.assertNotNull(comp);
2152 Assert.assertTrue(comp instanceof UISimpleComponent1);
2153
2154 endRequest();
2155 }
2156
2157 @Test
2158 public void testSimpleComponent2() throws Exception
2159 {
2160 startViewRequest("/simpleComponent2.xhtml");
2161 processLifecycleExecuteAndRender();
2162
2163 UIComponent comp = facesContext.getViewRoot().findComponent("mainForm:component");
2164 Assert.assertNotNull(comp);
2165 Assert.assertTrue(comp instanceof UISimpleComponent2);
2166
2167
2168
2169 UICommand button = (UICommand) facesContext.getViewRoot().findComponent("mainForm:postback");
2170 client.submit(button);
2171 processLifecycleExecuteAndRender();
2172
2173 comp = facesContext.getViewRoot().findComponent("mainForm:component");
2174 Assert.assertNotNull(comp);
2175 Assert.assertTrue(comp instanceof UISimpleComponent2);
2176
2177 endRequest();
2178 }
2179
2180 @Test
2181 public void testUIRepeatCC1() throws Exception
2182 {
2183 startViewRequest("/nested_ui_repeat_1.xhtml");
2184 processLifecycleExecuteAndRender();
2185
2186 MockPrintWriter writer1 = (MockPrintWriter) response.getWriter();
2187 String content1 = new String(writer1.content());
2188 Assert.assertTrue(content1.contains("A-"));
2189 Assert.assertTrue(content1.contains("B-"));
2190 Assert.assertTrue(content1.contains("C-"));
2191
2192 this.client.ajax("mainForm:j_id_7:1:j_id_8:refresh", "action",
2193 "mainForm:j_id_7:1:j_id_8:refresh",
2194 "mainForm:j_id_7:1:j_id_8:compToUpdate", true);
2195
2196 processLifecycleExecuteAndRender();
2197
2198 MockPrintWriter writer2 = (MockPrintWriter) response.getWriter();
2199 String content2 = new String(writer2.content());
2200 Assert.assertTrue(content2.contains("mainForm:j_id_7:1:j_id_8:compToUpdate"));
2201 Assert.assertTrue(content2.contains("B-"));
2202
2203 endRequest();
2204 }
2205 }