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