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