1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.view.facelets.compiler;
21
22 import java.io.StringWriter;
23
24 import javax.faces.component.UIForm;
25 import javax.faces.component.UIOutput;
26 import javax.faces.component.UIPanel;
27 import javax.faces.component.UISelectItem;
28 import javax.faces.component.UISelectOne;
29 import javax.faces.component.UIViewRoot;
30 import javax.faces.component.html.HtmlForm;
31 import javax.faces.component.html.HtmlOutputText;
32 import javax.faces.component.html.HtmlPanelGrid;
33 import javax.faces.component.html.HtmlSelectOneMenu;
34
35 import junit.framework.Assert;
36
37 import org.apache.myfaces.renderkit.html.HtmlFormRenderer;
38 import org.apache.myfaces.renderkit.html.HtmlGridRenderer;
39 import org.apache.myfaces.renderkit.html.HtmlMenuRenderer;
40 import org.apache.myfaces.renderkit.html.HtmlTextRenderer;
41 import org.apache.myfaces.test.mock.MockResponseWriter;
42 import org.apache.myfaces.view.facelets.FaceletTestCase;
43 import org.junit.Test;
44
45 public class XHTMLFaceletsProcessingTestCase extends FaceletTestCase {
46
47 @Override
48 protected void setupComponents() throws Exception
49 {
50 application.addComponent(UIViewRoot.COMPONENT_TYPE,
51 UIViewRoot.class.getName());
52 application.addComponent(HtmlForm.COMPONENT_TYPE,
53 HtmlForm.class.getName());
54 application.addComponent(HtmlPanelGrid.COMPONENT_TYPE,
55 HtmlPanelGrid.class.getName());
56 application.addComponent(HtmlSelectOneMenu.COMPONENT_TYPE,
57 HtmlSelectOneMenu.class.getName());
58 application.addComponent(UISelectItem.COMPONENT_TYPE,
59 UISelectItem.class.getName());
60 application.addComponent(HtmlOutputText.COMPONENT_TYPE,
61 HtmlOutputText.class.getName());
62 }
63
64 @Override
65 protected void setupRenderers() throws Exception
66 {
67 renderKit.addRenderer(UIForm.COMPONENT_FAMILY,
68 "javax.faces.Form", new HtmlFormRenderer());
69 renderKit.addRenderer(UIOutput.COMPONENT_FAMILY,
70 "javax.faces.Text", new HtmlTextRenderer());
71 renderKit.addRenderer(UISelectOne.COMPONENT_FAMILY,
72 "javax.faces.Menu", new HtmlMenuRenderer());
73 renderKit.addRenderer(UIPanel.COMPONENT_FAMILY,
74 "javax.faces.Grid", new HtmlGridRenderer());
75
76 }
77
78
79
80 @Override
81 protected void setUpExternalContext() throws Exception
82 {
83 super.setUpExternalContext();
84
85
86
87
88
89
90 }
91
92 @Test
93 public void testXHTMLProcessing1() throws Exception
94 {
95 facesContext.getExternalContext().getRequestMap().put("rquote", "\"");
96
97 UIViewRoot root = facesContext.getViewRoot();
98 vdl.buildView(facesContext, root, "testXHTMLProcessing1.xhtml");
99
100 StringWriter sw = new StringWriter();
101 MockResponseWriter mrw = new MockResponseWriter(sw);
102 facesContext.setResponseWriter(mrw);
103
104 root.encodeAll(facesContext);
105
106 sw.flush();
107
108 String resp = sw.toString();
109
110 Assert.assertTrue("Response contains DOCTYPE declaration", resp.contains("<!DOCTYPE"));
111 Assert.assertFalse("Response not contains DOCTYPE html declaration", resp.contains("<!DOCTYPE html>"));
112 Assert.assertTrue("Response contains xml declaration", resp.contains("<?xml"));
113 Assert.assertTrue("Response contains xml processing instructions", resp.contains("<?name"));
114 Assert.assertTrue("Response contains cdata section", resp.contains("<![CDATA["));
115 Assert.assertTrue("Response contains cdata section", resp.contains("cdata not consumed"));
116 Assert.assertTrue("Response does not escape characters", resp.contains("In this mode, if you put a double quote, it will be replaced by " : ""));
117 Assert.assertTrue("Response contains comments", resp.contains("<!--"));
118 Assert.assertTrue("Response should escape EL and markup", resp.contains("Check EL Escaping " : ""));
119
120 }
121 }