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.HtmlBody;
24  
25  import junit.framework.Test;
26  import junit.framework.TestSuite;
27  
28  import org.apache.myfaces.test.base.AbstractJsfTestCase;
29  import org.apache.myfaces.test.mock.MockRenderKitFactory;
30  import org.apache.myfaces.test.mock.MockResponseWriter;
31  import org.apache.myfaces.test.utils.HtmlCheckAttributesUtil;
32  import org.apache.myfaces.test.utils.HtmlRenderedAttr;
33  
34  /**
35   * @author Leonardo Uribe
36   */
37  public class HtmlBodyRendererTest extends AbstractJsfTestCase
38  {
39  
40      private MockResponseWriter writer ;
41      private HtmlBody body;
42  
43      public HtmlBodyRendererTest(String name)
44      {
45          super(name);
46      }
47      
48      public static Test suite() {
49          return new TestSuite(HtmlBodyRendererTest.class);
50      }
51  
52      public void setUp() throws Exception
53      {
54          super.setUp();
55  
56          body = new HtmlBody();
57  
58          writer = new MockResponseWriter(new StringWriter(), null, null);
59          facesContext.setResponseWriter(writer);
60  
61          facesContext.getViewRoot().setRenderKitId(MockRenderKitFactory.HTML_BASIC_RENDER_KIT);
62          facesContext.getRenderKit().addRenderer(
63                  body.getFamily(),
64                  body.getRendererType(),
65                  new HtmlBodyRenderer());
66          
67          facesContext.getAttributes().put("org.apache.myfaces.RENDERED_JSF_JS", Boolean.TRUE);
68      }
69  
70      public void tearDown()throws Exception
71      {
72          super.tearDown();
73          writer = null;
74      }
75      
76      public void testHtmlPropertyPassTru2() throws Exception
77      { 
78          HtmlRenderedAttr[] attrs = {
79                  new HtmlRenderedAttr("xmlns")
80          };
81  
82          HtmlCheckAttributesUtil.checkRenderedAttributes(
83                  body, facesContext, writer, attrs);
84          if(HtmlCheckAttributesUtil.hasFailedAttrRender(attrs)) {
85              fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
86          }
87      }
88      
89      public void testHtmlPropertyPassTru() throws Exception
90      {
91          HtmlRenderedAttr[] attrs = HtmlCheckAttributesUtil.generateBasicReadOnlyAttrs();
92  
93          HtmlCheckAttributesUtil.checkRenderedAttributes(
94                  body, facesContext, writer, attrs);
95          if(HtmlCheckAttributesUtil.hasFailedAttrRender(attrs)) {
96              fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
97          }
98      }
99  
100 }