1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 }