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 org.junit.After;
19 import org.junit.AfterClass;
20 import org.junit.Before;
21 import org.junit.BeforeClass;
22 import org.junit.Test;
23 import org.kuali.rice.core.api.config.property.Config;
24 import org.kuali.rice.core.api.config.property.ConfigContext;
25 import org.kuali.rice.core.impl.config.property.JAXBConfigImpl;
26 import org.kuali.student.enrollment.lui.dto.LuiInfo;
27 import org.kuali.student.r2.common.dto.ContextInfo;
28 import org.kuali.student.r2.common.dto.ValidationResultInfo;
29 import org.kuali.student.r2.common.infc.ValidationResult;
30 import org.kuali.student.r2.common.util.constants.LuiServiceConstants;
31 import org.springframework.context.ApplicationContext;
32 import org.springframework.context.support.ClassPathXmlApplicationContext;
33
34 import java.io.IOException;
35 import java.text.DateFormat;
36 import java.text.ParseException;
37 import java.text.SimpleDateFormat;
38 import java.util.ArrayList;
39 import java.util.Date;
40 import java.util.List;
41
42 import static org.junit.Assert.assertEquals;
43
44
45
46
47
48
49 public class TestRiceDataDictionaryValidatorImplAgainstLui {
50
51 public TestRiceDataDictionaryValidatorImplAgainstLui() {
52 }
53
54 @BeforeClass
55 public static void setUpClass() throws Exception {
56 }
57
58 @AfterClass
59 public static void tearDownClass() throws Exception {
60 }
61
62 protected Config getTestHarnessConfig() {
63 Config config = new JAXBConfigImpl(getConfigLocations(), System.getProperties());
64 try {
65 config.parseConfig();
66 } catch (IOException ex) {
67 throw new RuntimeException(ex);
68 }
69 return config;
70 }
71
72
73
74
75
76
77 protected List<String> getConfigLocations() {
78 List<String> configLocations = new ArrayList<String>();
79
80 return configLocations;
81 }
82
83 @Before
84 public void setUp() {
85 Config config = getTestHarnessConfig();
86 ConfigContext.init(config);
87 }
88
89 @After
90 public void tearDown() {
91 }
92
93 private Date parseDate(String str) {
94 DateFormat df = new SimpleDateFormat("yyyy-mm-dd");
95 Date date = null;
96 try {
97 date = df.parse(str);
98 } catch (ParseException ex) {
99 throw new IllegalArgumentException(str, ex);
100 }
101 return date;
102 }
103
104 private ContextInfo getContext1() {
105 return ContextInfo.getInstance("principalId.1", "en", "us");
106 }
107 private static DataDictionaryValidator validator;
108
109 public DataDictionaryValidator getValidator() {
110 if (validator == null) {
111 ApplicationContext appContext =
112 new ClassPathXmlApplicationContext(new String[]{"classpath:testContext.xml"});
113 this.validator = (DataDictionaryValidator) appContext.getBean("testValidator");
114 }
115 return validator;
116 }
117 private static DataDictionaryValidator validator2;
118 public DataDictionaryValidator getValidator2() {
119 if (validator2 == null) {
120 ApplicationContext appContext =
121 new ClassPathXmlApplicationContext(new String[]{"classpath:test2Context.xml"});
122 this.validator2 = (DataDictionaryValidator) appContext.getBean("testValidator");
123 }
124 return validator2;
125 }
126 private LuiInfo getDefaultLuiInfo() {
127 LuiInfo lui = new LuiInfo();
128 lui.setName("test lui");
129 lui.setTypeKey(LuiServiceConstants.COURSE_OFFERING_TYPE_KEY);
130 lui.setStateKey(LuiServiceConstants.LUI_DRAFT_STATE_KEY);
131 lui.setEffectiveDate(this.parseDate("2011-01-01"));
132 return lui;
133 }
134
135
136
137
138
139 public void testValidate1() throws Exception {
140 System.out.println("tests what I hoped to do -- define subobject field as required but object itself is missing so it should be checked");
141 DataDictionaryValidator.ValidationType validationType = null;
142 LuiInfo lui = null;
143 ContextInfo context = null;
144
145 DataDictionaryValidator intstance = this.getValidator();
146 List<ValidationResultInfo> result = null;
147
148 validationType = DataDictionaryValidator.ValidationType.FULL_VALIDATION;
149 lui = this.getDefaultLuiInfo();
150 context = getContext1();
151 result = intstance.validate(validationType, lui, context);
152 for (ValidationResult vri : result) {
153 System.out.println(vri.getElement() + " " + vri.getLevel() + " " + vri.getMessage());
154 }
155 assertEquals(0, result.size());
156 }
157
158
159
160
161 @Test
162 public void testValidate2() throws Exception {
163 System.out.println("test using the ComplexAttributeDefinition to hold the definition");
164 DataDictionaryValidator.ValidationType validationType = null;
165 LuiInfo lui = null;
166 ContextInfo context = null;
167
168 DataDictionaryValidator intstance = this.getValidator2();
169 List<ValidationResultInfo> result = null;
170
171 validationType = DataDictionaryValidator.ValidationType.FULL_VALIDATION;
172 lui = this.getDefaultLuiInfo();
173 context = getContext1();
174 result = intstance.validate(validationType, lui, context);
175 for (ValidationResult vri : result) {
176 System.out.println(vri.getElement() + " " + vri.getLevel() + " " + vri.getMessage());
177 }
178 assertEquals(0, result.size());
179 }
180 }