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.HtmlHead;
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 HtmlHeadRendererTest extends AbstractJsfTestCase
38  {
39  
40      private MockResponseWriter writer ;
41      private HtmlHead head;
42  
43      public HtmlHeadRendererTest(String name)
44      {
45          super(name);
46      }
47      
48      public static Test suite() {
49          return new TestSuite(HtmlHeadRendererTest.class);
50      }
51  
52      public void setUp() throws Exception
53      {
54          super.setUp();
55  
56          head = new HtmlHead();
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                  head.getFamily(),
64                  head.getRendererType(),
65                  new HtmlHeadRenderer());
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 testHtmlPropertyPassTru() throws Exception
77      { 
78          HtmlRenderedAttr[] attrs = {
79                  new HtmlRenderedAttr("xmlns"),
80                  new HtmlRenderedAttr("dir"),
81                  new HtmlRenderedAttr("lang"),
82          };
83  
84          HtmlCheckAttributesUtil.checkRenderedAttributes(
85                  head, facesContext, writer, attrs);
86          if(HtmlCheckAttributesUtil.hasFailedAttrRender(attrs)) {
87              fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
88          }
89      }
90  }