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.ext;
20  
21  import javax.faces.component.UISelectItem;
22  
23  import junit.framework.Test;
24  import junit.framework.TestSuite;
25  
26  import org.apache.myfaces.component.html.ext.HtmlSelectBooleanCheckbox;
27  import org.apache.myfaces.component.html.ext.HtmlSelectManyCheckbox;
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  
33  
34  public class HtmlCheckboxRendererTest extends AbstractTomahawkViewControllerTestCase
35  {
36      private MockResponseWriter writer ;
37      private HtmlSelectManyCheckbox selectManyCheckbox;
38      private HtmlSelectBooleanCheckbox selectBooleanCheckbox;
39  
40      public HtmlCheckboxRendererTest(String name)
41      {
42          super(name);
43      }
44      
45      public static Test suite() {
46          return new TestSuite(HtmlCheckboxRendererTest.class);
47      }
48  
49      public void setUp() throws Exception
50      {
51          super.setUp();
52  
53          selectManyCheckbox = new HtmlSelectManyCheckbox();
54          selectBooleanCheckbox = new HtmlSelectBooleanCheckbox();
55  
56          writer = (MockResponseWriter)facesContext.getResponseWriter();
57      }
58  
59      public void tearDown() throws Exception
60      {
61          super.tearDown();
62          selectManyCheckbox = null;
63          selectBooleanCheckbox = null;
64          writer = null;
65      }
66  
67      public void testSelectManyHtmlPropertyPassTru() throws Exception 
68      {
69          HtmlRenderedAttr[] attrs = {
70              //_AccesskeyProperty
71              new HtmlRenderedAttr("accesskey"),
72              //_UniversalProperties
73              new HtmlRenderedAttr("dir"), 
74              new HtmlRenderedAttr("lang"), 
75              new HtmlRenderedAttr("title"),
76              //_FocusBlurProperties
77              new HtmlRenderedAttr("onfocus"), 
78              new HtmlRenderedAttr("onblur"),
79              //_ChangeSelectProperties
80              new HtmlRenderedAttr("onchange"), 
81              new HtmlRenderedAttr("onselect"),
82              //_EventProperties
83              new HtmlRenderedAttr("onclick"), 
84              new HtmlRenderedAttr("ondblclick"), 
85              new HtmlRenderedAttr("onkeydown"), 
86              new HtmlRenderedAttr("onkeypress"),
87              new HtmlRenderedAttr("onkeyup"), 
88              new HtmlRenderedAttr("onmousedown"), 
89              new HtmlRenderedAttr("onmousemove"), 
90              new HtmlRenderedAttr("onmouseout"),
91              new HtmlRenderedAttr("onmouseover"), 
92              new HtmlRenderedAttr("onmouseup"),
93              //_StyleProperties
94              new HtmlRenderedAttr("style"), 
95              new HtmlRenderedAttr("styleClass", "styleClass", "class=\"styleClass\""),
96              //_TabindexProperty
97              new HtmlRenderedAttr("tabindex")
98          };
99          
100         UISelectItem item = new UISelectItem();
101         item.setItemLabel("mars");
102         item.setItemValue("mars");
103         selectManyCheckbox.getChildren().add(item);
104 
105         HtmlCheckAttributesUtil.checkRenderedAttributes(
106                 selectManyCheckbox, facesContext, writer, attrs);
107         if(HtmlCheckAttributesUtil.hasFailedAttrRender(attrs)) 
108         {
109             fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
110         }
111     }
112     
113     public void testSelectBooleanHtmlPropertyPasstru() throws Exception 
114     {
115         HtmlRenderedAttr[] attrs = {
116             //_AccesskeyProperty
117             new HtmlRenderedAttr("accesskey"),
118             //_UniversalProperties
119             new HtmlRenderedAttr("dir"), 
120             new HtmlRenderedAttr("lang"), 
121             new HtmlRenderedAttr("title"),
122             //_FocusBlurProperties
123             new HtmlRenderedAttr("onfocus"), 
124             new HtmlRenderedAttr("onblur"),
125             //_ChangeSelectProperties
126             new HtmlRenderedAttr("onchange"), 
127             new HtmlRenderedAttr("onselect"),
128             //_EventProperties
129             new HtmlRenderedAttr("onclick"), 
130             new HtmlRenderedAttr("ondblclick"), 
131             new HtmlRenderedAttr("onkeydown"), 
132             new HtmlRenderedAttr("onkeypress"),
133             new HtmlRenderedAttr("onkeyup"), 
134             new HtmlRenderedAttr("onmousedown"), 
135             new HtmlRenderedAttr("onmousemove"), 
136             new HtmlRenderedAttr("onmouseout"),
137             new HtmlRenderedAttr("onmouseover"), 
138             new HtmlRenderedAttr("onmouseup"),
139             //_StyleProperties
140             new HtmlRenderedAttr("style"), 
141             new HtmlRenderedAttr("styleClass", "styleClass", "class=\"styleClass\""),
142             //_TabindexProperty
143             new HtmlRenderedAttr("tabindex")
144         };
145         
146         selectBooleanCheckbox.setSelected(true);
147 
148         HtmlCheckAttributesUtil.checkRenderedAttributes(
149                 selectBooleanCheckbox, facesContext, writer, attrs);
150         if(HtmlCheckAttributesUtil.hasFailedAttrRender(attrs)) {
151             fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
152         }
153     
154     }   
155 }