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.custom.tabbedpane;
20  
21  import java.io.PrintWriter;
22  import java.io.StringWriter;
23  
24  import junit.framework.Test;
25  import junit.framework.TestSuite;
26  
27  import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
28  import org.apache.myfaces.test.AbstractTomahawkViewControllerTestCase;
29  import org.apache.myfaces.test.mock.MockResponseWriter;
30  import org.apache.myfaces.test.utils.HtmlCheckAttributesUtil;
31  import org.apache.myfaces.test.utils.HtmlRenderedAttr;
32  import org.apache.myfaces.test.utils.MockTestViewHandler;
33  
34  public class HtmlTabbedPaneRendererTest extends AbstractTomahawkViewControllerTestCase
35  {
36      private HtmlPanelTabbedPane tabbedPane;
37      
38      public HtmlTabbedPaneRendererTest(String name)
39      {
40          super(name);
41      }
42  
43      public static Test suite() {
44          return new TestSuite(HtmlTabbedPaneRendererTest.class);
45      }
46      
47      public void setUp() throws Exception
48      {
49          super.setUp();
50          application.setViewHandler(new MockTestViewHandler());
51          tabbedPane = new HtmlPanelTabbedPane();
52      }
53      
54      public void tearDown() throws Exception 
55      {
56          super.tearDown();
57          tabbedPane = null;
58      }
59      
60      public void testHtmlPropertyPassTru() throws Exception
61      {
62          HtmlRenderedAttr[] attrs = {
63              //_UniversalProperties
64              new HtmlRenderedAttr("dir"), 
65              new HtmlRenderedAttr("lang"), 
66              new HtmlRenderedAttr("title"),
67              //_EventProperties
68              new HtmlRenderedAttr("onclick"), 
69              new HtmlRenderedAttr("ondblclick"), 
70              new HtmlRenderedAttr("onkeydown"), 
71              new HtmlRenderedAttr("onkeypress"),
72              new HtmlRenderedAttr("onkeyup"), 
73              new HtmlRenderedAttr("onmousedown"), 
74              new HtmlRenderedAttr("onmousemove"), 
75              new HtmlRenderedAttr("onmouseout"),
76              new HtmlRenderedAttr("onmouseover"), 
77              new HtmlRenderedAttr("onmouseup"),
78              //_StyleProperties
79              new HtmlRenderedAttr("style"), 
80              new HtmlRenderedAttr("styleClass", "styleClass", "class=\"myFaces_panelTabbedPane styleClass\""),
81          };
82          
83          tabbedPane.setServerSideTabSwitch(false);
84          
85          MockResponseWriter writer = (MockResponseWriter)facesContext.getResponseWriter();
86          try {
87              HtmlCheckAttributesUtil.checkRenderedAttributes(
88                      tabbedPane, facesContext, writer, attrs);
89          } catch(Exception e) {
90              StringWriter sw = new StringWriter();
91              e.printStackTrace(new PrintWriter(sw));
92              fail(sw.toString() + "\nHTML.TABLE_PASSTHROUGH_ATTRIBUTES: " + printHTMLAttrs(HTML.TABLE_PASSTHROUGH_ATTRIBUTES));
93          }
94          if(HtmlCheckAttributesUtil.hasFailedAttrRender(attrs)) {
95              fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
96          }
97      }
98      
99      public void testHtmlPropertyPassTruNotRendered() throws Exception 
100     { 
101         HtmlRenderedAttr[] attrs = HtmlCheckAttributesUtil.generateAttrsNotRenderedForReadOnly();
102 
103         tabbedPane.setServerSideTabSwitch(false);
104         MockResponseWriter writer = (MockResponseWriter)facesContext.getResponseWriter();
105         HtmlCheckAttributesUtil.checkRenderedAttributes(
106                 tabbedPane, facesContext, writer, attrs);
107         if(HtmlCheckAttributesUtil.hasFailedAttrRender(attrs)) 
108         {
109             fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
110         }
111     }
112     
113     private String printHTMLAttrs(String[] attrs) 
114     {
115         StringBuffer buffer = new StringBuffer();
116         for(int i = 0; i < attrs.length; i++) {
117             buffer.append(attrs[i]);
118             if(i+1 < attrs.length) {
119                 buffer.append(", ");
120             }
121         }
122         return buffer.toString();
123     }
124 }