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 org.apache.myfaces.renderkit.html.ext;
20  
21  import javax.faces.component.UIColumn;
22  
23  import junit.framework.Test;
24  import junit.framework.TestSuite;
25  
26  import org.apache.myfaces.component.html.ext.HtmlOutputText;
27  import org.apache.myfaces.component.html.ext.HtmlPanelGrid;
28  import org.apache.myfaces.test.AbstractTomahawkViewControllerTestCase;
29  import org.apache.myfaces.test.utils.HtmlCheckAttributesUtil;
30  import org.apache.myfaces.test.utils.HtmlRenderedAttr;
31  import org.apache.shale.test.mock.MockResponseWriter;
32  
33  public class HtmlGridRendererTest extends AbstractTomahawkViewControllerTestCase
34  {
35      private MockResponseWriter writer ;
36      private HtmlPanelGrid panelGrid;
37      private HtmlOutputText colText;
38  
39      public HtmlGridRendererTest(String name)
40      {
41          super(name);
42      }
43      
44      public static Test suite() {
45          return new TestSuite(HtmlGridRendererTest.class);
46      }
47  
48      public void setUp() throws Exception
49      {
50          super.setUp();
51          panelGrid = new HtmlPanelGrid();
52          colText = new HtmlOutputText();
53          writer = (MockResponseWriter)facesContext.getResponseWriter();
54      }
55  
56      public void tearDown() throws Exception
57      {
58          super.tearDown();
59          panelGrid = null;
60          colText = null;
61          writer = null;
62      }
63  
64      public void testRenderTable() throws Exception
65      {
66          UIColumn col1 = new UIColumn();
67          HtmlOutputText col1Text = new HtmlOutputText();
68          col1Text.setValue("col1Text");
69  
70          UIColumn col2 = new UIColumn();
71          HtmlOutputText col2Text = new HtmlOutputText();
72          col2Text.setValue("col2Text");
73  
74          col1.getChildren().add(col1Text);
75          col2.getChildren().add(col2Text);
76          panelGrid.getChildren().add(col1);
77          panelGrid.getChildren().add(col2);
78  
79          panelGrid.encodeBegin(facesContext);
80          panelGrid.encodeChildren(facesContext);
81          panelGrid.encodeEnd(facesContext);
82          facesContext.renderResponse();
83  
84          String output = writer.getWriter().toString();
85          
86          assertEquals("<table><tbody><tr><td>col1Text</td></tr><tr><td>col2Text</td></tr></tbody></table>", output);
87      }
88  
89      public void testHtmlPropertyPassTru() throws Exception 
90      { 
91          HtmlRenderedAttr[] attrs = HtmlCheckAttributesUtil.generateBasicReadOnlyAttrs();
92  
93          HtmlCheckAttributesUtil.checkRenderedAttributes(
94                  panelGrid, facesContext, writer, attrs);
95          if(HtmlCheckAttributesUtil.hasFailedAttrRender(attrs)) 
96          {
97              fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
98          }
99      }
100     
101     public void testHtmlPropertyPassTruNotRendered() throws Exception
102     {
103         HtmlRenderedAttr[] attrs = HtmlCheckAttributesUtil.generateAttrsNotRenderedForReadOnly();
104 
105         HtmlCheckAttributesUtil.checkRenderedAttributes(
106                 panelGrid, facesContext, writer, attrs);
107         if(HtmlCheckAttributesUtil.hasFailedAttrRender(attrs)) 
108         {
109             fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
110         }
111     }
112 }