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.toggle;
20  
21  import junit.framework.Test;
22  import junit.framework.TestSuite;
23  
24  import org.apache.myfaces.component.html.ext.HtmlInputText;
25  import org.apache.myfaces.test.AbstractTomahawkViewControllerTestCase;
26  import org.apache.myfaces.test.utils.HtmlCheckAttributesUtil;
27  import org.apache.myfaces.test.utils.HtmlRenderedAttr;
28  import org.apache.shale.test.mock.MockResponseWriter;
29  
30  public class ToggleLinkRendererTest extends AbstractTomahawkViewControllerTestCase
31  {
32      private MockResponseWriter writer;
33      private ToggleLink link;
34      private TogglePanel panel;
35      
36      public ToggleLinkRendererTest(String name)
37      {
38          super(name);
39      }
40      
41      public static Test suite() {
42          return new TestSuite(ToggleLinkRendererTest.class);
43      }
44      
45      public void setUp() throws Exception {
46          super.setUp();
47          writer = (MockResponseWriter)facesContext.getResponseWriter();
48          link = new ToggleLink();
49          panel = new TogglePanel();
50          
51          HtmlInputText inputText = new HtmlInputText();
52          inputText.setId("comp1");
53          
54          panel.getChildren().add(link);
55          panel.getChildren().add(inputText);
56          link.setFor("comp1");
57      }
58      
59      public void tearDown() {
60          writer = null;
61          link = null;
62      }    
63      
64      public void testHtmlPropertyPassTru() throws Exception
65      {
66          HtmlRenderedAttr[] attrs = {
67              //_AccesskeyProperty
68              new HtmlRenderedAttr("accesskey"),
69              //_UniversalProperties
70              new HtmlRenderedAttr("dir"), 
71              new HtmlRenderedAttr("lang"), 
72              new HtmlRenderedAttr("title"),
73              //_FocusBlurProperties
74              new HtmlRenderedAttr("onfocus"), 
75              new HtmlRenderedAttr("onblur"),
76              //_EventProperties
77              new HtmlRenderedAttr("onclick", "onclick", "onclick=\""), 
78              new HtmlRenderedAttr("ondblclick"), 
79              new HtmlRenderedAttr("onkeydown"), 
80              new HtmlRenderedAttr("onkeypress"),
81              new HtmlRenderedAttr("onkeyup"), 
82              new HtmlRenderedAttr("onmousedown"), 
83              new HtmlRenderedAttr("onmousemove"), 
84              new HtmlRenderedAttr("onmouseout"),
85              new HtmlRenderedAttr("onmouseover"), 
86              new HtmlRenderedAttr("onmouseup"),
87              //_StyleProperties
88              new HtmlRenderedAttr("style"), 
89              new HtmlRenderedAttr("styleClass", "styleClass", "class=\"styleClass\""),
90              //_TabindexProperty
91              new HtmlRenderedAttr("tabindex")
92          };
93  
94          HtmlCheckAttributesUtil.checkRenderedAttributes(
95                  link, facesContext, writer, attrs);
96          if(HtmlCheckAttributesUtil.hasFailedAttrRender(attrs)) 
97          {
98              fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
99          }
100     }    
101 }