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.myfaces.test.base.junit4.AbstractJsfTestCase;
27 import org.junit.Assert;
28 import org.junit.Test;
29
30 public class UISelectManyTest extends AbstractJsfTestCase
31 {
32
33 public UISelectManyTest()
34 {
35 }
36
37 @Test
38 public void testValidateRequiredNull()
39 {
40
41 facesContext.getViewRoot().setLocale(_TEST_LOCALE);
42
43 UISelectMany selectMany = new UISelectMany();
44 selectMany.setId("selectMany");
45 selectMany.setRendererType(null);
46 selectMany.setRequired(true);
47 List<UIComponent> children = selectMany.getChildren();
48
49 UISelectItem one = new UISelectItem();
50 one.setItemValue(new Integer(1));
51 children.add(one);
52
53 UISelectItem two = new UISelectItem();
54 two.setItemValue(new Integer(2));
55 children.add(two);
56
57 UISelectItem three = new UISelectItem();
58 three.setItemValue(new Integer(3));
59 children.add(three);
60
61 selectMany.validateValue(facesContext, null);
62
63 Assert.assertFalse(selectMany.isValid());
64 }
65
66 @Test
67 public void testValidateRequiredEmptyList()
68 {
69
70 facesContext.getViewRoot().setLocale(_TEST_LOCALE);
71
72 UISelectMany selectMany = new UISelectMany();
73 selectMany.setId("selectMany");
74 selectMany.setRendererType(null);
75 selectMany.setRequired(true);
76 List<UIComponent> children = selectMany.getChildren();
77
78 UISelectItem one = new UISelectItem();
79 one.setItemValue(new Integer(1));
80 children.add(one);
81
82 UISelectItem two = new UISelectItem();
83 two.setItemValue(new Integer(2));
84 children.add(two);
85
86 UISelectItem three = new UISelectItem();
87 three.setItemValue(new Integer(3));
88 children.add(three);
89
90 selectMany.validateValue(facesContext, Collections.EMPTY_LIST);
91
92 Assert.assertFalse(selectMany.isValid());
93 }
94
95 @Test
96 public void testValidateIntArray()
97 {
98
99 facesContext.getViewRoot().setLocale(_TEST_LOCALE);
100
101 UISelectMany selectMany = new UISelectMany();
102 selectMany.setId("selectMany");
103 selectMany.setRendererType(null);
104 List<UIComponent> children = selectMany.getChildren();
105
106 UISelectItem one = new UISelectItem();
107 one.setItemValue(new Integer(1));
108 children.add(one);
109
110 UISelectItem two = new UISelectItem();
111 two.setItemValue(new Integer(2));
112 children.add(two);
113
114 UISelectItem three = new UISelectItem();
115 three.setItemValue(new Integer(3));
116 children.add(three);
117
118 selectMany.validateValue(facesContext, new int[] { 2, 3 });
119
120 Assert.assertTrue(selectMany.isValid());
121 }
122
123 @Test
124 public void testValidateStringArray()
125 {
126
127 facesContext.getViewRoot().setLocale(_TEST_LOCALE);
128
129 UISelectMany selectMany = new UISelectMany();
130 selectMany.setId("selectMany");
131 selectMany.setRendererType(null);
132 List<UIComponent> children = selectMany.getChildren();
133
134 UISelectItem one = new UISelectItem();
135 one.setItemValue("1");
136 children.add(one);
137
138 UISelectItem two = new UISelectItem();
139 two.setItemValue("2");
140 children.add(two);
141
142 UISelectItem three = new UISelectItem();
143 three.setItemValue("3");
144 children.add(three);
145
146 selectMany.validateValue(facesContext, new String[] { "2", "3" });
147
148 Assert.assertTrue(selectMany.isValid());
149 }
150
151 @Test
152 public void testValidateStringList()
153 {
154
155 facesContext.getViewRoot().setLocale(_TEST_LOCALE);
156
157 UISelectMany selectMany = new UISelectMany();
158 selectMany.setId("selectMany");
159 selectMany.setRendererType(null);
160 List<UIComponent> children = selectMany.getChildren();
161
162 UISelectItem one = new UISelectItem();
163 one.setItemValue("1");
164 children.add(one);
165
166 UISelectItem two = new UISelectItem();
167 two.setItemValue("2");
168 children.add(two);
169
170 UISelectItem three = new UISelectItem();
171 three.setItemValue("3");
172 children.add(three);
173
174 selectMany.validateValue(facesContext, Arrays.asList(new String[] {
175 "2", "3" }));
176
177 Assert.assertTrue(selectMany.isValid());
178 }
179
180 static private final Locale _TEST_LOCALE = new Locale("xx", "TEST");
181 }