1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package javax.faces.component;
20
21 import java.util.Arrays;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.Locale;
25
26 import org.apache.shale.test.base.AbstractJsfTestCase;
27
28 import junit.framework.Test;
29
30 public class UISelectManyTest extends AbstractJsfTestCase {
31
32 public UISelectManyTest(String name) {
33 super(name);
34 }
35
36 public void testValidateRequiredNull() {
37
38 facesContext.getViewRoot().setLocale(_TEST_LOCALE);
39
40 UISelectMany selectMany = new UISelectMany();
41 selectMany.setId("selectMany");
42 selectMany.setRendererType(null);
43 selectMany.setRequired(true);
44 List children = selectMany.getChildren();
45
46 UISelectItem one = new UISelectItem();
47 one.setItemValue(new Integer(1));
48 children.add(one);
49
50 UISelectItem two = new UISelectItem();
51 two.setItemValue(new Integer(2));
52 children.add(two);
53
54 UISelectItem three = new UISelectItem();
55 three.setItemValue(new Integer(3));
56 children.add(three);
57
58 selectMany.validateValue(facesContext, null);
59
60 assertFalse(selectMany.isValid());
61 }
62
63 public void testValidateRequiredEmptyList() {
64
65 facesContext.getViewRoot().setLocale(_TEST_LOCALE);
66
67 UISelectMany selectMany = new UISelectMany();
68 selectMany.setId("selectMany");
69 selectMany.setRendererType(null);
70 selectMany.setRequired(true);
71 List children = selectMany.getChildren();
72
73 UISelectItem one = new UISelectItem();
74 one.setItemValue(new Integer(1));
75 children.add(one);
76
77 UISelectItem two = new UISelectItem();
78 two.setItemValue(new Integer(2));
79 children.add(two);
80
81 UISelectItem three = new UISelectItem();
82 three.setItemValue(new Integer(3));
83 children.add(three);
84
85 selectMany.validateValue(facesContext, Collections.EMPTY_LIST);
86
87 assertFalse(selectMany.isValid());
88 }
89
90 public void testValidateIntArray() {
91
92 facesContext.getViewRoot().setLocale(_TEST_LOCALE);
93
94 UISelectMany selectMany = new UISelectMany();
95 selectMany.setId("selectMany");
96 selectMany.setRendererType(null);
97 List children = selectMany.getChildren();
98
99 UISelectItem one = new UISelectItem();
100 one.setItemValue(new Integer(1));
101 children.add(one);
102
103 UISelectItem two = new UISelectItem();
104 two.setItemValue(new Integer(2));
105 children.add(two);
106
107 UISelectItem three = new UISelectItem();
108 three.setItemValue(new Integer(3));
109 children.add(three);
110
111 selectMany.validateValue(facesContext, new int[] { 2, 3 });
112
113 assertTrue(selectMany.isValid());
114 }
115
116 public void testValidateStringArray() {
117
118 facesContext.getViewRoot().setLocale(_TEST_LOCALE);
119
120 UISelectMany selectMany = new UISelectMany();
121 selectMany.setId("selectMany");
122 selectMany.setRendererType(null);
123 List children = selectMany.getChildren();
124
125 UISelectItem one = new UISelectItem();
126 one.setItemValue("1");
127 children.add(one);
128
129 UISelectItem two = new UISelectItem();
130 two.setItemValue("2");
131 children.add(two);
132
133 UISelectItem three = new UISelectItem();
134 three.setItemValue("3");
135 children.add(three);
136
137 selectMany.validateValue(facesContext, new String[] { "2", "3" });
138
139 assertTrue(selectMany.isValid());
140 }
141
142 public void testValidateStringList() {
143
144 facesContext.getViewRoot().setLocale(_TEST_LOCALE);
145
146 UISelectMany selectMany = new UISelectMany();
147 selectMany.setId("selectMany");
148 selectMany.setRendererType(null);
149 List children = selectMany.getChildren();
150
151 UISelectItem one = new UISelectItem();
152 one.setItemValue("1");
153 children.add(one);
154
155 UISelectItem two = new UISelectItem();
156 two.setItemValue("2");
157 children.add(two);
158
159 UISelectItem three = new UISelectItem();
160 three.setItemValue("3");
161 children.add(three);
162
163 selectMany.validateValue(facesContext, Arrays.asList(new String[] { "2", "3" }));
164
165 assertTrue(selectMany.isValid());
166 }
167
168 static private final Locale _TEST_LOCALE = new Locale("xx", "TEST");
169 }