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;
20
21 import java.io.StringWriter;
22
23 import javax.faces.component.UIParameter;
24 import javax.faces.component.html.HtmlOutputFormat;
25
26 import junit.framework.Test;
27 import junit.framework.TestSuite;
28
29 import org.apache.myfaces.test.utils.HtmlCheckAttributesUtil;
30 import org.apache.myfaces.test.utils.HtmlRenderedAttr;
31 import org.apache.myfaces.test.base.AbstractJsfTestCase;
32 import org.apache.myfaces.test.mock.MockRenderKitFactory;
33 import org.apache.myfaces.test.mock.MockResponseWriter;
34
35 public class HtmlFormatRendererTest extends AbstractJsfTestCase
36 {
37 private MockResponseWriter writer;
38 private HtmlOutputFormat outputFormat;
39
40 public HtmlFormatRendererTest(String name)
41 {
42 super(name);
43 }
44
45 public static Test suite() {
46 return new TestSuite(HtmlFormatRendererTest.class);
47 }
48
49 public void setUp() throws Exception {
50 super.setUp();
51 outputFormat = new HtmlOutputFormat();
52 writer = new MockResponseWriter(new StringWriter(), null, null);
53 facesContext.setResponseWriter(writer);
54
55 facesContext.getViewRoot().setRenderKitId(MockRenderKitFactory.HTML_BASIC_RENDER_KIT);
56 facesContext.getRenderKit().addRenderer(
57 outputFormat.getFamily(),
58 outputFormat.getRendererType(),
59 new HtmlFormatRenderer());
60
61 facesContext.getAttributes().put("org.apache.myfaces.RENDERED_JSF_JS", Boolean.TRUE);
62 }
63
64 public void tearDown() throws Exception {
65 super.tearDown();
66 }
67
68 public void testHtmlPropertyPassTru() throws Exception
69 {
70 HtmlRenderedAttr[] attrs = {
71
72 new HtmlRenderedAttr("dir"),
73 new HtmlRenderedAttr("lang"),
74 new HtmlRenderedAttr("title"),
75
76 new HtmlRenderedAttr("style"),
77 new HtmlRenderedAttr("styleClass", "styleClass", "class=\"styleClass\""),
78 };
79
80 outputFormat.setValue("outputdata");
81 HtmlCheckAttributesUtil.checkRenderedAttributes(
82 outputFormat, facesContext, writer, attrs);
83 if(HtmlCheckAttributesUtil.hasFailedAttrRender(attrs)) {
84 fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
85 }
86 }
87
88 public void testHtmlPropertyPassTruNotRendered() throws Exception
89 {
90 HtmlRenderedAttr[] attrs = HtmlCheckAttributesUtil.generateAttrsNotRenderedForReadOnly();
91
92 outputFormat.setValue("outputdata");
93 HtmlCheckAttributesUtil.checkRenderedAttributes(
94 outputFormat, facesContext, writer, attrs);
95 if(HtmlCheckAttributesUtil.hasFailedAttrRender(attrs)) {
96 fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
97 }
98 }
99
100
101
102
103
104
105 public void testDisabledUIParameterNotRendered() throws Exception
106 {
107 UIParameter param1 = new UIParameter();
108 param1.setValue("value1");
109 param1.setDisable(true);
110 UIParameter param2 = new UIParameter();
111 param2.setValue("value2");
112 outputFormat.getChildren().add(param1);
113 outputFormat.getChildren().add(param2);
114
115 outputFormat.setValue("prefix{0}-{1}suffix");
116
117 outputFormat.encodeAll(facesContext);
118 String output = writer.getWriter().toString();
119 assertEquals("prefixvalue2-{1}suffix", output);
120 }
121 }