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.AfterClass;
21 import org.junit.Before;
22 import org.junit.BeforeClass;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.kuali.rice.core.api.config.property.Config;
26 import org.kuali.rice.core.api.config.property.ConfigContext;
27 import org.kuali.rice.core.impl.config.property.JAXBConfigImpl;
28 import org.kuali.student.enrollment.lui.dto.LuiInfo;
29 import org.kuali.student.r2.common.datadictionary.DataDictionaryValidator;
30 import org.kuali.student.r2.common.dto.ContextInfo;
31 import org.kuali.student.r2.common.dto.ValidationResultInfo;
32 import org.kuali.student.r2.common.infc.ValidationResult;
33 import org.kuali.student.r2.common.util.constants.LuiServiceConstants;
34 import org.springframework.context.ApplicationContext;
35 import org.springframework.context.support.ClassPathXmlApplicationContext;
36 import org.springframework.test.context.ContextConfiguration;
37 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
38
39 import javax.annotation.Resource;
40 import java.io.IOException;
41 import java.text.DateFormat;
42 import java.text.ParseException;
43 import java.text.SimpleDateFormat;
44 import java.util.ArrayList;
45 import java.util.Date;
46 import java.util.List;
47
48 import static org.junit.Assert.assertEquals;
49
50
51
52
53
54
55 @RunWith(SpringJUnit4ClassRunner.class)
56 @ContextConfiguration(locations = {"classpath:co-test-with-class2-mock-context.xml"})
57 public class TestRiceDataDictionaryValidatorImplAgainstLui {
58 private static final Logger log = Logger.getLogger(TestRiceDataDictionaryValidatorImplAgainstLui.class);
59 public ContextInfo callContext = null;
60
61 @Resource
62 protected DataDictionaryValidator validator;
63
64 public TestRiceDataDictionaryValidatorImplAgainstLui() {
65 }
66
67 @Before
68 public void setup() throws Exception {
69 callContext = new ContextInfo();
70 callContext.setPrincipalId("principalId.1");
71 }
72
73 @After
74 public void tearDown() throws Exception {
75 }
76
77 private Date parseDate(String str) {
78 DateFormat df = new SimpleDateFormat("yyyy-mm-dd");
79 Date date = null;
80 try {
81 date = df.parse(str);
82 } catch (ParseException ex) {
83 throw new IllegalArgumentException(str, ex);
84 }
85 return date;
86 }
87
88 private LuiInfo getDefaultLuiInfo() {
89 LuiInfo lui = new LuiInfo();
90 lui.setName("test lui");
91 lui.setTypeKey(LuiServiceConstants.COURSE_OFFERING_TYPE_KEY);
92 lui.setStateKey(LuiServiceConstants.LUI_CO_STATE_DRAFT_KEY);
93 lui.setEffectiveDate(this.parseDate("2011-01-01"));
94 lui.setCluId("fake-clu-id");
95 lui.setAtpId("fake-atp-id");
96 return lui;
97 }
98
99
100
101
102 @Test
103 public void testValidate1() throws Exception {
104 DataDictionaryValidator.ValidationType validationType = DataDictionaryValidator.ValidationType.FULL_VALIDATION;
105 LuiInfo lui = this.getDefaultLuiInfo();
106
107 List<ValidationResultInfo> result = validator.validate(validationType, lui, callContext);
108 for (ValidationResultInfo r : result) {
109 System.out.println(r.getElement() + ", " + r.getLevel() + ", " + r.getMessage());
110 }
111 assertEquals(0, result.size());
112
113 lui.setTypeKey("");
114 result = validator.validate(validationType, lui, callContext);
115 assertEquals(1, result.size());
116 assertEquals("typeKey", result.get(0).getElement());
117 assertEquals(ValidationResult.ErrorLevel.ERROR, result.get(0).getLevel());
118
119 validationType = DataDictionaryValidator.ValidationType.SKIP_REQUREDNESS_VALIDATIONS;
120 result = validator.validate(validationType, lui, callContext);
121 assertEquals(0, result.size());
122 }
123 }