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  package javax.faces.component;
20  
21  import java.lang.reflect.Method;
22  import java.util.ArrayList;
23  import java.util.Collection;
24  import java.util.Collections;
25  import java.util.List;
26  import java.util.Map;
27  
28  import javax.faces.context.FacesContext;
29  
30  import org.apache.myfaces.Assert;
31  import org.apache.myfaces.TestRunner;
32  import org.apache.myfaces.test.base.junit4.AbstractJsfTestCase;
33  import org.easymock.classextension.EasyMock;
34  import org.easymock.classextension.IMocksControl;
35  import org.junit.Test;
36  
37  /**
38       * Tests for {@link UIComponent#encodeAll(javax.faces.context.FacesContext)}.
39   */
40  public class UIComponentEncodeAllTest extends AbstractJsfTestCase
41  {
42      protected IMocksControl _mocksControl;
43      private UIComponent _testimpl;
44  
45      //@Override
46      //@BeforeMethod(alwaysRun = true)
47      public void setUp() throws Exception
48      {
49          super.setUp();
50          _mocksControl = EasyMock.createNiceControl();
51          //_facesContext = _mocksControl.createMock(FacesContext.class);
52          Collection<Method> mockedMethods = new ArrayList<Method>();
53          Class<UIComponent> clazz = UIComponent.class;
54          mockedMethods.add(clazz.getDeclaredMethod("pushComponentToEL", new Class[] { FacesContext.class, UIComponent.class }));
55          mockedMethods.add(clazz.getDeclaredMethod("isRendered", (Class<?>[])null));
56          mockedMethods.add(clazz.getDeclaredMethod("popComponentFromEL", new Class[] { FacesContext.class }));
57          mockedMethods.add(clazz.getDeclaredMethod("encodeBegin", new Class[] { FacesContext.class }));
58          mockedMethods.add(clazz.getDeclaredMethod("getRendersChildren", (Class<?>[])null));
59          mockedMethods.add(clazz.getDeclaredMethod("encodeChildren", new Class[] { FacesContext.class }));
60          mockedMethods.add(clazz.getDeclaredMethod("getChildren", (Class<?>[])null));
61          mockedMethods.add(clazz.getDeclaredMethod("getChildCount", (Class<?>[])null));
62          mockedMethods.add(clazz.getDeclaredMethod("encodeEnd", new Class[] { FacesContext.class }));
63  
64          _testimpl = _mocksControl.createMock(clazz, mockedMethods.toArray(new Method[mockedMethods.size()]));
65          _mocksControl.checkOrder(true);
66      }
67  
68      @Test
69      public void testEncodeAllNullContext() throws Exception
70      {
71          Assert.assertException(NullPointerException.class, new TestRunner()
72          {
73              public void run() throws Throwable
74              {
75                  _testimpl.encodeAll(null);
76              }
77          });
78      }
79  
80      @Test
81      public void testEncodeAllNotRendered() throws Exception
82      {
83          /*TODO: implement me
84          EasyMock.expect(_testimpl.isRendered()).andReturn(false);
85          _mocksControl.replay();
86          _testimpl.encodeAll(facesContext);
87          _mocksControl.verify();
88          */
89      }
90  
91      @Test
92      public void testEncodeAllRenderesChildren() throws Exception
93      {
94          /*TODO: implement me
95          EasyMock.expect(_testimpl.isRendered()).andReturn(true);
96          _testimpl.encodeBegin(EasyMock.same(facesContext));
97          EasyMock.expect(_testimpl.getRendersChildren()).andReturn(true);
98          _testimpl.encodeChildren(EasyMock.same(facesContext));
99          _testimpl.encodeEnd(EasyMock.same(facesContext));
100         _mocksControl.replay();
101         _testimpl.encodeAll(facesContext);
102         _mocksControl.verify();
103         */
104     }
105 
106     @Test
107     public void testEncodeAllNotRenderesChildren() throws Exception
108     {
109         /*TODO: implement me
110         EasyMock.expect(_testimpl.isRendered()).andReturn(true);
111         _testimpl.encodeBegin(EasyMock.same(facesContext));
112         EasyMock.expect(_testimpl.getRendersChildren()).andReturn(false);
113 
114         List<UIComponent> childs = new ArrayList<UIComponent>();
115         UIComponent testChild = _mocksControl.createMock(UIComponent.class);
116         childs.add(testChild);
117         EasyMock.expect(_testimpl.getChildCount()).andReturn(childs.size());        
118         EasyMock.expect(_testimpl.getChildren()).andReturn(childs);
119         testChild.encodeAll(EasyMock.same(facesContext));
120 
121         _testimpl.encodeEnd(EasyMock.same(facesContext));
122         _mocksControl.replay();
123         _testimpl.encodeAll(facesContext);
124         _mocksControl.verify();
125         */
126     }
127 }