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.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.courseoffering.dto.CourseOfferingInfo;
27 import org.kuali.student.r2.common.datadictionary.DataDictionaryValidator;
28 import org.kuali.student.r2.common.dto.ContextInfo;
29 import org.kuali.student.r2.common.dto.ValidationResultInfo;
30 import org.kuali.student.r2.common.infc.ValidationResult;
31 import org.kuali.student.r2.common.util.constants.LuiServiceConstants;
32 import org.springframework.context.ApplicationContext;
33 import org.springframework.context.support.ClassPathXmlApplicationContext;
34 import org.springframework.test.context.ContextConfiguration;
35 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
36 import sun.rmi.runtime.NewThreadAction;
37
38 import javax.annotation.Resource;
39 import java.io.IOException;
40 import java.text.DateFormat;
41 import java.text.ParseException;
42 import java.text.SimpleDateFormat;
43 import java.util.ArrayList;
44 import java.util.Date;
45 import java.util.List;
46
47 import static org.junit.Assert.assertEquals;
48
49
50
51
52
53 @RunWith(SpringJUnit4ClassRunner.class)
54 @ContextConfiguration(locations = {"classpath:co-test-with-class2-mock-context.xml"})
55 public class TestRiceDataDictionaryValidatorImplAgainstCourseOffering {
56
57 private static final Logger log = Logger.getLogger(TestRiceDataDictionaryValidatorImplAgainstCourseOffering.class);
58
59 private final boolean testAwareDataLoader;
60 public ContextInfo callContext = null;
61
62 @Resource
63 protected DataDictionaryValidator validator;
64
65 @Resource
66 protected CourseOfferingServiceTestDataLoader dataLoader;
67
68
69 public TestRiceDataDictionaryValidatorImplAgainstCourseOffering() {
70 this(true);
71 }
72
73 protected TestRiceDataDictionaryValidatorImplAgainstCourseOffering(boolean testAwareDataLoader) {
74 this.testAwareDataLoader = testAwareDataLoader;
75 }
76
77 protected Config getTestHarnessConfig() {
78 Config config = new JAXBConfigImpl(getConfigLocations(), System.getProperties());
79 try {
80 config.parseConfig();
81 } catch (IOException ex) {
82 throw new RuntimeException(ex);
83 }
84 return config;
85 }
86
87
88
89
90
91
92 protected List<String> getConfigLocations() {
93 List<String> configLocations = new ArrayList<String>();
94
95 return configLocations;
96 }
97
98 @Before
99 public void setup() throws Exception {
100 Config config = getTestHarnessConfig();
101 ConfigContext.init(config);
102
103 callContext = new ContextInfo();
104 callContext.setPrincipalId("principalId.1");
105
106 if (testAwareDataLoader || !dataLoader.isInitialized())
107 dataLoader.beforeTest();
108 }
109
110 @After
111 public void tearDown() throws Exception {
112 if (testAwareDataLoader)
113 dataLoader.afterTest();
114 }
115
116 private CourseOfferingInfo getDefaultCourseOfferingInfo() {
117 CourseOfferingInfo co = new CourseOfferingInfo();
118 return co;
119 }
120
121
122
123
124 @Test
125 public void testValidate1() throws Exception {
126 System.out.println("tests basic validation");
127 DataDictionaryValidator.ValidationType validationType = null;
128 CourseOfferingInfo co = new CourseOfferingInfo();
129 co.setTypeKey(LuiServiceConstants.COURSE_OFFERING_TYPE_KEY);
130 co.setStateKey(LuiServiceConstants.LUI_DRAFT_STATE_KEY);
131 co.setCourseId("fake-course-id");
132 co.setTermId("fake-term-key");
133 co.setGradingOptionId("fake-grading-option-id");
134 co.setCreditOptionId("fake-credit-option-id");
135
136 validationType = DataDictionaryValidator.ValidationType.FULL_VALIDATION;
137 List<ValidationResultInfo> result = validator.validate(validationType, co, callContext);
138 for (ValidationResult vri : result) {
139 System.out.println(vri.getElement() + " " + vri.getLevel() + " " + vri.getMessage());
140 }
141 assertEquals(0, result.size());
142
143 co.setGradingOptionId(null);
144 co.setCreditOptionId(null);
145 result = validator.validate(validationType, co, callContext);
146 for (ValidationResult vri : result) {
147 System.out.println(vri.getElement() + " " + vri.getLevel() + " " + vri.getMessage());
148 }
149 assertEquals(2, result.size());
150 }
151
152 }