1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.view.facelets.tag.composite;
21
22 import javax.el.ExpressionFactory;
23 import javax.faces.component.UICommand;
24 import javax.faces.component.UIComponent;
25 import javax.faces.component.UINamingContainer;
26 import javax.faces.component.UIViewRoot;
27
28 import org.apache.myfaces.config.RuntimeConfig;
29 import org.apache.myfaces.test.mock.MockExternalContext;
30 import org.apache.myfaces.view.facelets.FaceletTestCase;
31 import org.apache.myfaces.view.facelets.bean.HelloWorld;
32 import org.junit.Assert;
33 import org.junit.Test;
34
35 public class CompositeComponentConditionalButtonTestCase extends FaceletTestCase
36 {
37
38 @Override
39 protected void setupComponents() throws Exception
40 {
41 super.setupComponents();
42 }
43
44 @Override
45 protected ExpressionFactory createExpressionFactory()
46 {
47 return new org.apache.el.ExpressionFactoryImpl();
48 }
49
50 @Test
51 public void testConditionalButtonTargets() throws Exception
52 {
53 HelloWorld helloWorld = new HelloWorld();
54
55 facesContext.getExternalContext().getRequestMap().put("helloWorldBean",
56 helloWorld);
57
58 UIViewRoot root = facesContext.getViewRoot();
59 vdl.buildView(facesContext, root, "testConditionalButtonTargets.xhtml");
60
61
62 UIComponent form = root.findComponent("testForm1");
63 Assert.assertNotNull(form);
64 UINamingContainer compositeComponent1 = (UINamingContainer) form.findComponent("actionSource1");
65 Assert.assertNotNull(compositeComponent1);
66 UICommand button1 = (UICommand) compositeComponent1.findComponent("button");
67 Assert.assertNotNull(button1);
68 Assert.assertEquals("submit", button1.getActionExpression().invoke(facesContext.getELContext(), null));
69
70 Assert.assertNotNull(button1.getActionListeners());
71 Assert.assertEquals(1, button1.getActionListeners().length);
72
73 UINamingContainer compositeComponent2 = (UINamingContainer) form.findComponent("actionSource2");
74 Assert.assertNotNull(compositeComponent2);
75 UICommand button2 = (UICommand) compositeComponent2.findComponent("button");
76 Assert.assertNotNull(button2);
77
78 Assert.assertEquals("fail", button2.getActionExpression().invoke(facesContext.getELContext(), null));
79
80 Assert.assertNotNull(button2.getActionListeners());
81 Assert.assertEquals(0, button2.getActionListeners().length);
82
83
84
85
86
87
88
89
90 }
91 }