1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.r2.common.datadictionary;
17
18 import static org.junit.Assert.assertEquals;
19
20 import java.io.IOException;
21 import java.text.DateFormat;
22 import java.text.ParseException;
23 import java.text.SimpleDateFormat;
24 import java.util.ArrayList;
25 import java.util.Date;
26 import java.util.List;
27
28 import org.junit.*;
29 import org.kuali.rice.core.api.config.property.Config;
30 import org.kuali.rice.core.api.config.property.ConfigContext;
31 import org.kuali.rice.core.impl.config.property.JAXBConfigImpl;
32 import org.kuali.student.r2.common.util.constants.AcademicCalendarServiceConstants;
33 import org.kuali.student.enrollment.acal.dto.AcademicCalendarInfo;
34 import org.kuali.student.r2.common.dto.ContextInfo;
35 import org.kuali.student.r2.common.dto.ValidationResultInfo;
36 import org.kuali.student.r2.common.infc.ValidationResult;
37 import org.kuali.student.r2.common.util.RichTextHelper;
38 import org.springframework.context.ApplicationContext;
39 import org.springframework.context.support.ClassPathXmlApplicationContext;
40
41
42
43
44
45 @Ignore
46 public class TestRiceDataDictionaryValidatorImplAgainstAcal {
47
48 public TestRiceDataDictionaryValidatorImplAgainstAcal() {
49 }
50
51 @BeforeClass
52 public static void setUpClass() throws Exception {
53 }
54
55 @AfterClass
56 public static void tearDownClass() throws Exception {
57 }
58
59 protected Config getTestHarnessConfig() {
60 Config config = new JAXBConfigImpl(getConfigLocations(), System.getProperties());
61 try {
62 config.parseConfig();
63 } catch (IOException ex) {
64 throw new RuntimeException(ex);
65 }
66 return config;
67 }
68
69
70
71
72
73
74 protected List<String> getConfigLocations() {
75 List<String> configLocations = new ArrayList<String>();
76
77 return configLocations;
78 }
79
80 @Before
81 public void setUp() {
82 Config config = getTestHarnessConfig();
83 ConfigContext.init(config);
84 }
85
86 @After
87 public void tearDown() {
88 }
89
90 private Date parseDate(String str) {
91 DateFormat df = new SimpleDateFormat("yyyy-mm-dd");
92 Date date = null;
93 try {
94 date = df.parse(str);
95 } catch (ParseException ex) {
96 throw new IllegalArgumentException(str, ex);
97 }
98 return date;
99 }
100
101 private ContextInfo getContext1() {
102 return ContextInfo.getInstance("principalId.1", "en", "us");
103 }
104 private static DataDictionaryValidator validator;
105
106 public DataDictionaryValidator getValidator() {
107 if (validator == null) {
108 ApplicationContext appContext =
109 new ClassPathXmlApplicationContext(new String[]{"classpath:testContext.xml"});
110 this.validator = (DataDictionaryValidator) appContext.getBean("testValidator");
111 }
112 return validator;
113 }
114
115 private AcademicCalendarInfo getDefaultAcademicCalendarInfo() {
116 AcademicCalendarInfo acal = new AcademicCalendarInfo();
117 acal.setId("org.kuali.test.acal");
118 acal.setName("test acal");
119 acal.setTypeKey(AcademicCalendarServiceConstants.ACADEMIC_CALENDAR_TYPE_KEY);
120 acal.setStateKey(AcademicCalendarServiceConstants.ACADEMIC_CALENDAR_DRAFT_STATE_KEY);
121 acal.setStartDate(parseDate("2010-01-01"));
122 acal.setEndDate(parseDate("2010-06-30"));
123 return acal;
124 }
125
126
127
128
129 @Test
130 public void testValidate1() throws Exception {
131 System.out.println("basic validation test has all required fields");
132 DataDictionaryValidator.ValidationType validationType = null;
133 AcademicCalendarInfo acal = null;
134 ContextInfo context = null;
135
136 DataDictionaryValidator intstance = this.getValidator();
137 List<ValidationResultInfo> result = null;
138
139 validationType = DataDictionaryValidator.ValidationType.FULL_VALIDATION;
140 acal = this.getDefaultAcademicCalendarInfo();
141 context = getContext1();
142 result = intstance.validate(validationType, acal, context);
143 assertEquals(0, result.size());
144 }
145
146
147
148
149 @Test
150 public void testValidate2() throws Exception {
151 System.out.println("check that type key is required");
152 DataDictionaryValidator.ValidationType validationType = null;
153 AcademicCalendarInfo acal = null;
154 ContextInfo context = null;
155
156 DataDictionaryValidator intstance = this.getValidator();
157 List<ValidationResultInfo> result = null;
158
159
160 validationType = DataDictionaryValidator.ValidationType.FULL_VALIDATION;
161 acal = this.getDefaultAcademicCalendarInfo();
162 context = getContext1();
163 acal.setTypeKey(null);
164 result = intstance.validate(validationType, acal, context);
165 for (ValidationResult vri : result) {
166 System.out.println(vri.getElement() + " " + vri.getLevel() + " " + vri.getMessage());
167 }
168 assertEquals(1, result.size());
169 assertEquals("typeKey", result.get(0).getElement());
170 assertEquals(new Integer(2), result.get(0).getLevel());
171 assertEquals("error.required", result.get(0).getMessage());
172 }
173
174
175
176
177 @Test
178 public void testValidate3() throws Exception {
179 System.out.println("check that empty string is same as null");
180 DataDictionaryValidator.ValidationType validationType = null;
181 AcademicCalendarInfo acal = null;
182 ContextInfo context = null;
183
184 DataDictionaryValidator intstance = this.getValidator();
185 List<ValidationResultInfo> result = null;
186
187
188
189 validationType = DataDictionaryValidator.ValidationType.FULL_VALIDATION;
190 acal = this.getDefaultAcademicCalendarInfo();
191 context = getContext1();
192 acal.setTypeKey("");
193 result = intstance.validate(validationType, acal, context);
194 for (ValidationResult vri : result) {
195 System.out.println(vri.getElement() + " " + vri.getLevel() + " " + vri.getMessage());
196 }
197 assertEquals(1, result.size());
198 assertEquals("typeKey", result.get(0).getElement());
199 assertEquals(new Integer(2), result.get(0).getLevel());
200 assertEquals("error.required", result.get(0).getMessage());
201 }
202
203
204
205
206 @Test
207 public void testValidate4() throws Exception {
208 System.out.println("check that a single blank string is same as null");
209 DataDictionaryValidator.ValidationType validationType = null;
210 AcademicCalendarInfo acal = null;
211 ContextInfo context = null;
212
213 DataDictionaryValidator intstance = this.getValidator();
214 List<ValidationResultInfo> result = null;
215
216
217
218 validationType = DataDictionaryValidator.ValidationType.FULL_VALIDATION;
219 acal = this.getDefaultAcademicCalendarInfo();
220 context = getContext1();
221 acal.setTypeKey(" ");
222 result = intstance.validate(validationType, acal, context);
223 for (ValidationResult vri : result) {
224 System.out.println(vri.getElement() + " " + vri.getLevel() + " " + vri.getMessage());
225 }
226 assertEquals(1, result.size());
227 assertEquals("typeKey", result.get(0).getElement());
228 assertEquals(new Integer(2), result.get(0).getLevel());
229 assertEquals("error.required", result.get(0).getMessage());
230 }
231
232
233
234
235 @Test
236 public void testValidate5() throws Exception {
237 System.out.println("check that a lots of blanks is same as null");
238 DataDictionaryValidator.ValidationType validationType = null;
239 AcademicCalendarInfo acal = null;
240 ContextInfo context = null;
241
242 DataDictionaryValidator intstance = this.getValidator();
243 List<ValidationResultInfo> result = null;
244
245
246
247 validationType = DataDictionaryValidator.ValidationType.FULL_VALIDATION;
248 acal = this.getDefaultAcademicCalendarInfo();
249 context = getContext1();
250 acal.setTypeKey(" ");
251 result = intstance.validate(validationType, acal, context);
252 for (ValidationResult vri : result) {
253 System.out.println(vri.getElement() + " " + vri.getLevel() + " " + vri.getMessage());
254 }
255 assertEquals(1, result.size());
256 assertEquals("typeKey", result.get(0).getElement());
257 assertEquals(new Integer(2), result.get(0).getLevel());
258 assertEquals("error.required", result.get(0).getMessage());
259 }
260
261
262
263
264 @Test
265 public void testValidate6() throws Exception {
266 System.out.println("check that tabs and newlines count as all whitespace and is the same as null");
267 DataDictionaryValidator.ValidationType validationType = null;
268 AcademicCalendarInfo acal = null;
269 ContextInfo context = null;
270
271 DataDictionaryValidator intstance = this.getValidator();
272 List<ValidationResultInfo> result = null;
273
274
275
276 validationType = DataDictionaryValidator.ValidationType.FULL_VALIDATION;
277 acal = this.getDefaultAcademicCalendarInfo();
278 context = getContext1();
279 acal.setTypeKey(" \n\t\r ");
280 result = intstance.validate(validationType, acal, context);
281 for (ValidationResult vri : result) {
282 System.out.println(vri.getElement() + " " + vri.getLevel() + " " + vri.getMessage());
283 }
284 assertEquals(1, result.size());
285 assertEquals("typeKey", result.get(0).getElement());
286 assertEquals(new Integer(2), result.get(0).getLevel());
287 assertEquals("error.required", result.get(0).getMessage());
288
289 }
290
291
292
293
294 @Test
295 public void testValidate7() throws Exception {
296 System.out.println("check that we can skip the requiredness checks");
297 DataDictionaryValidator.ValidationType validationType = null;
298 AcademicCalendarInfo acal = null;
299 ContextInfo context = null;
300
301 DataDictionaryValidator intstance = this.getValidator();
302 List<ValidationResultInfo> result = null;
303
304
305
306 validationType = DataDictionaryValidator.ValidationType.SKIP_REQUREDNESS_VALIDATIONS;
307 acal = this.getDefaultAcademicCalendarInfo();
308 context = getContext1();
309 acal.setTypeKey(null);
310 result = intstance.validate(validationType, acal, context);
311 for (ValidationResult vri : result) {
312 System.out.println(vri.getElement() + " " + vri.getLevel() + " " + vri.getMessage());
313 }
314 assertEquals(0, result.size());
315 }
316
317
318
319
320 @Test
321 @Ignore
322 public void testValidate8() throws Exception {
323 System.out.println("check that valid chars catches that the name cannot have an embedded new line");
324 DataDictionaryValidator.ValidationType validationType = null;
325 AcademicCalendarInfo acal = null;
326 ContextInfo context = null;
327
328 DataDictionaryValidator intstance = this.getValidator();
329 List<ValidationResultInfo> result = null;
330
331
332
333 validationType = DataDictionaryValidator.ValidationType.FULL_VALIDATION;
334 acal = this.getDefaultAcademicCalendarInfo();
335 context = getContext1();
336 acal.setName("this has \n an embedded return");
337 result = intstance.validate(validationType, acal, context);
338 for (ValidationResult vri : result) {
339 System.out.println(vri.getElement() + " " + vri.getLevel() + " " + vri.getMessage());
340 }
341 assertEquals(1, result.size());
342 assertEquals("name", result.get(0).getElement());
343 assertEquals(new Integer(2), result.get(0).getLevel());
344 assertEquals("error.invalidFormat", result.get(0).getMessage());
345 }
346
347
348
349
350 @Test
351 public void testValidate9() throws Exception {
352 System.out.println("check that name cannot exceed 255");
353 DataDictionaryValidator.ValidationType validationType = null;
354 AcademicCalendarInfo acal = null;
355 ContextInfo context = null;
356
357 DataDictionaryValidator intstance = this.getValidator();
358 List<ValidationResultInfo> result = null;
359
360
361
362 validationType = DataDictionaryValidator.ValidationType.FULL_VALIDATION;
363 acal = this.getDefaultAcademicCalendarInfo();
364 context = getContext1();
365 acal.setName(
366 "This has is a really long name in fact it is so long that it goes on and on and on and on sometimes I think it will go on forever"
367 + " but not really because the limit should be at 255 becaue that is the default in the dictionary and now I think I should stop typing");
368 result = intstance.validate(validationType, acal, context);
369 for (ValidationResult vri : result) {
370 System.out.println(vri.getElement() + " " + vri.getLevel() + " " + vri.getMessage());
371 }
372 assertEquals(1, result.size());
373 assertEquals("name", result.get(0).getElement());
374 assertEquals(new Integer(2), result.get(0).getLevel());
375 assertEquals("error.outOfRange", result.get(0).getMessage());
376 }
377
378
379
380
381 @Test
382 public void testValidate10() throws Exception {
383 System.out.println("check that the name does not get trimmed before comparing it to not exceed 255");
384 DataDictionaryValidator.ValidationType validationType = null;
385 AcademicCalendarInfo acal = null;
386 ContextInfo context = null;
387
388 DataDictionaryValidator intstance = this.getValidator();
389 List<ValidationResultInfo> result = null;
390
391
392
393 validationType = DataDictionaryValidator.ValidationType.FULL_VALIDATION;
394 acal = this.getDefaultAcademicCalendarInfo();
395 context = getContext1();
396 acal.setName(
397 "test acal "
398 + " ");
399 result = intstance.validate(validationType, acal, context);
400 for (ValidationResult vri : result) {
401 System.out.println(vri.getElement() + " " + vri.getLevel() + " " + vri.getMessage());
402 }
403 assertEquals(1, result.size());
404 assertEquals("name", result.get(0).getElement());
405 assertEquals(new Integer(2), result.get(0).getLevel());
406 assertEquals("error.outOfRange", result.get(0).getMessage());
407 }
408
409
410
411
412 @Test
413 public void testValidate11() throws Exception {
414 System.out.println("check reference to a complex sub-structure (descr)");
415 DataDictionaryValidator.ValidationType validationType = null;
416 AcademicCalendarInfo acal = null;
417 ContextInfo context = null;
418
419 DataDictionaryValidator intstance = this.getValidator();
420 List<ValidationResultInfo> result = null;
421
422
423
424 validationType = DataDictionaryValidator.ValidationType.FULL_VALIDATION;
425 acal = this.getDefaultAcademicCalendarInfo();
426 context = getContext1();
427 acal.setDescr(new RichTextHelper().fromPlain("test acal description\n that is ok"));
428 result = intstance.validate(validationType, acal, context);
429 for (ValidationResult vri : result) {
430 System.out.println(vri.getElement() + " " + vri.getLevel() + " " + vri.getMessage());
431 }
432 assertEquals(0, result.size());
433 }
434
435
436
437
438 @Test
439 @Ignore
440 public void testValidate12() throws Exception {
441 System.out.println("check reference to a complex sub-structure (descr) with bad data in it");
442 DataDictionaryValidator.ValidationType validationType = null;
443 AcademicCalendarInfo acal = null;
444 ContextInfo context = null;
445
446 DataDictionaryValidator intstance = this.getValidator();
447 List<ValidationResultInfo> result = null;
448
449
450
451 validationType = DataDictionaryValidator.ValidationType.FULL_VALIDATION;
452 acal = this.getDefaultAcademicCalendarInfo();
453 context = getContext1();
454 acal.setDescr(new RichTextHelper().fromPlain("test acal description \nwith an invalid character tilde ~ in it"));
455 result = intstance.validate(validationType, acal, context);
456 for (ValidationResult vri : result) {
457 System.out.println(vri.getElement() + " " + vri.getLevel() + " " + vri.getMessage());
458 }
459
460 assertEquals(2, result.size());
461 assertEquals("descr.plain", result.get(0).getElement());
462 assertEquals(new Integer(2), result.get(0).getLevel());
463 assertEquals("error.invalidFormat", result.get(0).getMessage());
464 assertEquals("descr.formatted", result.get(1).getElement());
465 assertEquals(new Integer(2), result.get(1).getLevel());
466 assertEquals("error.invalidFormat", result.get(1).getMessage());
467 }
468
469
470
471
472
473 public void testValidate13() throws Exception {
474 System.out.println("check start date required if official");
475 DataDictionaryValidator.ValidationType validationType = null;
476 AcademicCalendarInfo acal = null;
477 ContextInfo context = null;
478
479 DataDictionaryValidator intstance = this.getValidator();
480 List<ValidationResultInfo> result = null;
481
482
483 validationType = DataDictionaryValidator.ValidationType.FULL_VALIDATION;
484 acal = this.getDefaultAcademicCalendarInfo();
485 acal.setStateKey(AcademicCalendarServiceConstants.ACADEMIC_CALENDAR_OFFICIAL_STATE_KEY);
486 acal.setStartDate(null);
487 context = getContext1();
488 result = intstance.validate(validationType, acal, context);
489 for (ValidationResult vri : result) {
490 System.out.println(vri.getElement() + " " + vri.getLevel() + " " + vri.getMessage());
491 }
492 assertEquals(1, result.size());
493 assertEquals("startDate", result.get(0).getElement());
494 assertEquals(new Integer(2), result.get(0).getLevel());
495 assertEquals("error.required", result.get(0).getMessage());
496 }
497
498
499
500
501
502 public void testValidate14() throws Exception {
503 System.out.println("validate null is not ok");
504 DataDictionaryValidator.ValidationType validationType = null;
505 AcademicCalendarInfo acal = null;
506 ContextInfo context = null;
507
508 DataDictionaryValidator intstance = this.getValidator();
509 List<ValidationResultInfo> result = null;
510
511
512 validationType = DataDictionaryValidator.ValidationType.FULL_VALIDATION;
513 acal = this.getDefaultAcademicCalendarInfo();
514 List<String> holidayCalendarIds = new ArrayList();
515 acal.setHolidayCalendarIds(holidayCalendarIds);
516 context = getContext1();
517 result = intstance.validate(validationType, acal, context);
518 for (ValidationResult vri : result) {
519 System.out.println(vri.getElement() + " " + vri.getLevel() + " " + vri.getMessage());
520 }
521 assertEquals(1, result.size());
522 }
523
524
525
526
527
528 public void testValidate15() throws Exception {
529 System.out.println("validate the empty list is not ok");
530 DataDictionaryValidator.ValidationType validationType = null;
531 AcademicCalendarInfo acal = null;
532 ContextInfo context = null;
533
534 DataDictionaryValidator intstance = this.getValidator();
535 List<ValidationResultInfo> result = null;
536
537
538 validationType = DataDictionaryValidator.ValidationType.FULL_VALIDATION;
539 acal = this.getDefaultAcademicCalendarInfo();
540 List<String> holidayCalendarIds = new ArrayList();
541 acal.setHolidayCalendarIds(holidayCalendarIds);
542 context = getContext1();
543 result = intstance.validate(validationType, acal, context);
544 for (ValidationResult vri : result) {
545 System.out.println(vri.getElement() + " " + vri.getLevel() + " " + vri.getMessage());
546 }
547 assertEquals(1, result.size());
548 }
549
550
551
552
553 @Test
554 public void testValidate16() throws Exception {
555 System.out.println("validate the single entry in list is ok");
556 DataDictionaryValidator.ValidationType validationType = null;
557 AcademicCalendarInfo acal = null;
558 ContextInfo context = null;
559
560 DataDictionaryValidator intstance = this.getValidator();
561 List<ValidationResultInfo> result = null;
562
563
564 validationType = DataDictionaryValidator.ValidationType.FULL_VALIDATION;
565 acal = this.getDefaultAcademicCalendarInfo();
566 List<String> holidayCalendarIds = new ArrayList();
567 holidayCalendarIds.add("holidayCalendarId1");
568 acal.setHolidayCalendarIds(holidayCalendarIds);
569 context = getContext1();
570 result = intstance.validate(validationType, acal, context);
571 for (ValidationResult vri : result) {
572 System.out.println(vri.getElement() + " " + vri.getLevel() + " " + vri.getMessage());
573 }
574 assertEquals(0, result.size());
575 }
576
577
578
579
580 @Test
581 public void testValidate17() throws Exception {
582 System.out.println("validate the two entries in list are ok");
583 DataDictionaryValidator.ValidationType validationType = null;
584 AcademicCalendarInfo acal = null;
585 ContextInfo context = null;
586
587 DataDictionaryValidator intstance = this.getValidator();
588 List<ValidationResultInfo> result = null;
589
590 validationType = DataDictionaryValidator.ValidationType.FULL_VALIDATION;
591 acal = this.getDefaultAcademicCalendarInfo();
592 List<String> holidayCalendarIds = new ArrayList();
593 holidayCalendarIds.add("holidayCalendarId1");
594 holidayCalendarIds.add("holidayCalendarId2");
595 acal.setHolidayCalendarIds(holidayCalendarIds);
596 context = getContext1();
597 result = intstance.validate(validationType, acal, context);
598 for (ValidationResult vri : result) {
599 System.out.println(vri.getElement() + " " + vri.getLevel() + " " + vri.getMessage());
600 }
601 assertEquals(0, result.size());
602 }
603
604
605
606
607
608 public void testValidate18() throws Exception {
609 System.out.println("validate the three entries in list are not ok");
610 DataDictionaryValidator.ValidationType validationType = null;
611 AcademicCalendarInfo acal = null;
612 ContextInfo context = null;
613
614 DataDictionaryValidator intstance = this.getValidator();
615 List<ValidationResultInfo> result = null;
616
617 validationType = DataDictionaryValidator.ValidationType.FULL_VALIDATION;
618 acal = this.getDefaultAcademicCalendarInfo();
619 List<String> holidayCalendarIds = new ArrayList();
620 holidayCalendarIds.add("holidayCalendarId1");
621 holidayCalendarIds.add("holidayCalendarId2");
622 holidayCalendarIds.add("holidayCalendarId3");
623 acal.setHolidayCalendarIds(holidayCalendarIds);
624 context = getContext1();
625 result = intstance.validate(validationType, acal, context);
626 for (ValidationResult vri : result) {
627 System.out.println(vri.getElement() + " " + vri.getLevel() + " " + vri.getMessage());
628 }
629 assertEquals(1, result.size());
630 }
631
632
633
634
635
636 public void testValidate19() throws Exception {
637 System.out.println("validate the keys cannot have new lines embedded in themn");
638 DataDictionaryValidator.ValidationType validationType = null;
639 AcademicCalendarInfo acal = null;
640 ContextInfo context = null;
641
642 DataDictionaryValidator intstance = this.getValidator();
643 List<ValidationResultInfo> result = null;
644
645 validationType = DataDictionaryValidator.ValidationType.FULL_VALIDATION;
646 acal = this.getDefaultAcademicCalendarInfo();
647 List<String> holidayCalendarIds = new ArrayList();
648 holidayCalendarIds.add("campusCa\nlendarKey1");
649 acal.setHolidayCalendarIds(holidayCalendarIds);
650 context = getContext1();
651 result = intstance.validate(validationType, acal, context);
652 for (ValidationResult vri : result) {
653 System.out.println(vri.getElement() + " " + vri.getLevel() + " " + vri.getMessage());
654 }
655 assertEquals(1, result.size());
656 }
657 }