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