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