KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > renderkit > RendererUtilsTest


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.myfaces.renderkit;
17
18 import org.apache.myfaces.MyFacesBaseTest;
19 import org.apache.myfaces.el.ValueBindingImpl;
20
21 import javax.faces.component.UISelectItems;
22 import javax.faces.component.UISelectOne;
23 import javax.faces.model.SelectItem;
24 import java.util.List JavaDoc;
25 import java.util.Locale JavaDoc;
26 import java.util.Map JavaDoc;
27
28 /**
29  * @author Manfred Geiler (latest modification by $Author: matze $)
30  * @version $Revision: 1.3 $ $Date: 2004/10/13 11:50:59 $
31  * $Log: RendererUtilsTest.java,v $
32  * Revision 1.3 2004/10/13 11:50:59 matze
33  * renamed packages to org.apache
34  *
35  * Revision 1.2 2004/07/01 22:01:21 mwessendorf
36  * ASF switch
37  *
38  * Revision 1.1 2004/05/03 08:05:19 manolito
39  * new test
40  *
41  */

42 public class RendererUtilsTest
43         extends MyFacesBaseTest
44 {
45     //private static final Log log = LogFactory.getLog(RendererUtilsTest.class);
46

47     public RendererUtilsTest(String JavaDoc name)
48     {
49         super(name);
50     }
51
52
53     protected void setUp() throws Exception JavaDoc
54     {
55         super.setUp();
56
57         Map JavaDoc reqMap = _facesContext.getExternalContext().getRequestMap();
58         reqMap.put("bean", new Bean());
59     }
60
61
62     public static class Bean
63     {
64         private String JavaDoc _countryCode = Locale.US.getCountry();
65         public String JavaDoc getCountryCode()
66         {
67             return _countryCode;
68         }
69
70         public SelectItem[] getCountrySelectItems()
71         {
72             String JavaDoc[] codes = Locale.getISOCountries();
73             SelectItem[] items = new SelectItem[codes.length];
74             for (int i = 0, len = codes.length; i < len; i++)
75             {
76                 String JavaDoc iso = codes[i];
77                 String JavaDoc name = new Locale JavaDoc("", codes[i]).getDisplayCountry();
78                 items[i] = new SelectItem(iso, name);
79             }
80             return items;
81         }
82     }
83
84
85     public void testGetSelectItemList()
86     {
87         UISelectOne uiSelectOne = new UISelectOne();
88         uiSelectOne.setId("id1");
89         uiSelectOne.setValueBinding("value", new ValueBindingImpl(_application,
90                                                                   "#{bean.countryCode}"));
91
92         UISelectItems uiSelectItems = new UISelectItems();
93         uiSelectItems.setId("id2");
94         uiSelectItems.setValueBinding("value", new ValueBindingImpl(_application,
95                                                                   "#{bean.countrySelectItems}"));
96
97         uiSelectOne.getChildren().add(uiSelectItems);
98
99         List JavaDoc lst = RendererUtils.getSelectItemList(uiSelectOne);
100         assertEquals(Locale.getISOCountries().length, lst.size());
101     }
102
103 }
104
Popular Tags