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  
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          FaceletsProcessing item = new FaceletsProcessing();
86          item.setFileExtension(".view.xml");
87          item.setProcessAs(FaceletsProcessing.PROCESS_AS_XML);
88          RuntimeConfig.getCurrentInstance(externalContext).addFaceletProcessingConfiguration(FaceletsProcessing.PROCESS_AS_XML, item);
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 &quot; : &quot"));
117         Assert.assertTrue("Response contains comments", resp.contains("<!--"));
118         Assert.assertTrue("Response should escape EL and markup", resp.contains("Check EL Escaping &quot; : &quot;"));
119         
120     }
121 }