1 package org.kuali.student.core.dictionary.service;
2
3 import java.util.Map;
4 import org.junit.Test;
5 import org.kuali.student.common.dictionary.dto.ValidCharsConstraint;
6 import org.kuali.student.common.validator.DefaultValidatorImpl;
7 import org.springframework.context.ApplicationContext;
8 import org.springframework.context.support.ClassPathXmlApplicationContext;
9 import static org.junit.Assert.*;
10
11 public class TestBaseDictionary
12 {
13
14 @Test
15 public void testValidCharsConstraints ()
16 {
17 System.out.println ("testing base dictionary");
18 String contextFile = "ks-base-dictionary-context.xml";
19 ApplicationContext ac = new ClassPathXmlApplicationContext ("classpath:"
20 + contextFile);
21 Map<String, ValidCharsConstraint> vcs = (Map<String, ValidCharsConstraint>) ac.getBeansOfType (
22 ValidCharsConstraint.class);
23 for (String id : vcs.keySet ())
24 {
25 ValidCharsConstraint vc = vcs.get (id);
26 System.out.println ("valid chars constraint: " + id + " "
27 + vc.getLabelKey () + " " + vc.getValue ());
28 }
29
30 String id = null;
31 ValidCharsConstraint vc = null;
32 DefaultValidatorImpl v = new DefaultValidatorImpl ();
33
34 id = "alphanumericHyphenPeriod";
35 vc = vcs.get (id);
36 assertNotNull (vc);
37 assertNull (v.processValidCharConstraint ("test", vc, null, "1"));
38 assertNull (v.processValidCharConstraint ("test", vc, null, "A"));
39 assertNull (v.processValidCharConstraint ("test", vc, null, "."));
40 assertNull (v.processValidCharConstraint ("test", vc, null, "-"));
41 assertNotNull (v.processValidCharConstraint ("test", vc, null, " "));
42 assertNotNull (v.processValidCharConstraint ("test", vc, null, ","));
43 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\n"));
44 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\r"));
45 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\t"));
46
47 id = "digits";
48 vc = vcs.get (id);
49 assertNotNull (vc);
50 assertNull (v.processValidCharConstraint ("test", vc, null, "1"));
51 assertNotNull (v.processValidCharConstraint ("test", vc, null, "A"));
52 assertNotNull (v.processValidCharConstraint ("test", vc, null, "."));
53 assertNotNull (v.processValidCharConstraint ("test", vc, null, "-"));
54 assertNotNull (v.processValidCharConstraint ("test", vc, null, " "));
55 assertNotNull (v.processValidCharConstraint ("test", vc, null, ","));
56 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\n"));
57 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\r"));
58 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\t"));
59
60 id = "numeric";
61 vc = vcs.get (id);
62 assertNotNull (vc);
63 assertNull (v.processValidCharConstraint ("test", vc, null, "0"));
64 assertNull (v.processValidCharConstraint ("test", vc, null, "1"));
65 assertNull (v.processValidCharConstraint ("test", vc, null, "20"));
66 assertNull (v.processValidCharConstraint ("test", vc, null, "-20"));
67 assertNull (v.processValidCharConstraint ("test", vc, null, "-12345620"));
68 assertNull (v.processValidCharConstraint ("test", vc, null, "20.1"));
69 assertNull (v.processValidCharConstraint ("test", vc, null, "20.0"));
70 assertNull (v.processValidCharConstraint ("test", vc, null, "20.01"));
71 assertNull (v.processValidCharConstraint ("test", vc, null, "20.00"));
72 assertNull (v.processValidCharConstraint ("test", vc, null, "120.00"));
73 assertNull (v.processValidCharConstraint ("test", vc, null, "1120.00"));
74 assertNull (v.processValidCharConstraint ("test", vc, null, "11120.00"));
75 assertNull (v.processValidCharConstraint ("test", vc, null, "111120.00"));
76 assertNull (v.processValidCharConstraint ("test", vc, null, "1111120.00"));
77 assertNull (v.processValidCharConstraint ("test", vc, null, "11111120.00"));
78 assertNotNull (v.processValidCharConstraint ("test", vc, null, "020"));
79 assertNotNull (v.processValidCharConstraint ("test", vc, null, "-020"));
80 assertNotNull (v.processValidCharConstraint ("test", vc, null, "-020.1"));
81 assertNotNull (v.processValidCharConstraint ("test", vc, null, "20.010"));
82 assertNotNull (v.processValidCharConstraint ("test", vc, null, "20.011"));
83 assertNotNull (v.processValidCharConstraint ("test", vc, null, "A"));
84 assertNotNull (v.processValidCharConstraint ("test", vc, null, "."));
85 assertNotNull (v.processValidCharConstraint ("test", vc, null, "-"));
86 assertNotNull (v.processValidCharConstraint ("test", vc, null, " "));
87 assertNotNull (v.processValidCharConstraint ("test", vc, null, ","));
88 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\n"));
89 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\r"));
90 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\t"));
91
92 id = "numeric.range";
93 vc = vcs.get (id);
94 assertNotNull (vc);
95 assertNull (v.processValidCharConstraint ("test", vc, null, "0"));
96 assertNull (v.processValidCharConstraint ("test", vc, null, "1"));
97 assertNull (v.processValidCharConstraint ("test", vc, null, "20"));
98 assertNull (v.processValidCharConstraint ("test", vc, null, "-20"));
99 assertNull (v.processValidCharConstraint ("test", vc, null, "-12345620"));
100 assertNull (v.processValidCharConstraint ("test", vc, null, "20.1"));
101 assertNull (v.processValidCharConstraint ("test", vc, null, "20.0"));
102 assertNull (v.processValidCharConstraint ("test", vc, null, "20.01"));
103 assertNull (v.processValidCharConstraint ("test", vc, null, "20.00"));
104 assertNull (v.processValidCharConstraint ("test", vc, null, "120.00"));
105 assertNull (v.processValidCharConstraint ("test", vc, null, "1120.00"));
106 assertNull (v.processValidCharConstraint ("test", vc, null, "11120.00"));
107 assertNull (v.processValidCharConstraint ("test", vc, null, "111120.00"));
108 assertNull (v.processValidCharConstraint ("test", vc, null, "1111120.00"));
109 assertNull (v.processValidCharConstraint ("test", vc, null, "11111120.00"));
110 assertNull (v.processValidCharConstraint ("test", vc, null, "1-2"));
111 assertNull (v.processValidCharConstraint ("test", vc, null, "1.1-2.2"));
112 assertNull (v.processValidCharConstraint ("test", vc, null, "1 - 2"));
113 assertNull (v.processValidCharConstraint ("test", vc, null, "1--2"));
114 assertNull (v.processValidCharConstraint ("test", vc, null, "1 - -2"));
115 assertNull (v.processValidCharConstraint ("test", vc, null, "-1 - -2"));
116 assertNotNull (v.processValidCharConstraint ("test", vc, null, "1 -2"));
117 assertNotNull (v.processValidCharConstraint ("test", vc, null, "1 - 2 - 3"));
118 assertNotNull (v.processValidCharConstraint ("test", vc, null, "1- 2"));
119 assertNotNull (v.processValidCharConstraint ("test", vc, null, "020"));
120 assertNotNull (v.processValidCharConstraint ("test", vc, null, "-020"));
121 assertNotNull (v.processValidCharConstraint ("test", vc, null, "-020.1"));
122 assertNotNull (v.processValidCharConstraint ("test", vc, null, "20.010"));
123 assertNotNull (v.processValidCharConstraint ("test", vc, null, "20.011"));
124 assertNotNull (v.processValidCharConstraint ("test", vc, null, "A"));
125 assertNotNull (v.processValidCharConstraint ("test", vc, null, "."));
126 assertNotNull (v.processValidCharConstraint ("test", vc, null, "-"));
127 assertNotNull (v.processValidCharConstraint ("test", vc, null, " "));
128 assertNotNull (v.processValidCharConstraint ("test", vc, null, ","));
129 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\n"));
130 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\r"));
131 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\t"));
132
133 id = "positive.numeric.range";
134 vc = vcs.get (id);
135 assertNotNull (vc);
136 assertNull (v.processValidCharConstraint ("test", vc, null, "0"));
137 assertNull (v.processValidCharConstraint ("test", vc, null, "1"));
138 assertNull (v.processValidCharConstraint ("test", vc, null, "20"));
139 assertNotNull (v.processValidCharConstraint ("test", vc, null, "-20"));
140 assertNotNull (v.processValidCharConstraint ("test", vc, null, "-12345620"));
141 assertNull (v.processValidCharConstraint ("test", vc, null, "20.1"));
142 assertNull (v.processValidCharConstraint ("test", vc, null, "20.0"));
143 assertNull (v.processValidCharConstraint ("test", vc, null, "20.01"));
144 assertNull (v.processValidCharConstraint ("test", vc, null, "20.00"));
145 assertNull (v.processValidCharConstraint ("test", vc, null, "120.00"));
146 assertNull (v.processValidCharConstraint ("test", vc, null, "1120.00"));
147 assertNull (v.processValidCharConstraint ("test", vc, null, "11120.00"));
148 assertNull (v.processValidCharConstraint ("test", vc, null, "111120.00"));
149 assertNull (v.processValidCharConstraint ("test", vc, null, "1111120.00"));
150 assertNull (v.processValidCharConstraint ("test", vc, null, "11111120.00"));
151 assertNull (v.processValidCharConstraint ("test", vc, null, "1-2"));
152 assertNull (v.processValidCharConstraint ("test", vc, null, "1.1-2.2"));
153 assertNull (v.processValidCharConstraint ("test", vc, null, "1 - 2"));
154 assertNotNull (v.processValidCharConstraint ("test", vc, null, "1--2"));
155 assertNotNull (v.processValidCharConstraint ("test", vc, null, "1 - -2"));
156 assertNotNull (v.processValidCharConstraint ("test", vc, null, "-1 - -2"));
157 assertNotNull (v.processValidCharConstraint ("test", vc, null, "1 -2"));
158 assertNotNull (v.processValidCharConstraint ("test", vc, null, "1 - 2 - 3"));
159 assertNotNull (v.processValidCharConstraint ("test", vc, null, "1- 2"));
160 assertNotNull (v.processValidCharConstraint ("test", vc, null, "020"));
161 assertNotNull (v.processValidCharConstraint ("test", vc, null, "-020"));
162 assertNotNull (v.processValidCharConstraint ("test", vc, null, "-020.1"));
163 assertNotNull (v.processValidCharConstraint ("test", vc, null, "20.010"));
164 assertNotNull (v.processValidCharConstraint ("test", vc, null, "20.011"));
165 assertNotNull (v.processValidCharConstraint ("test", vc, null, "A"));
166 assertNotNull (v.processValidCharConstraint ("test", vc, null, "."));
167 assertNotNull (v.processValidCharConstraint ("test", vc, null, "-"));
168 assertNotNull (v.processValidCharConstraint ("test", vc, null, " "));
169 assertNotNull (v.processValidCharConstraint ("test", vc, null, ","));
170 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\n"));
171 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\r"));
172 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\t"));
173
174 id = "gpa4.0";
175 vc = vcs.get (id);
176 assertNotNull (vc);
177 assertNull (v.processValidCharConstraint ("test", vc, null, "0.0"));
178 assertNull (v.processValidCharConstraint ("test", vc, null, "4.0"));
179 assertNull (v.processValidCharConstraint ("test", vc, null, "1.0"));
180
181
182 assertNotNull (v.processValidCharConstraint ("test", vc, null, "1"));
183 assertNull (v.processValidCharConstraint ("test", vc, null, "1.0"));
184 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\n"));
185 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\r"));
186 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\t"));
187
188 id = "positive.integer";
189 vc = vcs.get (id);
190 assertNotNull (vc);
191 assertNull (v.processValidCharConstraint ("test", vc, null, "1"));
192 assertNull (v.processValidCharConstraint ("test", vc, null, "22"));
193 assertNull (v.processValidCharConstraint ("test", vc, null, "33"));
194 assertNotNull (v.processValidCharConstraint ("test", vc, null, "0"));
195 assertNotNull (v.processValidCharConstraint ("test", vc, null, "1.0"));
196 assertNotNull (v.processValidCharConstraint ("test", vc, null, "-1"));
197 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\n"));
198 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\r"));
199 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\t"));
200
201 id = "relationalOperator";
202 vc = vcs.get (id);
203 assertNotNull (vc);
204 assertNull (v.processValidCharConstraint ("test", vc, null, "="));
205 assertNull (v.processValidCharConstraint ("test", vc, null, ">"));
206 assertNull (v.processValidCharConstraint ("test", vc, null, "<"));
207 assertNull (v.processValidCharConstraint ("test", vc, null, ">="));
208 assertNull (v.processValidCharConstraint ("test", vc, null, "<="));
209 assertNull (v.processValidCharConstraint ("test", vc, null, "<>"));
210 assertNotNull (v.processValidCharConstraint ("test", vc, null, "!="));
211 assertNotNull (v.processValidCharConstraint ("test", vc, null, "=>"));
212 assertNotNull (v.processValidCharConstraint ("test", vc, null, "=<"));
213 assertNotNull (v.processValidCharConstraint ("test", vc, null, "0"));
214 assertNotNull (v.processValidCharConstraint ("test", vc, null, "1.0"));
215 assertNotNull (v.processValidCharConstraint ("test", vc, null, "-1"));
216 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\n"));
217 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\r"));
218 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\t"));
219
220 id = "alpha";
221 vc = vcs.get (id);
222 assertNotNull (vc);
223 assertNull (v.processValidCharConstraint ("test", vc, null, "a"));
224 assertNull (v.processValidCharConstraint ("test", vc, null, "A"));
225 assertNull (v.processValidCharConstraint ("test", vc, null, "Z"));
226 assertNull (v.processValidCharConstraint ("test", vc, null, "zzzzz"));
227 assertNull (v.processValidCharConstraint ("test", vc, null,
228 "abcdefghijklmnopqrstuvwxyz"));
229 assertNotNull (v.processValidCharConstraint ("test", vc, null, "1"));
230 assertNotNull (v.processValidCharConstraint ("test", vc, null, "0"));
231 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\n"));
232 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\r"));
233 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\t"));
234
235 id = "upperCase";
236 vc = vcs.get (id);
237 assertNotNull (vc);
238 assertNull (v.processValidCharConstraint ("test", vc, null, "AB"));
239 assertNull (v.processValidCharConstraint ("test", vc, null, "A"));
240 assertNull (v.processValidCharConstraint ("test", vc, null,
241 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
242 assertNull (v.processValidCharConstraint ("test", vc, null, "-"));
243 assertNull (v.processValidCharConstraint ("test", vc, null, "."));
244 assertNull (v.processValidCharConstraint ("test", vc, null, "1"));
245 assertNull (v.processValidCharConstraint ("test", vc, null, "0"));
246 assertNotNull (v.processValidCharConstraint ("test", vc, null, "a"));
247 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\n"));
248 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\r"));
249 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\t"));
250
251 id = "upperAlpha";
252 vc = vcs.get (id);
253 assertNotNull (vc);
254 assertNull (v.processValidCharConstraint ("test", vc, null, "AB"));
255 assertNull (v.processValidCharConstraint ("test", vc, null, "A"));
256 assertNull (v.processValidCharConstraint ("test", vc, null,
257 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
258 assertNotNull (v.processValidCharConstraint ("test", vc, null, "a"));
259 assertNotNull (v.processValidCharConstraint ("test", vc, null, "1"));
260 assertNotNull (v.processValidCharConstraint ("test", vc, null, "0"));
261 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\n"));
262 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\r"));
263 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\t"));
264
265 id = "lineText";
266 vc = vcs.get (id);
267 assertNotNull (vc);
268 assertNull (v.processValidCharConstraint ("test", vc, null, "a"));
269 assertNull (v.processValidCharConstraint ("test", vc, null, "A"));
270 assertNull (v.processValidCharConstraint ("test", vc, null, "Z"));
271 assertNull (v.processValidCharConstraint ("test", vc, null, "Z"));
272 assertNull (v.processValidCharConstraint ("test", vc, null, "!"));
273 assertNull (v.processValidCharConstraint ("test", vc, null, "@"));
274 assertNull (v.processValidCharConstraint ("test", vc, null, "#"));
275 assertNull (v.processValidCharConstraint ("test", vc, null, "$"));
276 assertNull (v.processValidCharConstraint ("test", vc, null, "%"));
277
278 assertNotNull (v.processValidCharConstraint ("test", vc, null, "^"));
279 assertNull (v.processValidCharConstraint ("test", vc, null, "&"));
280 assertNotNull (v.processValidCharConstraint ("test", vc, null, "*"));
281 assertNull (v.processValidCharConstraint ("test", vc, null, "("));
282 assertNull (v.processValidCharConstraint ("test", vc, null, ")"));
283 assertNull (v.processValidCharConstraint ("test", vc, null, "_"));
284 assertNull (v.processValidCharConstraint ("test", vc, null, "+"));
285 assertNull (v.processValidCharConstraint ("test", vc, null, "-"));
286 assertNull (v.processValidCharConstraint ("test", vc, null, "="));
287 assertNotNull (v.processValidCharConstraint ("test", vc, null, "{"));
288 assertNotNull (v.processValidCharConstraint ("test", vc, null, "}"));
289 assertNull (v.processValidCharConstraint ("test", vc, null, "["));
290 assertNull (v.processValidCharConstraint ("test", vc, null, "]"));
291 assertNotNull (v.processValidCharConstraint ("test", vc, null, "|"));
292 assertNull (v.processValidCharConstraint ("test", vc, null, "\\"));
293 assertNull (v.processValidCharConstraint ("test", vc, null, ","));
294 assertNull (v.processValidCharConstraint ("test", vc, null, "."));
295 assertNull (v.processValidCharConstraint ("test", vc, null, "/"));
296 assertNull (v.processValidCharConstraint ("test", vc, null, "<"));
297 assertNull (v.processValidCharConstraint ("test", vc, null, ">"));
298 assertNull (v.processValidCharConstraint ("test", vc, null, "?"));
299 assertNotNull (v.processValidCharConstraint ("test", vc, null, "~"));
300 assertNotNull (v.processValidCharConstraint ("test", vc, null, "`"));
301
302 assertNull (v.processValidCharConstraint ("test", vc, null, "zzzzz"));
303 assertNull (v.processValidCharConstraint ("test", vc, null,
304 "abcdefghijklmnopqrstuvwxyz"));
305 assertNull (v.processValidCharConstraint ("test", vc, null,
306 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
307 assertNull (v.processValidCharConstraint ("test", vc, null, "1"));
308 assertNull (v.processValidCharConstraint ("test", vc, null, "0"));
309 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\n"));
310 assertNotNull (v.processValidCharConstraint ("test", vc, null, "\r"));
311 assertNull (v.processValidCharConstraint ("test", vc, null, "\t"));
312
313 id = "multiLineText";
314 vc = vcs.get (id);
315 assertNotNull (vc);
316 assertNull (v.processValidCharConstraint ("test", vc, null, "a"));
317 assertNull (v.processValidCharConstraint ("test", vc, null, "A"));
318 assertNull (v.processValidCharConstraint ("test", vc, null, "Z"));
319 assertNull (v.processValidCharConstraint ("test", vc, null, "Z"));
320 assertNull (v.processValidCharConstraint ("test", vc, null, "!"));
321 assertNull (v.processValidCharConstraint ("test", vc, null, "@"));
322 assertNull (v.processValidCharConstraint ("test", vc, null, "#"));
323 assertNull (v.processValidCharConstraint ("test", vc, null, "$"));
324 assertNull (v.processValidCharConstraint ("test", vc, null, "%"));
325
326 assertNotNull (v.processValidCharConstraint ("test", vc, null, "^"));
327 assertNull (v.processValidCharConstraint ("test", vc, null, "&"));
328 assertNotNull (v.processValidCharConstraint ("test", vc, null, "*"));
329 assertNull (v.processValidCharConstraint ("test", vc, null, "("));
330 assertNull (v.processValidCharConstraint ("test", vc, null, ")"));
331 assertNull (v.processValidCharConstraint ("test", vc, null, "_"));
332 assertNull (v.processValidCharConstraint ("test", vc, null, "+"));
333 assertNull (v.processValidCharConstraint ("test", vc, null, "-"));
334 assertNull (v.processValidCharConstraint ("test", vc, null, "="));
335 assertNotNull (v.processValidCharConstraint ("test", vc, null, "{"));
336 assertNotNull (v.processValidCharConstraint ("test", vc, null, "}"));
337 assertNull (v.processValidCharConstraint ("test", vc, null, "["));
338 assertNull (v.processValidCharConstraint ("test", vc, null, "]"));
339 assertNotNull (v.processValidCharConstraint ("test", vc, null, "|"));
340 assertNull (v.processValidCharConstraint ("test", vc, null, "\\"));
341 assertNull (v.processValidCharConstraint ("test", vc, null, ","));
342 assertNull (v.processValidCharConstraint ("test", vc, null, "."));
343 assertNull (v.processValidCharConstraint ("test", vc, null, "/"));
344 assertNull (v.processValidCharConstraint ("test", vc, null, "<"));
345 assertNull (v.processValidCharConstraint ("test", vc, null, ">"));
346 assertNull (v.processValidCharConstraint ("test", vc, null, "?"));
347 assertNotNull (v.processValidCharConstraint ("test", vc, null, "~"));
348 assertNotNull (v.processValidCharConstraint ("test", vc, null, "`"));
349
350 assertNull (v.processValidCharConstraint ("test", vc, null, "zzzzz"));
351 assertNull (v.processValidCharConstraint ("test", vc, null,
352 "abcdefghijklmnopqrstuvwxyz"));
353 assertNull (v.processValidCharConstraint ("test", vc, null,
354 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
355 assertNull (v.processValidCharConstraint ("test", vc, null, "1"));
356 assertNull (v.processValidCharConstraint ("test", vc, null, "0"));
357 assertNull (v.processValidCharConstraint ("test", vc, null, "\n"));
358 assertNull (v.processValidCharConstraint ("test", vc, null, "\r"));
359 assertNull (v.processValidCharConstraint ("test", vc, null, "\t"));
360
361
362
363 assertEquals (13, vcs.size ());
364 }
365 }