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