1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.enrollment.class2.courseoffering.krms.service.impl;
17
18 import java.util.ArrayList;
19 import java.util.LinkedHashMap;
20 import java.util.List;
21 import java.util.Map;
22
23 import javax.annotation.Resource;
24
25 import org.junit.After;
26 import org.junit.Assert;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.kuali.rice.krms.api.engine.EngineResults;
31 import org.kuali.rice.krms.api.engine.ResultEvent;
32 import org.kuali.rice.krms.api.engine.TermResolver;
33 import org.kuali.rice.krms.framework.engine.AgendaTree;
34 import org.kuali.rice.krms.framework.engine.BasicAgenda;
35 import org.kuali.rice.krms.framework.engine.BasicAgendaTree;
36 import org.kuali.rice.krms.framework.engine.BasicAgendaTreeEntry;
37 import org.kuali.rice.krms.framework.engine.BasicRule;
38 import org.kuali.student.enrollment.class2.acal.krms.termresolver.AtpEndDateFieldTermResolver;
39 import org.kuali.student.enrollment.class2.acal.krms.termresolver.AtpStartDateFieldTermResolver;
40 import org.kuali.student.enrollment.class2.acal.krms.termresolver.AtpTermResolver;
41 import org.kuali.student.enrollment.academicrecord.dto.StudentCourseRecordInfo;
42 import org.kuali.student.enrollment.academicrecord.service.AcademicRecordService;
43 import org.kuali.student.r2.common.krms.data.KRMSEnrollmentEligibilityDataLoader;
44 import org.kuali.student.krms.mock.KRMSEngineService;
45 import org.kuali.student.enrollment.class2.courseoffering.krms.proposition.CompletedCourseBetweenTermsProposition;
46 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
47 import org.kuali.student.r2.common.exceptions.OperationFailedException;
48 import org.kuali.student.r2.core.constants.KSKRMSServiceConstants;
49 import org.kuali.student.r2.core.atp.service.AtpService;
50 import org.springframework.test.context.ContextConfiguration;
51 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
52
53
54
55
56
57
58
59 @RunWith(SpringJUnit4ClassRunner.class)
60 @ContextConfiguration(locations="classpath:krms-test-with-mocks-context.xml")
61 public class TestKRMSEnrollmentEligibility {
62
63 @Resource
64 private KRMSEngineService krmsServices;
65
66 @Resource
67 private KRMSEnrollmentEligibilityDataLoader dataLoader;
68
69 @Resource
70 private AtpService atpService;
71
72 @Resource
73 private AcademicRecordService recordService;
74
75
76
77
78
79 public TestKRMSEnrollmentEligibility() {
80
81 }
82
83
84 @Before
85 public void setup() throws Exception {
86
87 dataLoader.beforeTest();
88
89 krmsServices.initialize();
90 }
91
92 @After
93 public void afterTest() throws Exception {
94
95 dataLoader.afterTest();
96
97
98 }
99
100
101 @Test
102 public void testCompletedCourseBetweenTermsProposition() throws DoesNotExistException, OperationFailedException {
103
104
105 StudentCourseRecordInfo courseRecord = dataLoader.createStudentCourseRecord(KRMSEnrollmentEligibilityDataLoader.STUDENT_ONE_ID,
106 dataLoader.getFallTermId(), "ENGL123", "Comparative English Literature", "3.0", "1");
107
108 dataLoader.storeStudentCourseRecord(KRMSEnrollmentEligibilityDataLoader.STUDENT_ONE_ID, dataLoader.getFallTermId(), KRMSEnrollmentEligibilityDataLoader.FAKE_COURSE_ID, courseRecord);
109
110
111 AgendaTree agendaTree = new BasicAgendaTree(new BasicAgendaTreeEntry(new BasicRule(new CompletedCourseBetweenTermsProposition(atpService, recordService), null)));
112
113 Map<String, Object> executionFacts = new LinkedHashMap<String, Object>();
114
115
116 executionFacts.put(KSKRMSServiceConstants.TERM_TYPE_STUDENT_ID, KRMSEnrollmentEligibilityDataLoader.STUDENT_ONE_ID);
117
118
119 executionFacts.put(KSKRMSServiceConstants.TERM_TYPE_COURSE_ID, KRMSEnrollmentEligibilityDataLoader.FAKE_COURSE_ID);
120
121
122 executionFacts.put(KSKRMSServiceConstants.TERM_TYPE_START_DATE, KRMSEnrollmentEligibilityDataLoader.START_FALL_TERM_DATE);
123
124
125 executionFacts.put(KSKRMSServiceConstants.TERM_TYPE_END_DATE, KRMSEnrollmentEligibilityDataLoader.END_FALL_TERM_DATE);
126
127 EngineResults agendaResults = krmsServices.executeAgenda(new BasicAgenda(new LinkedHashMap<String, String>(), agendaTree), executionFacts);
128
129 List<ResultEvent> resultEvents = agendaResults.getAllResults();
130
131 for (ResultEvent event : resultEvents) {
132
133 Boolean result = event.getResult();
134
135 Assert.assertNotNull(result);
136 Assert.assertTrue(result);
137
138 }
139 }
140
141 @Test
142 public void testCompletedCourseBetweenTermsPropositionWithTermResolvers() throws DoesNotExistException, OperationFailedException {
143
144
145 StudentCourseRecordInfo courseRecord = dataLoader.createStudentCourseRecord(KRMSEnrollmentEligibilityDataLoader.STUDENT_ONE_ID,
146 dataLoader.getFallTermId(), "ENGL123", "Comparative English Literature", "3.0", "1");
147
148 dataLoader.storeStudentCourseRecord(KRMSEnrollmentEligibilityDataLoader.STUDENT_ONE_ID, dataLoader.getFallTermId(), KRMSEnrollmentEligibilityDataLoader.FAKE_COURSE_ID, courseRecord);
149
150
151 AgendaTree agendaTree = new BasicAgendaTree(new BasicAgendaTreeEntry(new BasicRule(new CompletedCourseBetweenTermsProposition(atpService, recordService), null)));
152
153 Map<String, Object> executionFacts = new LinkedHashMap<String, Object>();
154
155
156 executionFacts.put(KSKRMSServiceConstants.TERM_TYPE_STUDENT_ID, KRMSEnrollmentEligibilityDataLoader.STUDENT_ONE_ID);
157
158
159 executionFacts.put(KSKRMSServiceConstants.TERM_TYPE_COURSE_ID, KRMSEnrollmentEligibilityDataLoader.FAKE_COURSE_ID);
160
161
162
163
164
165
166
167 List<TermResolver<?>> termResolvers = new ArrayList<TermResolver<?>>();
168
169
170
171
172
173 AtpTermResolver fallTermResolver = new AtpTermResolver(KSKRMSServiceConstants.TERM_TYPE_CURRENT_TERM_ID, "testUser1", dataLoader.getFallTermId(), atpService);
174
175 termResolvers.add(fallTermResolver);
176
177
178
179
180 AtpStartDateFieldTermResolver fromResolver = new AtpStartDateFieldTermResolver(KSKRMSServiceConstants.TERM_TYPE_START_DATE, "testUser1");
181
182 termResolvers.add(fromResolver);
183
184
185
186 AtpEndDateFieldTermResolver toResolver = new AtpEndDateFieldTermResolver(KSKRMSServiceConstants.TERM_TYPE_END_DATE, "testUser1");
187
188
189 termResolvers.add(toResolver);
190
191 krmsServices.setTermResolvers(termResolvers);
192
193 EngineResults agendaResults = krmsServices.executeAgenda(new BasicAgenda(new LinkedHashMap<String, String>(), agendaTree), executionFacts);
194
195 List<ResultEvent> resultEvents = agendaResults.getAllResults();
196
197 for (ResultEvent event : resultEvents) {
198
199 Boolean result = event.getResult();
200
201 Assert.assertNotNull(result);
202 Assert.assertTrue(result);
203
204 }
205 }
206
207
208 }