1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.student.enrollment.class2.acal.service.impl;
18
19 import org.junit.After;
20 import org.junit.Before;
21 import org.junit.Ignore;
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.kuali.student.common.test.spring.log4j.KSLog4JConfigurer;
25 import org.kuali.student.enrollment.class2.courseoffering.service.adapter.AutogenRegGroupServiceAdapter;
26 import org.kuali.student.enrollment.class2.courseoffering.service.impl.CourseOfferingServiceTestDataLoader;
27 import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
28 import org.kuali.student.r2.common.dto.ContextInfo;
29 import org.kuali.student.r2.common.dto.StatusInfo;
30 import org.kuali.student.r2.common.exceptions.AlreadyExistsException;
31 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
32 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
33 import org.kuali.student.r2.common.exceptions.MissingParameterException;
34 import org.kuali.student.r2.common.exceptions.OperationFailedException;
35 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
36 import org.kuali.student.r2.core.acal.dto.AcademicCalendarInfo;
37 import org.kuali.student.r2.core.acal.dto.TermInfo;
38 import org.kuali.student.r2.core.acal.service.AcademicCalendarService;
39 import org.kuali.student.r2.core.acal.service.facade.AcademicCalendarServiceFacade;
40 import org.kuali.student.r2.core.acal.service.facade.AcademicCalendarServiceFacadeImpl;
41 import org.kuali.student.r2.core.atp.service.AtpService;
42 import org.kuali.student.r2.core.constants.AtpServiceConstants;
43 import org.kuali.student.r2.lum.course.service.CourseService;
44 import org.kuali.student.r2.lum.lrc.service.LRCService;
45 import org.slf4j.Logger;
46 import org.springframework.test.context.ContextConfiguration;
47 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
48
49 import javax.annotation.Resource;
50 import java.util.Date;
51
52 import static junit.framework.Assert.assertEquals;
53 import static junit.framework.Assert.assertFalse;
54 import static junit.framework.Assert.assertTrue;
55
56
57
58
59
60
61 @RunWith(SpringJUnit4ClassRunner.class)
62 @ContextConfiguration(locations = {"classpath:acal-service-facade-test-class2-mock-context.xml"})
63 public class TestAcademicCalendarServiceFacadeImpl {
64 private static final Logger log = KSLog4JConfigurer
65 .getLogger(TestAcademicCalendarServiceFacadeImpl.class);
66
67 @Resource(name="CourseOfferingService")
68 protected CourseOfferingService coService;
69
70 @Resource
71 protected CourseService courseService;
72
73 @Resource
74 protected CourseOfferingServiceTestDataLoader dataLoader;
75
76 @Resource(name = "LrcService")
77 protected LRCService lrcService;
78
79 @Resource
80 protected AcademicCalendarService acalService;
81
82 @Resource
83 protected AtpService atpService;
84
85 @Resource
86 private AcademicCalendarServiceFacade acalServiceFacade;
87
88
89 private ContextInfo contextInfo;
90 private AcademicCalendarInfo cal;
91 private TermInfo parentTerm;
92 private TermInfo childTerm;
93 private TermInfo childTerm2;
94
95 public TestAcademicCalendarServiceFacadeImpl() {
96 }
97
98 @Before
99 public void beforeTest() throws Exception {
100 dataLoader.beforeTest();
101
102 contextInfo = new ContextInfo();
103
104 contextInfo.setCurrentDate(new Date());
105
106 contextInfo.setPrincipalId("test");
107 contextInfo.setAuthenticatedPrincipalId("test");
108
109
110 cal = new AcademicCalendarInfo();
111 cal.setStateKey(AtpServiceConstants.ATP_DRAFT_STATE_KEY);
112 cal.setTypeKey(AtpServiceConstants.ATP_ACADEMIC_CALENDAR_TYPE_KEY);
113 cal = acalService.createAcademicCalendar(cal.getTypeKey(), cal, contextInfo);
114
115 parentTerm = new TermInfo();
116 parentTerm.setTypeKey(AtpServiceConstants.ATP_FALL_TYPE_KEY);
117 parentTerm.setStateKey(AtpServiceConstants.ATP_DRAFT_STATE_KEY);
118 parentTerm = acalService.createTerm(parentTerm.getTypeKey(), parentTerm, contextInfo);
119
120 acalService.addTermToAcademicCalendar(cal.getId(), parentTerm.getId(), contextInfo);
121
122 childTerm = new TermInfo();
123 childTerm.setTypeKey(AtpServiceConstants.ATP_HALF_FALL_1_TYPE_KEY);
124 childTerm.setStateKey(AtpServiceConstants.ATP_DRAFT_STATE_KEY);
125 childTerm = acalService.createTerm(childTerm.getTypeKey(), childTerm, contextInfo);
126
127 acalService.addTermToTerm(parentTerm.getId(), childTerm.getId(), contextInfo);
128
129 childTerm2 = new TermInfo();
130 childTerm2.setTypeKey(AtpServiceConstants.ATP_HALF_FALL_2_TYPE_KEY);
131 childTerm2.setStateKey(AtpServiceConstants.ATP_DRAFT_STATE_KEY);
132 childTerm2 = acalService.createTerm(childTerm2.getTypeKey(), childTerm2, contextInfo);
133
134 acalService.addTermToTerm(parentTerm.getId(), childTerm2.getId(), contextInfo);
135 }
136
137 @After
138 public void afterTest() throws Exception {
139 dataLoader.afterTest();
140 }
141
142 @Test
143 public void testMakeTermOfficialCascaded() throws Exception {
144
145 acalServiceFacade.makeTermOfficialCascaded(childTerm.getId(), contextInfo);
146
147 cal = acalService.getAcademicCalendar(cal.getId(), contextInfo);
148 parentTerm = acalService.getTerm(parentTerm.getId(), contextInfo);
149 childTerm = acalService.getTerm(childTerm.getId(), contextInfo);
150 childTerm2 = acalService.getTerm(childTerm2.getId(), contextInfo);
151 assertEquals(AtpServiceConstants.ATP_OFFICIAL_STATE_KEY, cal.getStateKey());
152 assertEquals(AtpServiceConstants.ATP_OFFICIAL_STATE_KEY, parentTerm.getStateKey());
153 assertEquals(AtpServiceConstants.ATP_OFFICIAL_STATE_KEY, childTerm.getStateKey());
154
155 assertEquals(AtpServiceConstants.ATP_DRAFT_STATE_KEY, childTerm2.getStateKey());
156 }
157
158 @Test
159 public void testDeleteTermSucceed() throws Exception {
160
161 StatusInfo statusInfo = acalServiceFacade.deleteTermCascaded(parentTerm.getId(), contextInfo);
162 assert(statusInfo.getIsSuccess());
163 boolean threwException = false;
164 try {
165 acalService.getTerm(parentTerm.getId(), contextInfo);
166 } catch (DoesNotExistException e) {
167 threwException = true;
168 }
169 assert(threwException);
170
171 threwException = false;
172 try {
173 acalService.getTerm(childTerm.getId(), contextInfo);
174 } catch (DoesNotExistException e) {
175 threwException = true;
176 }
177 assert(threwException);
178
179 threwException = false;
180 try {
181 acalService.getTerm(childTerm2.getId(), contextInfo);
182 } catch (DoesNotExistException e) {
183 threwException = true;
184 }
185 assert(threwException);
186 }
187
188 @Test
189 public void testDeleteTermFailed() throws Exception {
190 boolean threwException = false;
191
192 acalServiceFacade.makeTermOfficialCascaded(parentTerm.getId(), contextInfo);
193 try {
194 StatusInfo statusInfo = acalServiceFacade.deleteTermCascaded(parentTerm.getId(), contextInfo);
195 } catch (OperationFailedException e) {
196 threwException = true;
197 }
198 assert(threwException);
199
200 threwException = false;
201 try {
202 acalService.getTerm(parentTerm.getId(), contextInfo);
203 } catch (DoesNotExistException e) {
204 threwException = true;
205 }
206 assert(!threwException);
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228 }
229
230 private TermInfo _setup2(int level) throws Exception {
231
232 TermInfo subSubTerm = new TermInfo();
233 subSubTerm.setTypeKey(AtpServiceConstants.ATP_HALF_FALL_2_TYPE_KEY);
234 subSubTerm.setStateKey(AtpServiceConstants.ATP_DRAFT_STATE_KEY);
235 subSubTerm = acalService.createTerm(subSubTerm.getTypeKey(), subSubTerm, contextInfo);
236 acalService.addTermToTerm(childTerm2.getId(), subSubTerm.getId(), contextInfo);
237 if (level == 0) {
238 acalService.changeTermState(parentTerm.getId(), AtpServiceConstants.ATP_OFFICIAL_STATE_KEY, contextInfo);
239 } else if (level == 1) {
240 acalService.changeTermState(childTerm.getId(), AtpServiceConstants.ATP_OFFICIAL_STATE_KEY, contextInfo);
241 } else if (level == 2) {
242 acalService.changeTermState(childTerm2.getId(), AtpServiceConstants.ATP_OFFICIAL_STATE_KEY, contextInfo);
243 } else if (level == 3) {
244 acalService.changeTermState(subSubTerm.getId(), AtpServiceConstants.ATP_OFFICIAL_STATE_KEY, contextInfo);
245 }
246 return subSubTerm;
247 }
248
249 @Test
250 public void testValidateTerm0() throws Exception {
251 _setup2(0);
252
253 assertTrue(acalServiceFacade.validateTerm(parentTerm.getId(), contextInfo));
254
255 }
256
257 @Test
258 public void testValidateTerm1() throws Exception {
259 _setup2(1);
260
261 assertFalse(acalServiceFacade.validateTerm(parentTerm.getId(), contextInfo));
262 }
263
264 @Test
265 public void testValidateTerm2() throws Exception {
266 _setup2(2);
267
268 assertFalse(acalServiceFacade.validateTerm(parentTerm.getId(), contextInfo));
269 }
270
271 @Test
272 public void testValidateTerm3() throws Exception {
273 _setup2(3);
274
275 assertFalse(acalServiceFacade.validateTerm(parentTerm.getId(), contextInfo));
276 }
277
278 @Test
279 public void testValidateCalendar0() throws Exception {
280 _setup2(0);
281
282
283 assertFalse(acalServiceFacade.validateCalendar(cal.getId(), contextInfo));
284 acalService.changeAcademicCalendarState(cal.getId(), AtpServiceConstants.ATP_OFFICIAL_STATE_KEY, contextInfo);
285 assertTrue(acalServiceFacade.validateCalendar(cal.getId(), contextInfo));
286 }
287
288 @Test
289 public void testValidateCalendar1() throws Exception {
290 _setup2(1);
291
292 assertFalse(acalServiceFacade.validateTerm(parentTerm.getId(), contextInfo));
293 acalService.changeAcademicCalendarState(cal.getId(), AtpServiceConstants.ATP_OFFICIAL_STATE_KEY, contextInfo);
294 assertFalse(acalServiceFacade.validateCalendar(cal.getId(), contextInfo));
295 }
296
297 @Test
298 public void testValidateCalendar2() throws Exception {
299 _setup2(2);
300
301 assertFalse(acalServiceFacade.validateTerm(parentTerm.getId(), contextInfo));
302 acalService.changeAcademicCalendarState(cal.getId(), AtpServiceConstants.ATP_OFFICIAL_STATE_KEY, contextInfo);
303 assertFalse(acalServiceFacade.validateCalendar(cal.getId(), contextInfo));
304 }
305
306 @Test
307 public void testValidateCalendar3() throws Exception {
308 _setup2(3);
309
310 assertFalse(acalServiceFacade.validateTerm(parentTerm.getId(), contextInfo));
311 acalService.changeAcademicCalendarState(cal.getId(), AtpServiceConstants.ATP_OFFICIAL_STATE_KEY, contextInfo);
312 assertFalse(acalServiceFacade.validateCalendar(cal.getId(), contextInfo));
313 }
314
315 @Test
316 public void testValidateCalendar4() throws Exception {
317 _setup2(4);
318
319 assertTrue(acalServiceFacade.validateTerm(parentTerm.getId(), contextInfo));
320 acalService.changeAcademicCalendarState(cal.getId(), AtpServiceConstants.ATP_OFFICIAL_STATE_KEY, contextInfo);
321 assertTrue(acalServiceFacade.validateCalendar(cal.getId(), contextInfo));
322 }
323 }