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 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.component.html.ext.HtmlSelectManyListbox;
31  import org.apache.myfaces.component.html.ext.HtmlSelectOneListbox;
32  import org.apache.myfaces.test.AbstractTomahawkViewControllerTestCase;
33  import org.apache.myfaces.test.mock.MockResponseWriter;
34  import org.apache.myfaces.test.utils.HtmlCheckAttributesUtil;
35  import org.apache.myfaces.test.utils.HtmlRenderedAttr;
36  
37  public class HtmlListboxRendererTest extends AbstractTomahawkViewControllerTestCase
38  {
39      private MockResponseWriter writer ;
40      private HtmlSelectOneListbox selectOneListbox;
41      private HtmlSelectManyListbox selectManyListbox;
42  
43      public HtmlListboxRendererTest(String name)
44      {
45          super(name);
46      }
47      
48      public static Test suite() {
49          return new TestSuite(HtmlListboxRendererTest.class);
50      }
51  
52      public void setUp() throws Exception
53      {
54          super.setUp();
55  
56          selectOneListbox = new HtmlSelectOneListbox();
57          selectManyListbox = new HtmlSelectManyListbox();
58  
59          writer = (MockResponseWriter) facesContext.getResponseWriter();
60      }
61  
62      public void tearDown() throws Exception
63      {
64          super.tearDown();
65          selectOneListbox = null;
66          writer = null;
67      }
68  
69      public void testSelectOneHtmlPropertyPassTru() throws Exception
70      {
71          HtmlRenderedAttr[] attrs = HtmlCheckAttributesUtil.generateBasicAttrs();
72          
73          List items = new ArrayList();
74          items.add(new SelectItem("mars"));
75  
76          UISelectItems selectItems = new UISelectItems();
77          selectItems.setValue(items);
78  
79          selectOneListbox.getChildren().add(selectItems);
80  
81          HtmlCheckAttributesUtil.checkRenderedAttributes(
82                  selectOneListbox, facesContext, writer, attrs);
83          if(HtmlCheckAttributesUtil.hasFailedAttrRender(attrs)) {
84              fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
85          }
86      }
87      
88      public void testSelectManyHtmlPropertyPassTru() throws Exception
89      {
90          HtmlRenderedAttr[] attrs = HtmlCheckAttributesUtil.generateBasicAttrs();
91          
92          List items = new ArrayList();
93          items.add(new SelectItem("mars"));
94  
95          UISelectItems selectItems = new UISelectItems();
96          selectItems.setValue(items);
97  
98          selectManyListbox.getChildren().add(selectItems);
99          
100         HtmlCheckAttributesUtil.checkRenderedAttributes(
101                 selectManyListbox, facesContext, writer, attrs);
102         if(HtmlCheckAttributesUtil.hasFailedAttrRender(attrs)) {
103             fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
104         }
105     }
106 }