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  package org.apache.myfaces.renderkit.html;
20  
21  import java.io.StringWriter;
22  
23  import javax.faces.component.html.HtmlOutputText;
24  import javax.faces.component.html.HtmlPanelGroup;
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  /**
36   * @author Bruno Aranda (latest modification by $Author: lu4242 $)
37   * @version $Revision: 1152969 $ $Date: 2011-08-01 18:30:49 -0500 (Mon, 01 Aug 2011) $
38   */
39  public class HtmlGroupRendererTest extends AbstractJsfTestCase
40  {
41      private static String PANEL_CHILD_TEXT = "PANEL";
42  
43      private MockResponseWriter writer ;
44      private HtmlPanelGroup panelGroup;
45  
46      public HtmlGroupRendererTest(String name)
47      {
48          super(name);
49      }
50      
51      public static Test suite() {
52          return new TestSuite(HtmlGroupRendererTest.class);
53      }
54  
55      public void setUp() throws Exception
56      {
57          super.setUp();
58  
59          panelGroup = new HtmlPanelGroup();
60  
61          HtmlOutputText panelChildOutputText = new HtmlOutputText();
62          panelChildOutputText.setValue(PANEL_CHILD_TEXT);
63          panelGroup.getChildren().add(panelChildOutputText);
64  
65          writer = new MockResponseWriter(new StringWriter(), null, null);
66          facesContext.setResponseWriter(writer);
67  
68          facesContext.getViewRoot().setRenderKitId(MockRenderKitFactory.HTML_BASIC_RENDER_KIT);
69          facesContext.getRenderKit().addRenderer(
70                  panelGroup.getFamily(),
71                  panelGroup.getRendererType(),
72                  new HtmlGroupRenderer());
73          facesContext.getRenderKit().addRenderer(
74                  panelChildOutputText.getFamily(),
75                  panelChildOutputText.getRendererType(),
76                  new HtmlTextRenderer());
77          
78          facesContext.getAttributes().put("org.apache.myfaces.RENDERED_JSF_JS", Boolean.TRUE);
79      }
80  
81      public void tearDown()throws Exception
82      {
83          super.tearDown();
84          writer = null;
85      }
86      
87      public void testHtmlPropertyPassTru() throws Exception
88      { 
89          HtmlRenderedAttr[] attrs = {
90                  new HtmlRenderedAttr("style"), 
91                  new HtmlRenderedAttr("styleClass", "styleClass", "class=\"styleClass\"")
92                  }; 
93              //HtmlCheckAttributesUtil.generateBasicReadOnlyAttrs();
94  
95          HtmlCheckAttributesUtil.checkRenderedAttributes(
96                  panelGroup, facesContext, writer, attrs);
97          if(HtmlCheckAttributesUtil.hasFailedAttrRender(attrs)) {
98              fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
99          }
100     }
101     
102     public void testHtmlPropertyPassTruNotRendered() throws Exception
103     { 
104         HtmlRenderedAttr[] attrs = HtmlCheckAttributesUtil.generateAttrsNotRenderedForReadOnly();        
105 
106         HtmlCheckAttributesUtil.checkRenderedAttributes(
107                 panelGroup, facesContext, writer, attrs);
108         if(HtmlCheckAttributesUtil.hasFailedAttrRender(attrs)) {
109             fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
110         }
111     }
112 }