View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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          // TODO remove this line once shale-test goes alpha, see MYFACES-1155
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       * Test method for 'javax.faces.component.UIComponentBase.isRendered()'
62       */
63      public void testIsRendered() {
64          // defaults to true
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       * Test method for 'javax.faces.component.UIComponentBase.getRendersChildren()'
87       */
88      public void testGetRendersChildren() {
89  
90      }
91  
92      /*
93       * Test method for 'javax.faces.component.UIComponentBase.getChildCount()'
94       */
95      public void testGetChildCount() {
96  
97      }
98  
99      /*
100      * Test method for 'javax.faces.component.UIComponentBase.UIComponentBase()'
101      */
102     public void testUIComponentBase() {
103 
104     }
105 
106     /*
107      * Test method for 'javax.faces.component.UIComponentBase.getAttributes()'
108      */
109     public void testGetAttributes() {
110 
111     }
112 
113     /*
114      * Test method for 'javax.faces.component.UIComponentBase.getValueBinding(String)'
115      */
116     public void testGetValueBindingString() {
117 
118     }
119 
120     /*
121      * Test method for 'javax.faces.component.UIComponentBase.setValueBinding(String, ValueBinding)'
122      */
123     public void testSetValueBindingStringValueBinding() {
124 
125     }
126 
127     /*
128      * Test method for 'javax.faces.component.UIComponentBase.getClientId(FacesContext)'
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      * Test method for 'javax.faces.component.UIComponentBase.getId()'
170      */
171     public void testGetId() {
172 
173     }
174 
175     /*
176      * Test method for 'javax.faces.component.UIComponentBase.setId(String)'
177      */
178     public void testSetIdString() {
179 
180     }
181 
182     /*
183      * Test method for 'javax.faces.component.UIComponentBase.getParent()'
184      */
185     public void testGetParent() {
186 
187     }
188 
189     /*
190      * Test method for 'javax.faces.component.UIComponentBase.setParent(UIComponent)'
191      */
192     public void testSetParentUIComponent() {
193 
194     }
195 
196     /*
197      * Test method for 'javax.faces.component.UIComponentBase.getChildren()'
198      */
199     public void testGetChildren() {
200 
201     }
202 
203     /*
204      * Test method for 'javax.faces.component.UIComponentBase.findComponent(String)'
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      * Test method for 'javax.faces.component.UIComponentBase.getFacets()'
220      */
221     public void testGetFacets() {
222 
223     }
224 
225     /*
226      * Test method for 'javax.faces.component.UIComponentBase.getFacet(String)'
227      */
228     public void testGetFacetString() {
229 
230     }
231 
232     /*
233      * Test method for 'javax.faces.component.UIComponentBase.getFacetsAndChildren()'
234      */
235     public void testGetFacetsAndChildren() {
236 
237     }
238 
239     /*
240      * Test method for 'javax.faces.component.UIComponentBase.broadcast(FacesEvent)'
241      */
242     public void testBroadcastFacesEvent() {
243 
244     }
245 
246     /*
247      * Test method for 'javax.faces.component.UIComponentBase.decode(FacesContext)'
248      */
249     public void testDecodeFacesContext() {
250 
251     }
252 
253     /*
254      * Test method for 'javax.faces.component.UIComponentBase.encodeBegin(FacesContext)'
255      */
256     public void testEncodeBeginFacesContext() {
257 
258     }
259 
260     /*
261      * Test method for 'javax.faces.component.UIComponentBase.encodeChildren(FacesContext)'
262      */
263     public void testEncodeChildrenFacesContext() {
264 
265     }
266 
267     /*
268      * Test method for 'javax.faces.component.UIComponentBase.encodeEnd(FacesContext)'
269      */
270     public void testEncodeEndFacesContext() {
271 
272     }
273 
274     /*
275      * Test method for 'javax.faces.component.UIComponentBase.addFacesListener(FacesListener)'
276      */
277     public void testAddFacesListenerFacesListener() {
278 
279     }
280 
281     /*
282      * Test method for 'javax.faces.component.UIComponentBase.getFacesListeners(Class)'
283      */
284     public void testGetFacesListenersClass() {
285 
286     }
287 
288     /*
289      * Test method for 'javax.faces.component.UIComponentBase.removeFacesListener(FacesListener)'
290      */
291     public void testRemoveFacesListenerFacesListener() {
292 
293     }
294 
295     /*
296      * Test method for 'javax.faces.component.UIComponentBase.queueEvent(FacesEvent)'
297      */
298     public void testQueueEventFacesEvent() {
299 
300     }
301 
302     /*
303      * Test method for 'javax.faces.component.UIComponentBase.processDecodes(FacesContext)'
304      */
305     public void testProcessDecodesFacesContext() {
306 
307     }
308 
309     /*
310      * Test method for 'javax.faces.component.UIComponentBase.processValidators(FacesContext)'
311      */
312     public void testProcessValidatorsFacesContext() {
313 
314     }
315 
316     /*
317      * Test method for 'javax.faces.component.UIComponentBase.processUpdates(FacesContext)'
318      */
319     public void testProcessUpdatesFacesContext() {
320 
321     }
322 
323     /*
324      * Test method for 'javax.faces.component.UIComponentBase.processSaveState(FacesContext)'
325      */
326     public void testProcessSaveStateFacesContext() {
327 
328     }
329 
330     /*
331      * Test method for 'javax.faces.component.UIComponentBase.processRestoreState(FacesContext, Object)'
332      */
333     public void testProcessRestoreStateFacesContextObject() {
334 
335     }
336 
337     /*
338      * Test method for 'javax.faces.component.UIComponentBase.getFacesContext()'
339      */
340     public void testGetFacesContext() {
341 
342     }
343 
344     /*
345      * Test method for 'javax.faces.component.UIComponentBase.getRenderer(FacesContext)'
346      */
347     public void testGetRendererFacesContext() {
348 
349     }
350 
351     /*
352      * Test method for 'javax.faces.component.UIComponentBase.getPathToComponent(UIComponent)'
353      */
354     public void testGetPathToComponent() {
355 
356     }
357 
358     /*
359      * Test method for 'javax.faces.component.UIComponentBase.isTransient()'
360      */
361     public void testIsTransient() {
362 
363     }
364 
365     /*
366      * Test method for 'javax.faces.component.UIComponentBase.setTransient(boolean)'
367      */
368     public void testSetTransient() {
369 
370     }
371 
372     /*
373      * Test method for 'javax.faces.component.UIComponentBase.saveAttachedState(FacesContext, Object)'
374      */
375     public void testSaveAttachedState() {
376 
377     }
378 
379     /*
380      * Test method for 'javax.faces.component.UIComponentBase.restoreAttachedState(FacesContext, Object)'
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      * Test method for 'javax.faces.component.UIComponentBase.restoreState(FacesContext, Object)'
410      */
411     public void testRestoreState() {
412 
413     }
414 
415     /*
416      * Test method for 'javax.faces.component.UIComponentBase.setRendererType(String)'
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 }