1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package javax.faces.component;
21
22 import javax.faces.el.ValueBinding;
23
24 import junit.framework.Test;
25 import junit.framework.TestSuite;
26
27 import org.apache.shale.test.base.AbstractJsfTestCase;
28 import org.apache.shale.test.mock.MockRenderKitFactory;
29 import org.apache.shale.test.mock.MockValueBinding;
30
31 public class UIComponentBaseTest extends AbstractJsfTestCase {
32 private UIComponentBase mock = null;
33
34 public static void main(String[] args) {
35 junit.textui.TestRunner.run(UIComponentBaseTest.class);
36 }
37
38 public UIComponentBaseTest(String name) {
39 super(name);
40 }
41
42 public static Test suite() {
43 TestSuite suite = new TestSuite();
44 suite.addTestSuite(UIComponentBaseTest.class);
45 return suite;
46 }
47
48 public void setUp() {
49 super.setUp();
50
51 facesContext.getViewRoot().setRenderKitId(MockRenderKitFactory.HTML_BASIC_RENDER_KIT);
52 mock = new UIComponentMock();
53 }
54
55 public void tearDown() {
56 super.tearDown();
57 mock = null;
58 }
59
60
61
62
63 public void testIsRendered() {
64
65 assertTrue(mock.isRendered());
66 }
67
68 public void testIsRenderedValueSet() {
69 mock.setRendered(true);
70 assertTrue(mock.isRendered());
71 mock.setRendered(false);
72 assertFalse(mock.isRendered());
73 }
74
75 public void testIsRenderedBinding() {
76
77 ValueBinding vb = new MockValueBinding(application,
78 "#{requestScope.foo}");
79 externalContext.getRequestMap().put("foo", new Boolean(false));
80
81 mock.setValueBinding("rendered", vb);
82 assertFalse(mock.isRendered());
83 }
84
85
86
87
88 public void testGetRendersChildren() {
89
90 }
91
92
93
94
95 public void testGetChildCount() {
96
97 }
98
99
100
101
102 public void testUIComponentBase() {
103
104 }
105
106
107
108
109 public void testGetAttributes() {
110
111 }
112
113
114
115
116 public void testGetValueBindingString() {
117
118 }
119
120
121
122
123 public void testSetValueBindingStringValueBinding() {
124
125 }
126
127
128
129
130 public void testGetClientIdFacesContext() {
131
132 UIInput input = createInputInTree();
133
134 String str = input.getClientId(facesContext);
135
136 assertEquals(str, "data:input99");
137
138 UIData uiData = (UIData) input.getParent().getParent();
139
140 uiData.setRowIndex(1);
141
142 str = input.getClientId(facesContext);
143 }
144
145 private UIInput createInputInTree() {
146 UIViewRoot viewRoot = facesContext.getViewRoot();
147
148 UIData uiData = new UIData();
149 uiData.setId("data");
150
151 UIColumn column = new UIColumn();
152
153 uiData.getChildren().add(column);
154
155 UIInput input = null;
156
157 for(int i=0; i<100; i++) {
158 input = new UIInput();
159 input.setId("input"+i);
160 column.getChildren().add(input);
161 }
162
163 viewRoot.getChildren().add(uiData);
164
165 return input;
166 }
167
168
169
170
171 public void testGetId() {
172
173 }
174
175
176
177
178 public void testSetIdString() {
179
180 }
181
182
183
184
185 public void testGetParent() {
186
187 }
188
189
190
191
192 public void testSetParentUIComponent() {
193
194 }
195
196
197
198
199 public void testGetChildren() {
200
201 }
202
203
204
205
206 public void testFindComponentString() {
207
208 UIInput input = createInputInTree();
209
210 for(int j=0; j<100; j++) {
211 UIComponent comp = input.findComponent(":data:input"+j);
212 assertEquals("input-ids are not equal","input"+j, comp.getId());
213 comp = input.findComponent("input"+j);
214 assertEquals("input-ids are not equal","input"+j, comp.getId());
215 }
216 }
217
218
219
220
221 public void testGetFacets() {
222
223 }
224
225
226
227
228 public void testGetFacetString() {
229
230 }
231
232
233
234
235 public void testGetFacetsAndChildren() {
236
237 }
238
239
240
241
242 public void testBroadcastFacesEvent() {
243
244 }
245
246
247
248
249 public void testDecodeFacesContext() {
250
251 }
252
253
254
255
256 public void testEncodeBeginFacesContext() {
257
258 }
259
260
261
262
263 public void testEncodeChildrenFacesContext() {
264
265 }
266
267
268
269
270 public void testEncodeEndFacesContext() {
271
272 }
273
274
275
276
277 public void testAddFacesListenerFacesListener() {
278
279 }
280
281
282
283
284 public void testGetFacesListenersClass() {
285
286 }
287
288
289
290
291 public void testRemoveFacesListenerFacesListener() {
292
293 }
294
295
296
297
298 public void testQueueEventFacesEvent() {
299
300 }
301
302
303
304
305 public void testProcessDecodesFacesContext() {
306
307 }
308
309
310
311
312 public void testProcessValidatorsFacesContext() {
313
314 }
315
316
317
318
319 public void testProcessUpdatesFacesContext() {
320
321 }
322
323
324
325
326 public void testProcessSaveStateFacesContext() {
327
328 }
329
330
331
332
333 public void testProcessRestoreStateFacesContextObject() {
334
335 }
336
337
338
339
340 public void testGetFacesContext() {
341
342 }
343
344
345
346
347 public void testGetRendererFacesContext() {
348
349 }
350
351
352
353
354 public void testGetPathToComponent() {
355
356 }
357
358
359
360
361 public void testIsTransient() {
362
363 }
364
365
366
367
368 public void testSetTransient() {
369
370 }
371
372
373
374
375 public void testSaveAttachedState() {
376
377 }
378
379
380
381
382 public void testRestoreAttachedState() {
383
384 }
385
386 public void testSaveState() throws Exception {
387
388 try {
389 String id = "id";
390 String rendererType = "Whumpy";
391 mock.setId(id);
392 mock.setRendered(true);
393 mock.setRendererType(rendererType);
394 Object value[] = (Object[]) mock.saveState(facesContext);
395 assertEquals(id, value[0]);
396 assertEquals(Boolean.TRUE, value[1]);
397 assertEquals(rendererType, value[2]);
398
399 assertNull(value[3]);
400 assertNull(value[4]);
401 assertNull(value[5]);
402 assertNull(value[6]);
403 } catch (NullPointerException e) {
404 fail("Should not throw an exception");
405 }
406 }
407
408
409
410
411 public void testRestoreState() {
412
413 }
414
415
416
417
418 public void testSetRendererType() {
419 assertNull(mock.getRendererType());
420 }
421
422 public void testSetRendererTypeStringValue() {
423 String rendererType = "BlueBlorf";
424 mock.setRendererType(rendererType);
425 assertEquals(mock.getRendererType(), rendererType);
426 }
427
428 public void testSetRendererTypeStringBinding() {
429
430 String whumpy = "Whumpy";
431
432 ValueBinding vb = new MockValueBinding(application,
433 "#{requestScope.foo}");
434 externalContext.getRequestMap().put("foo", whumpy);
435
436 mock.setValueBinding("rendererType", vb);
437 assertEquals(mock.getRendererType(), whumpy);
438
439 }
440
441 }