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.view.facelets.tag.jsf.html;
20  
21  import javax.faces.component.UIForm;
22  import javax.faces.component.UIOutput;
23  import javax.faces.component.UISelectItem;
24  import javax.faces.component.UISelectOne;
25  import javax.faces.component.UIViewRoot;
26  import javax.faces.component.html.HtmlCommandButton;
27  import javax.faces.component.html.HtmlForm;
28  import javax.faces.component.html.HtmlMessages;
29  import javax.faces.component.html.HtmlSelectOneMenu;
30  import javax.faces.convert.IntegerConverter;
31  
32  import org.apache.myfaces.renderkit.html.HtmlButtonRenderer;
33  import org.apache.myfaces.renderkit.html.HtmlFormRenderer;
34  import org.apache.myfaces.renderkit.html.HtmlMenuRenderer;
35  import org.apache.myfaces.renderkit.html.HtmlMessagesRenderer;
36  import org.apache.myfaces.renderkit.html.HtmlTextRenderer;
37  import org.apache.myfaces.view.facelets.FaceletTestCase;
38  import org.junit.Test;
39  
40  public class SelectTestCase extends FaceletTestCase
41  {
42  
43      @Override
44      protected void setupComponents() throws Exception
45      {
46          application.addComponent(UIViewRoot.COMPONENT_TYPE,
47                  UIViewRoot.class.getName());
48          application.addComponent(HtmlForm.COMPONENT_TYPE,
49                  HtmlForm.class.getName());        
50          application.addComponent(HtmlSelectOneMenu.COMPONENT_TYPE,
51                  HtmlSelectOneMenu.class.getName());
52          application.addComponent(UISelectItem.COMPONENT_TYPE,
53                  UISelectItem.class.getName());        
54          application.addComponent(HtmlCommandButton.COMPONENT_TYPE,
55                  HtmlCommandButton.class.getName());
56          application.addComponent(HtmlMessages.COMPONENT_TYPE,
57                  HtmlMessages.class.getName());
58      }
59  
60      @Override
61      protected void setupConvertersAndValidators() throws Exception
62      {
63          application.addConverter(IntegerConverter.CONVERTER_ID,
64                  IntegerConverter.class.getName());
65      }
66  
67      @Override
68      protected void setupRenderers() throws Exception
69      {
70          renderKit.addRenderer(UIOutput.COMPONENT_FAMILY,
71                  "javax.faces.Text", new HtmlTextRenderer());        
72          renderKit.addRenderer(UIForm.COMPONENT_FAMILY,
73                  "javax.faces.Form", new HtmlFormRenderer());
74          renderKit.addRenderer(HtmlSelectOneMenu.COMPONENT_FAMILY,
75                  "javax.faces.Menu", new HtmlMenuRenderer());        
76          renderKit.addRenderer(HtmlCommandButton.COMPONENT_FAMILY,
77                  "javax.faces.Button", new HtmlButtonRenderer());
78          renderKit.addRenderer(HtmlMessages.COMPONENT_FAMILY,
79                  "javax.faces.Messages", new HtmlMessagesRenderer());
80      }
81  
82      @Test
83      public void testSelectOne() throws Exception
84      {
85          request.getSession().setAttribute("test", new MockBean());
86          request.addParameter("testForm:alignment", "10");
87  
88          UIViewRoot root = new UIViewRoot();
89          vdl.buildView(facesContext, root,"selectOne.xml");
90          UISelectOne one = (UISelectOne) root
91                  .findComponent("testForm:alignment");
92          root.processDecodes(facesContext);
93          root.processValidators(facesContext);
94          //System.out.println(facesContext.getMessages().hasNext());
95      }
96  
97  }