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