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.junit.After;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22 import org.kuali.student.r2.common.datadictionary.DataDictionaryValidator;
23 import org.kuali.student.r2.common.dto.ContextInfo;
24 import org.kuali.student.r2.common.dto.ValidationResultInfo;
25 import org.kuali.student.r2.common.infc.ValidationResult;
26 import org.kuali.student.r2.core.atp.dto.AtpInfo;
27 import org.kuali.student.r2.core.constants.AtpServiceConstants;
28 import org.springframework.test.context.ContextConfiguration;
29 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
30
31 import javax.annotation.Resource;
32 import java.text.DateFormat;
33 import java.text.SimpleDateFormat;
34 import java.util.Date;
35 import java.util.List;
36
37 import static org.junit.Assert.assertEquals;
38 import static org.junit.Assert.assertTrue;
39
40
41
42
43
44 @RunWith(SpringJUnit4ClassRunner.class)
45 @ContextConfiguration(locations = {"classpath:co-test-with-class2-mock-context.xml"})
46 public class TestRiceDataDictionaryValidatorImplAgainstAtp {
47 public ContextInfo callContext = null;
48
49 @Resource
50 protected DataDictionaryValidator validator;
51
52
53 public TestRiceDataDictionaryValidatorImplAgainstAtp() {
54 }
55
56 @Before
57 public void setup() throws Exception {
58 callContext = new ContextInfo();
59 callContext.setPrincipalId("principalId.1");
60 }
61
62 @After
63 public void tearDown() throws Exception {
64 }
65
66
67 private Date parseDate(String str) throws Exception {
68 DateFormat df = new SimpleDateFormat("yyyy-mm-dd");
69 return df.parse(str);
70 }
71
72 private AtpInfo getDefaultAtpInfo() throws Exception {
73 AtpInfo atp = new AtpInfo();
74 atp.setId("org.kuali.test.atp");
75 atp.setName("test atp");
76 atp.setTypeKey(AtpServiceConstants.ATP_ACADEMIC_CALENDAR_TYPE_KEY);
77 atp.setStateKey(AtpServiceConstants.ATP_DRAFT_STATE_KEY);
78 atp.setStartDate(parseDate("2010-01-01"));
79 atp.setEndDate(parseDate("2010-06-30"));
80 return atp;
81 }
82
83
84
85
86
87
88 @Test
89 public void testValidate() throws Exception {
90
91 DataDictionaryValidator.ValidationType validationType = DataDictionaryValidator.ValidationType.FULL_VALIDATION;
92 AtpInfo atp = this.getDefaultAtpInfo();
93
94 List<ValidationResultInfo> result = validator.validate(validationType, atp, callContext);
95 assertTrue(result.isEmpty());
96
97
98 atp.setTypeKey(null);
99 result = validator.validate(validationType, atp, callContext);
100 assertEquals(1, result.size());
101 assertEquals("typeKey", result.get(0).getElement());
102 assertEquals(ValidationResult.ErrorLevel.ERROR, result.get(0).getLevel());
103 assertEquals("error.required", result.get(0).getMessage());
104
105
106 validationType = DataDictionaryValidator.ValidationType.SKIP_REQUREDNESS_VALIDATIONS;
107 result = validator.validate(validationType, atp, callContext);
108 assertTrue(result.isEmpty());
109 }
110 }