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 javax.faces.component.UIComponent;
23  import javax.faces.component.UIForm;
24  import javax.faces.component.UIOutput;
25  import javax.faces.component.UIPanel;
26  import javax.faces.component.UISelectItem;
27  import javax.faces.component.UISelectOne;
28  import javax.faces.component.UIViewRoot;
29  import javax.faces.component.html.HtmlForm;
30  import javax.faces.component.html.HtmlOutputText;
31  import javax.faces.component.html.HtmlPanelGrid;
32  import javax.faces.component.html.HtmlSelectOneMenu;
33  import javax.faces.context.ResponseWriter;
34  
35  import org.apache.myfaces.renderkit.html.HtmlFormRenderer;
36  import org.apache.myfaces.renderkit.html.HtmlGridRenderer;
37  import org.apache.myfaces.renderkit.html.HtmlMenuRenderer;
38  import org.apache.myfaces.renderkit.html.HtmlTextRenderer;
39  import org.apache.myfaces.view.facelets.FaceletTestCase;
40  import org.apache.myfaces.view.facelets.util.FastWriter;
41  import org.junit.Assert;
42  import org.junit.Test;
43  
44  public class WhitespaceTestCase extends FaceletTestCase {
45  
46      private UIComponent target;
47      
48      @Override
49      protected void setupComponents() throws Exception
50      {
51          application.addComponent(UIViewRoot.COMPONENT_TYPE,
52                  UIViewRoot.class.getName());
53          application.addComponent(HtmlForm.COMPONENT_TYPE,
54                  HtmlForm.class.getName());
55          application.addComponent(HtmlPanelGrid.COMPONENT_TYPE,
56                  HtmlPanelGrid.class.getName());
57          application.addComponent(HtmlSelectOneMenu.COMPONENT_TYPE,
58                  HtmlSelectOneMenu.class.getName());
59          application.addComponent(UISelectItem.COMPONENT_TYPE,
60                  UISelectItem.class.getName()); 
61          application.addComponent(HtmlOutputText.COMPONENT_TYPE,
62                  HtmlOutputText.class.getName());
63      }
64  
65      @Override
66      protected void setupConvertersAndValidators() throws Exception
67      {
68      }
69  
70      @Override
71      protected void setupRenderers() throws Exception
72      {
73          renderKit.addRenderer(UIForm.COMPONENT_FAMILY,
74                  "javax.faces.Form", new HtmlFormRenderer());
75          renderKit.addRenderer(UIOutput.COMPONENT_FAMILY,
76                  "javax.faces.Text", new HtmlTextRenderer());
77          renderKit.addRenderer(UISelectOne.COMPONENT_FAMILY,
78                  "javax.faces.Menu", new HtmlMenuRenderer());        
79          renderKit.addRenderer(UIPanel.COMPONENT_FAMILY,
80                  "javax.faces.Grid", new HtmlGridRenderer());
81          
82      }    
83  
84      @Test
85      public void testSelectOneMenu() throws Exception {
86          request.setAttribute("test", this);
87  
88          UIViewRoot root = facesContext.getViewRoot();
89          vdl.buildView(facesContext, root, "selectOne.xml");
90          
91          Assert.assertNotNull("target binding", target);
92          Assert.assertEquals("children", 2, this.target.getChildCount());
93  
94          FastWriter fw = new FastWriter();
95          ResponseWriter rw = facesContext.getResponseWriter();
96          rw = rw.cloneWithWriter(fw);
97          facesContext.setResponseWriter(rw);
98          root.encodeAll(facesContext);
99          //System.out.println(fw);
100     }
101     
102     @Test
103     public void testPanelGrid() throws Exception {
104         request.setAttribute("test", this);
105 
106         UIViewRoot root = facesContext.getViewRoot();
107         vdl.buildView(facesContext, root, "panelGrid.xml");
108         
109         Assert.assertNotNull("target binding", target);
110         Assert.assertEquals("children", 3, this.target.getChildCount());
111 
112         FastWriter fw = new FastWriter();
113         ResponseWriter rw = facesContext.getResponseWriter();
114         rw = rw.cloneWithWriter(fw);
115         facesContext.setResponseWriter(rw);
116         root.encodeAll(facesContext);
117         //System.out.println(fw);
118     }
119 
120     public void setUp() throws Exception {
121         super.setUp();
122         this.target = null;
123     }
124 
125     public UIComponent getTarget() {
126         return target;
127     }
128 
129     public void setTarget(UIComponent target) {
130         this.target = target;
131     }
132 
133 }