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