1 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 ; 25 import java.util.Locale ; 26 import java.util.Map ; 27 28 42 public class RendererUtilsTest 43 extends MyFacesBaseTest 44 { 45 47 public RendererUtilsTest(String name) 48 { 49 super(name); 50 } 51 52 53 protected void setUp() throws Exception 54 { 55 super.setUp(); 56 57 Map reqMap = _facesContext.getExternalContext().getRequestMap(); 58 reqMap.put("bean", new Bean()); 59 } 60 61 62 public static class Bean 63 { 64 private String _countryCode = Locale.US.getCountry(); 65 public String getCountryCode() 66 { 67 return _countryCode; 68 } 69 70 public SelectItem[] getCountrySelectItems() 71 { 72 String [] codes = Locale.getISOCountries(); 73 SelectItem[] items = new SelectItem[codes.length]; 74 for (int i = 0, len = codes.length; i < len; i++) 75 { 76 String iso = codes[i]; 77 String name = new Locale ("", 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 lst = RendererUtils.getSelectItemList(uiSelectOne); 100 assertEquals(Locale.getISOCountries().length, lst.size()); 101 } 102 103 } 104 | Popular Tags |