1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.enrollment.class2.courseoffering.service.impl;
17
18 import org.apache.log4j.Logger;
19 import org.junit.After;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.junit.runner.RunWith;
23 import org.kuali.student.r2.common.datadictionary.DataDictionaryValidator;
24 import org.kuali.student.r2.common.dto.ContextInfo;
25 import org.kuali.student.r2.common.dto.ValidationResultInfo;
26 import org.kuali.student.r2.common.infc.ValidationResult;
27 import org.kuali.student.r2.common.util.RichTextHelper;
28 import org.kuali.student.r2.core.atp.dto.AtpInfo;
29 import org.kuali.student.r2.core.constants.AtpServiceConstants;
30 import org.springframework.context.ApplicationContext;
31 import org.springframework.context.support.ClassPathXmlApplicationContext;
32 import org.springframework.test.context.ContextConfiguration;
33 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
34
35 import javax.annotation.Resource;
36 import java.text.DateFormat;
37 import java.text.ParseException;
38 import java.text.SimpleDateFormat;
39 import java.util.Date;
40 import java.util.List;
41
42 import static org.junit.Assert.assertEquals;
43
44
45
46
47
48 @RunWith(SpringJUnit4ClassRunner.class)
49 @ContextConfiguration(locations = {"classpath:co-test-with-class2-mock-context.xml"})
50 public class TestRiceDataDictionaryValidatorImplAgainstAtp {
51 private static final Logger log = Logger.getLogger(TestRiceDataDictionaryValidatorImplAgainstAtp.class);
52
53 public ContextInfo callContext = null;
54
55 @Resource
56 protected DataDictionaryValidator validator;
57
58
59 public TestRiceDataDictionaryValidatorImplAgainstAtp() {
60 }
61
62 @Before
63 public void setup() throws Exception {
64 callContext = new ContextInfo();
65 callContext.setPrincipalId("principalId.1");
66 }
67
68 @After
69 public void tearDown() throws Exception {
70 }
71
72
73 private Date parseDate(String str) {
74 DateFormat df = new SimpleDateFormat("yyyy-mm-dd");
75 Date date = null;
76 try {
77 date = df.parse(str);
78 } catch (ParseException ex) {
79 throw new IllegalArgumentException(str, ex);
80 }
81 return date;
82 }
83
84 private AtpInfo getDefaultAtpInfo() {
85 AtpInfo atp = new AtpInfo();
86 atp.setId("org.kuali.test.atp");
87 atp.setName("test atp");
88 atp.setTypeKey(AtpServiceConstants.ATP_ACADEMIC_CALENDAR_TYPE_KEY);
89 atp.setStateKey(AtpServiceConstants.ATP_DRAFT_STATE_KEY);
90 atp.setStartDate(parseDate("2010-01-01"));
91 atp.setEndDate(parseDate("2010-06-30"));
92 return atp;
93 }
94
95
96
97
98
99
100 @Test
101 public void testValidate() throws Exception {
102
103 DataDictionaryValidator.ValidationType validationType = DataDictionaryValidator.ValidationType.FULL_VALIDATION;
104 AtpInfo atp = this.getDefaultAtpInfo();
105
106 List<ValidationResultInfo> result = validator.validate(validationType, atp, callContext);
107 assertEquals(0, result.size());
108
109
110 atp.setTypeKey(null);
111 result = validator.validate(validationType, atp, callContext);
112 assertEquals(1, result.size());
113 assertEquals("typeKey", result.get(0).getElement());
114 assertEquals(ValidationResult.ErrorLevel.ERROR, result.get(0).getLevel());
115 assertEquals("error.required", result.get(0).getMessage());
116
117
118 validationType = DataDictionaryValidator.ValidationType.SKIP_REQUREDNESS_VALIDATIONS;
119 result = validator.validate(validationType, atp, callContext);
120 assertEquals(0, result.size());
121 }
122 }