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.tag.composite;
20
21 import javax.faces.component.UICommand;
22 import javax.faces.component.UIComponent;
23 import javax.faces.component.UINamingContainer;
24 import javax.faces.component.UIViewRoot;
25
26 import org.apache.myfaces.view.facelets.FaceletTestCase;
27 import org.apache.myfaces.view.facelets.bean.HelloWorld;
28 import org.junit.Assert;
29 import org.junit.Test;
30
31 public class CompositeComponentClientBehaviorTestCase extends FaceletTestCase
32 {
33 @Test
34 public void testSimpleClientBehavior() throws Exception
35 {
36 HelloWorld helloWorld = new HelloWorld();
37
38 facesContext.getExternalContext().getRequestMap().put("helloWorldBean",
39 helloWorld);
40
41 UIViewRoot root = facesContext.getViewRoot();
42 vdl.buildView(facesContext, root, "testSimpleClientBehavior.xhtml");
43
44 UIComponent form = root.findComponent("testForm1");
45 Assert.assertNotNull(form);
46 UINamingContainer compositeComponent = (UINamingContainer) form.getChildren().get(0);
47 Assert.assertNotNull(compositeComponent);
48 UICommand button = (UICommand) compositeComponent.findComponent("button");
49 Assert.assertNotNull(button);
50 Assert.assertNotNull(button.getClientBehaviors().get("action"));
51 Assert.assertEquals(1, button.getClientBehaviors().get("action").size());
52
53
54
55
56
57
58
59
60 }
61
62 @Test
63 public void testSimpleClientBehaviorDefault() throws Exception
64 {
65 HelloWorld helloWorld = new HelloWorld();
66
67 facesContext.getExternalContext().getRequestMap().put("helloWorldBean",
68 helloWorld);
69
70 UIViewRoot root = facesContext.getViewRoot();
71 vdl.buildView(facesContext, root, "testSimpleClientBehaviorDefault.xhtml");
72
73 UIComponent form = root.findComponent("testForm1");
74 Assert.assertNotNull(form);
75 UINamingContainer compositeComponent = (UINamingContainer) form.getChildren().get(0);
76 Assert.assertNotNull(compositeComponent);
77 UICommand button = (UICommand) compositeComponent.findComponent("button");
78 Assert.assertNotNull(button);
79 Assert.assertNotNull(button.getClientBehaviors().get("dblclick"));
80 Assert.assertEquals(1, button.getClientBehaviors().get("dblclick").size());
81
82
83
84
85
86
87
88
89 }
90
91 @Test
92 public void testSimpleClientBehaviorDefaultNoEvent() throws Exception
93 {
94 HelloWorld helloWorld = new HelloWorld();
95
96 facesContext.getExternalContext().getRequestMap().put("helloWorldBean",
97 helloWorld);
98
99 UIViewRoot root = facesContext.getViewRoot();
100 vdl.buildView(facesContext, root, "testSimpleClientBehaviorDefaultNoEvent.xhtml");
101
102 UIComponent form = root.findComponent("testForm1");
103 Assert.assertNotNull(form);
104 UINamingContainer compositeComponent = (UINamingContainer) form.getChildren().get(0);
105 Assert.assertNotNull(compositeComponent);
106 UICommand button = (UICommand) compositeComponent.findComponent("button");
107 Assert.assertNotNull(button);
108 Assert.assertNotNull(button.getClientBehaviors().get("action"));
109 Assert.assertEquals(1, button.getClientBehaviors().get("action").size());
110
111
112
113
114
115
116
117
118 }
119
120 @Test
121 public void testSimpleClientBehaviorAjaxWrap() throws Exception
122 {
123 HelloWorld helloWorld = new HelloWorld();
124
125 facesContext.getExternalContext().getRequestMap().put("helloWorldBean",
126 helloWorld);
127
128 UIViewRoot root = facesContext.getViewRoot();
129 vdl.buildView(facesContext, root, "testSimpleClientBehaviorAjaxWrap.xhtml");
130
131 UIComponent form = root.findComponent("testForm1");
132 Assert.assertNotNull(form);
133 UINamingContainer compositeComponent = (UINamingContainer) form.getChildren().get(0);
134 Assert.assertNotNull(compositeComponent);
135 UICommand button = (UICommand) compositeComponent.findComponent("button");
136 Assert.assertNotNull(button);
137 Assert.assertNotNull(button.getClientBehaviors().get("action"));
138 Assert.assertEquals(1, button.getClientBehaviors().get("action").size());
139
140
141
142
143
144
145
146
147 }
148
149 @Test
150 public void testSimpleClientBehaviorDefaultAjaxWrap() throws Exception
151 {
152 HelloWorld helloWorld = new HelloWorld();
153
154 facesContext.getExternalContext().getRequestMap().put("helloWorldBean",
155 helloWorld);
156
157 UIViewRoot root = facesContext.getViewRoot();
158 vdl.buildView(facesContext, root, "testSimpleClientBehaviorDefaultAjaxWrap.xhtml");
159
160 UIComponent form = root.findComponent("testForm1");
161 Assert.assertNotNull(form);
162 UINamingContainer compositeComponent = (UINamingContainer) form.getChildren().get(0);
163 Assert.assertNotNull(compositeComponent);
164 UICommand button = (UICommand) compositeComponent.findComponent("button");
165 Assert.assertNotNull(button);
166 Assert.assertNotNull(button.getClientBehaviors().get("dblclick"));
167 Assert.assertEquals(1, button.getClientBehaviors().get("dblclick").size());
168
169
170
171
172
173
174
175
176 }
177
178 @Test
179 public void testSimpleClientBehaviorDefaultNoEventAjaxWrap() throws Exception
180 {
181 HelloWorld helloWorld = new HelloWorld();
182
183 facesContext.getExternalContext().getRequestMap().put("helloWorldBean",
184 helloWorld);
185
186 UIViewRoot root = facesContext.getViewRoot();
187 vdl.buildView(facesContext, root, "testSimpleClientBehaviorDefaultNoEventAjaxWrap.xhtml");
188
189 UIComponent form = root.findComponent("testForm1");
190 Assert.assertNotNull(form);
191 UINamingContainer compositeComponent = (UINamingContainer) form.getChildren().get(0);
192 Assert.assertNotNull(compositeComponent);
193 UICommand button = (UICommand) compositeComponent.findComponent("button");
194 Assert.assertNotNull(button);
195 Assert.assertNotNull(button.getClientBehaviors().get("action"));
196 Assert.assertEquals(1, button.getClientBehaviors().get("action").size());
197
198
199
200
201
202
203
204
205 }
206
207 @Test
208 public void testCompositeClientBehavior() throws Exception
209 {
210 HelloWorld helloWorld = new HelloWorld();
211
212 facesContext.getExternalContext().getRequestMap().put("helloWorldBean",
213 helloWorld);
214
215 UIViewRoot root = facesContext.getViewRoot();
216 vdl.buildView(facesContext, root, "testCompositeClientBehavior.xhtml");
217
218 UIComponent form = root.findComponent("testForm1");
219 Assert.assertNotNull(form);
220 UINamingContainer compositeComponent = (UINamingContainer) form.getChildren().get(0);
221 Assert.assertNotNull(compositeComponent);
222 UINamingContainer compositeComponent2 = (UINamingContainer) compositeComponent.findComponent("button3");
223 Assert.assertNotNull(compositeComponent2);
224 UICommand button = (UICommand) compositeComponent2.findComponent("button");
225 Assert.assertNotNull(button);
226
227
228 Assert.assertNotNull(button.getClientBehaviors().get("action"));
229 Assert.assertEquals(1, button.getClientBehaviors().get("action").size());
230
231
232
233
234
235
236
237
238 }
239
240 @Test
241 public void testCompositeDoubleClientBehavior() throws Exception
242 {
243 HelloWorld helloWorld = new HelloWorld();
244
245 facesContext.getExternalContext().getRequestMap().put("helloWorldBean",
246 helloWorld);
247
248 UIViewRoot root = facesContext.getViewRoot();
249 vdl.buildView(facesContext, root, "testCompositeDoubleClientBehavior.xhtml");
250
251 UIComponent form = root.findComponent("testForm1");
252 Assert.assertNotNull(form);
253 UINamingContainer compositeComponent = (UINamingContainer) form.getChildren().get(0);
254 Assert.assertNotNull(compositeComponent);
255 UINamingContainer compositeComponent2 = (UINamingContainer) compositeComponent.findComponent("compositeClientBehavior");
256 Assert.assertNotNull(compositeComponent2);
257 UINamingContainer compositeComponent3 = (UINamingContainer) compositeComponent2.findComponent("button3");
258 Assert.assertNotNull(compositeComponent3);
259 UICommand button = (UICommand) compositeComponent3.findComponent("button");
260 Assert.assertNotNull(button);
261
262
263 Assert.assertNotNull(button.getClientBehaviors().get("action"));
264 Assert.assertEquals(1, button.getClientBehaviors().get("action").size());
265
266
267
268
269
270
271
272
273 }
274 }