1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.enrollment.class2.courseofferingset.service.impl;
17
18 import org.junit.Before;
19 import org.junit.Ignore;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22 import org.kuali.student.r2.core.acal.service.AcademicCalendarService;
23 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo;
24 import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
25 import org.kuali.student.enrollment.courseofferingset.service.CourseOfferingSetService;
26 import org.kuali.student.r2.common.dto.ContextInfo;
27 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
28 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
29 import org.kuali.student.r2.common.exceptions.MissingParameterException;
30 import org.kuali.student.r2.common.exceptions.OperationFailedException;
31 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
32 import org.kuali.student.r2.common.util.constants.CourseOfferingServiceConstants;
33 import org.kuali.student.r2.common.util.constants.LuiServiceConstants;
34 import org.kuali.student.r2.core.atp.service.AtpService;
35 import org.kuali.student.r2.core.scheduling.dto.ScheduleComponentInfo;
36 import org.kuali.student.r2.core.scheduling.dto.ScheduleInfo;
37 import org.kuali.student.r2.core.scheduling.dto.ScheduleRequestComponentInfo;
38 import org.kuali.student.r2.core.scheduling.dto.ScheduleRequestInfo;
39 import org.kuali.student.r2.core.scheduling.service.SchedulingService;
40 import org.kuali.student.r2.lum.course.service.CourseService;
41 import org.springframework.test.context.ContextConfiguration;
42 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
43 import org.springframework.test.context.transaction.TransactionConfiguration;
44 import org.springframework.transaction.annotation.Transactional;
45
46 import javax.annotation.Resource;
47 import java.util.List;
48
49 import static org.junit.Assert.assertEquals;
50 import static org.junit.Assert.assertFalse;
51 import static org.junit.Assert.assertNotNull;
52 import static org.junit.Assert.assertNull;
53 import static org.junit.Assert.assertTrue;
54
55
56
57
58
59
60 @Ignore
61 @RunWith(SpringJUnit4ClassRunner.class)
62 @ContextConfiguration(locations = {"classpath:scheduling-runner-test-context.xml"})
63 @TransactionConfiguration(transactionManager = "JtaTxManager", defaultRollback = true)
64 @Transactional
65 public class TestCourseOfferingSetSchedulingRunner {
66
67 @Resource(name = "socService")
68 private CourseOfferingSetService socService;
69
70 @Resource(name = "coService")
71 private CourseOfferingService coService;
72
73 @Resource(name = "schedulingService")
74 private SchedulingService schedulingService;
75
76 @Resource
77 private AcademicCalendarService acalService;
78
79 @Resource
80 private AtpService atpService;
81
82 @Resource
83 private CourseService canonicalCourseService;
84
85 @Resource
86 private CourseOfferingSetSchedulingRunnerDataLoader dataLoader;
87
88 public static String principalId = "123";
89 public ContextInfo callContext = null;
90 private String socId;
91
92
93 @Before
94 public void setUp() {
95 principalId = "123";
96 callContext = new ContextInfo();
97 callContext.setPrincipalId(principalId);
98
99 dataLoader.setContext(callContext);
100
101 try {
102 dataLoader.beforeTest();
103 } catch (Exception ex) {
104 throw new RuntimeException(ex);
105 }
106
107 socId = dataLoader.getSocId();
108 }
109
110
111
112 @Test
113 public void testSchedulingRunner() throws InvalidParameterException, MissingParameterException, DoesNotExistException, PermissionDeniedException, OperationFailedException {
114 CourseOfferingSetSchedulingRunner runner = new CourseOfferingSetSchedulingRunner(socId);
115
116 runner.setContextInfo(callContext);
117 runner.setCoService(coService);
118 runner.setSocService(socService);
119 runner.setSchedulingService(schedulingService);
120
121 System.out.println("RUNNER RUNNING");
122 runner.run();
123 System.out.println("RUNNER COMPLETED");
124
125
126 ActivityOfferingInfo scheduledAo = coService.getActivityOffering(CourseOfferingSetSchedulingRunnerDataLoader.SCHEDULED_AO_ID, callContext);
127 assertNotNull(scheduledAo.getScheduleId());
128 assertEquals(LuiServiceConstants.LUI_AO_SCHEDULING_STATE_SCHEDULED_KEY, scheduledAo.getSchedulingStateKey());
129
130 ScheduleInfo schedule = schedulingService.getSchedule(scheduledAo.getScheduleId(), callContext);
131 assertNotNull(schedule);
132 assertEquals(2, schedule.getScheduleComponents().size());
133
134
135 ScheduleComponentInfo tbaComp = null, nonTbaComp = null;
136 for (ScheduleComponentInfo sci : schedule.getScheduleComponents()) {
137 if(sci.getIsTBA()) {
138 tbaComp = sci;
139 }
140 else {
141 nonTbaComp = sci;
142 }
143 }
144
145 assertNotNull(tbaComp);
146 assertNotNull(nonTbaComp);
147
148 assertFalse(nonTbaComp.getIsTBA());
149 assertEquals(1, nonTbaComp.getTimeSlotIds().size());
150 assertTrue(nonTbaComp.getTimeSlotIds().contains(CourseOfferingSetSchedulingRunnerDataLoader.TIME_SLOT_1_ID));
151 assertEquals(CourseOfferingSetSchedulingRunnerDataLoader.ROOM_ID, nonTbaComp.getRoomId());
152
153 assertTrue(tbaComp.getIsTBA());
154 assertTrue(tbaComp.getTimeSlotIds().contains(CourseOfferingSetSchedulingRunnerDataLoader.TIME_SLOT_2_ID));
155 assertEquals(CourseOfferingSetSchedulingRunnerDataLoader.ROOM_ID, tbaComp.getRoomId());
156
157
158 List<String> requestIds = schedulingService.getScheduleRequestIdsByRefObject(CourseOfferingServiceConstants.REF_OBJECT_URI_ACTIVITY_OFFERING, scheduledAo.getId(), callContext);
159 assertEquals(1, requestIds.size());
160
161
162 ActivityOfferingInfo exemptAo = coService.getActivityOffering(CourseOfferingSetSchedulingRunnerDataLoader.EXEMPT_AO_ID, callContext);
163 assertEquals(LuiServiceConstants.LUI_AO_SCHEDULING_STATE_EXEMPT_KEY, exemptAo.getSchedulingStateKey());
164 assertNotNull(exemptAo.getScheduleId());
165
166 ScheduleInfo exemptSchedule = schedulingService.getSchedule(exemptAo.getScheduleId(), callContext);
167 assertNotNull(exemptSchedule);
168 assertFalse(exemptSchedule.getScheduleComponents().isEmpty());
169 ScheduleComponentInfo exemptComponent = exemptSchedule.getScheduleComponents().get(0);
170
171 assertTrue(exemptComponent.getIsTBA());
172 assertEquals(1, exemptComponent.getTimeSlotIds().size());
173 assertTrue(exemptComponent.getTimeSlotIds().contains(CourseOfferingSetSchedulingRunnerDataLoader.TIME_SLOT_2_ID));
174 assertEquals(CourseOfferingSetSchedulingRunnerDataLoader.ROOM_ID, exemptComponent.getRoomId());
175
176
177 requestIds = schedulingService.getScheduleRequestIdsByRefObject(CourseOfferingServiceConstants.REF_OBJECT_URI_ACTIVITY_OFFERING, exemptAo.getId(), callContext);
178 assertEquals(1, requestIds.size());
179
180
181
182 ActivityOfferingInfo draftAo = coService.getActivityOffering(CourseOfferingSetSchedulingRunnerDataLoader.DRAFT_AO_ID, callContext);
183 assertEquals(LuiServiceConstants.LUI_AO_SCHEDULING_STATE_UNSCHEDULED_KEY, draftAo.getSchedulingStateKey());
184 assertNull(draftAo.getScheduleId());
185
186
187 List<ScheduleRequestInfo> draftRequests = schedulingService.getScheduleRequestsByRefObject(CourseOfferingServiceConstants.REF_OBJECT_URI_ACTIVITY_OFFERING, draftAo.getId(), callContext);
188 assertEquals(1, draftRequests.size());
189 ScheduleRequestInfo draftReq = draftRequests.get(0);
190 assertEquals(draftAo.getId(), draftReq.getRefObjectId());
191
192 assertEquals(1, draftReq.getScheduleRequestComponents().size());
193 ScheduleRequestComponentInfo draftReqComp = draftReq.getScheduleRequestComponents().get(0);
194 assertEquals(false, draftReqComp.getIsTBA());
195 assertTrue(draftReqComp.getTimeSlotIds().contains(CourseOfferingSetSchedulingRunnerDataLoader.TIME_SLOT_1_ID));
196 }
197
198
199 }