1 package org.kuali.student.enrollment.class2.courseoffering.service.impl;
2
3 import org.junit.Before;
4 import org.junit.Test;
5 import org.junit.runner.RunWith;
6 import org.kuali.student.enrollment.class2.acal.util.MockAcalTestDataLoader;
7 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo;
8 import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
9 import org.kuali.student.enrollment.courseoffering.dto.FormatOfferingInfo;
10 import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
11 import org.kuali.student.enrollment.courseofferingset.dto.SocRolloverResultItemInfo;
12 import org.kuali.student.r2.common.dto.ContextInfo;
13 import org.kuali.student.r2.common.exceptions.AlreadyExistsException;
14 import org.kuali.student.r2.common.exceptions.DataValidationErrorException;
15 import org.kuali.student.r2.common.exceptions.DependentObjectsExistException;
16 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
17 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
18 import org.kuali.student.r2.common.exceptions.MissingParameterException;
19 import org.kuali.student.r2.common.exceptions.OperationFailedException;
20 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
21 import org.kuali.student.r2.common.exceptions.ReadOnlyException;
22 import org.kuali.student.r2.common.exceptions.VersionMismatchException;
23 import org.kuali.student.r2.common.util.ContextUtils;
24 import org.kuali.student.r2.common.util.RichTextHelper;
25 import org.kuali.student.r2.common.util.constants.LuServiceConstants;
26 import org.kuali.student.r2.common.util.constants.LuiServiceConstants;
27 import org.kuali.student.r2.core.acal.dto.TermInfo;
28 import org.kuali.student.r2.core.acal.service.AcademicCalendarService;
29 import org.kuali.student.r2.core.atp.dto.AtpInfo;
30 import org.kuali.student.r2.core.atp.service.AtpService;
31 import org.kuali.student.r2.core.constants.AtpServiceConstants;
32 import org.kuali.student.r2.core.scheduling.constants.SchedulingServiceConstants;
33 import org.kuali.student.r2.core.scheduling.dto.ScheduleInfo;
34 import org.kuali.student.r2.core.scheduling.service.SchedulingService;
35 import org.kuali.student.r2.lum.course.dto.ActivityInfo;
36 import org.kuali.student.r2.lum.course.dto.CourseInfo;
37 import org.kuali.student.r2.lum.course.dto.FormatInfo;
38 import org.kuali.student.r2.lum.course.service.CourseService;
39 import org.springframework.test.context.ContextConfiguration;
40 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
41
42 import javax.annotation.Resource;
43 import java.util.ArrayList;
44 import java.util.List;
45
46 import static org.junit.Assert.assertEquals;
47 import static org.junit.Assert.assertNotNull;
48
49 @RunWith(SpringJUnit4ClassRunner.class)
50 @ContextConfiguration(locations = {"classpath:co-businesslogic-test-with-mocks-context.xml"})
51 public class TestCourseOfferingServiceBusinessLogicWithMocks {
52
53 @Resource(name = "coService")
54 private CourseOfferingService coService;
55 public static String principalId = "123";
56 public ContextInfo callContext = null;
57 @Resource(name = "courseService")
58 private CourseService courseService;
59 @Resource(name = "acalService")
60 private AcademicCalendarService acalService;
61 @Resource(name = "schedulingService")
62 private SchedulingService schedulingService;
63 @Resource(name = "atpService")
64 private AtpService atpService;
65 @Before
66 public void setUp() {
67 callContext = new ContextInfo();
68 callContext.setPrincipalId(principalId);
69
70
71
72
73
74
75
76 }
77
78 @Test
79 public void testRollover() throws DoesNotExistException,
80 DataValidationErrorException, InvalidParameterException, MissingParameterException,
81 OperationFailedException, PermissionDeniedException, ReadOnlyException, VersionMismatchException,
82 DependentObjectsExistException, AlreadyExistsException {
83 MockAcalTestDataLoader acalLoader = new MockAcalTestDataLoader(this.acalService);
84 acalLoader.loadTerm("2011SP", "Spring 2011", "2011-03-01 00:00:00.0", "2011-05-31 00:00:00.0", AtpServiceConstants.ATP_SPRING_TYPE_KEY, AtpServiceConstants.ATP_OFFICIAL_STATE_KEY, "Spring Term 2011"
85 );
86 acalLoader.loadTerm("2011FA", "Fall 2011", "2011-09-01 00:00:00.0", "2011-12-31 00:00:00.0", AtpServiceConstants.ATP_FALL_TYPE_KEY, AtpServiceConstants.ATP_OFFICIAL_STATE_KEY, "Fall Term 2011"
87 );
88 acalLoader.loadTerm("2012SP", "Spring 2012", "2012-03-01 00:00:00.0", "2012-05-31 00:00:00.0", AtpServiceConstants.ATP_SPRING_TYPE_KEY, AtpServiceConstants.ATP_OFFICIAL_STATE_KEY, "Spring Term 2012"
89 );
90 acalLoader.loadTerm("2012FA", "Fall 2012", "2012-09-01 00:00:00.0", "2012-12-31 00:00:00.0", AtpServiceConstants.ATP_FALL_TYPE_KEY, AtpServiceConstants.ATP_OFFICIAL_STATE_KEY, "Fall Term 2012"
91 );
92 acalLoader.loadTerm("2013SP", "Spring 2013", "2013-03-01 00:00:00.0", "2013-05-31 00:00:00.0", AtpServiceConstants.ATP_SPRING_TYPE_KEY, AtpServiceConstants.ATP_OFFICIAL_STATE_KEY, "Spring Term 2013"
93 );
94
95 CourseR1TestDataLoader courseLoader = new CourseR1TestDataLoader(this.courseService);
96 courseLoader.loadCourse("COURSE1", "2012FA", "CHEM", "CHEM123", "Chemistry 123", "description 1", "COURSE1-FORMAT1",
97 LuServiceConstants.COURSE_ACTIVITY_LECTURE_TYPE_KEY, LuServiceConstants.COURSE_ACTIVITY_LAB_TYPE_KEY);
98 courseLoader.loadCourse("COURSE2", "2012SP", "ENG", "ENG101", "Intro English", "description 2", "COURSE2-FORMAT1",
99 LuServiceConstants.COURSE_ACTIVITY_LECTURE_TYPE_KEY, null);
100
101 AtpInfo atp = new AtpInfo();
102 atp.setTypeKey(AtpServiceConstants.ATP_FALL_TYPE_KEY);
103 atp.setId("2011FA");
104 atpService.createAtp(atp.getTypeKey(),atp,callContext);
105 atp = new AtpInfo();
106 atp.setTypeKey(AtpServiceConstants.ATP_FALL_TYPE_KEY);
107 atp.setId("2012FA");
108 atpService.createAtp(atp.getTypeKey(),atp,callContext);
109
110
111 CourseInfo course;
112 try {
113 course = courseService.getCourse("COURSE1", ContextUtils.getContextInfo());
114 } catch (Exception ex) {
115 throw new RuntimeException(ex);
116 }
117 TermInfo sourceTerm = acalService.getTerm("2012FA", callContext);
118
119 List<String> optionKeys = new ArrayList<String>();
120 CourseOfferingInfo sourceCo = new CourseOfferingInfo();
121 sourceCo.setCourseId(course.getId());
122 sourceCo.setTermId(sourceTerm.getId());
123 sourceCo.setTypeKey(LuiServiceConstants.COURSE_OFFERING_TYPE_KEY);
124 sourceCo.setStateKey(LuiServiceConstants.LUI_CO_STATE_OFFERED_KEY);
125 sourceCo = coService.createCourseOffering(sourceCo.getCourseId(), sourceCo.getTermId(),
126 sourceCo.getTypeKey(), sourceCo, optionKeys, callContext);
127
128 FormatInfo format = course.getFormats().get(0);
129 FormatOfferingInfo sourceFo = new FormatOfferingInfo ();
130 sourceFo.setTypeKey(LuiServiceConstants.FORMAT_OFFERING_TYPE_KEY);
131 sourceFo.setStateKey(LuiServiceConstants.LUI_FO_STATE_OFFERED_KEY);
132 sourceFo.setCourseOfferingId(sourceCo.getId());
133 sourceFo.setDescr(new RichTextHelper ().fromPlain ("test format offering"));
134 sourceFo.setFormatId(format.getId());
135 sourceFo.setName("format offering 1");
136 sourceFo.setTermId(sourceCo.getTermId());
137 sourceFo = coService.createFormatOffering(sourceFo.getCourseOfferingId(), sourceFo.getFormatId(),
138 sourceFo.getTypeKey(), sourceFo, callContext);
139
140 ActivityInfo activity = format.getActivities().get(0);
141 ActivityOfferingInfo sourceAo = new ActivityOfferingInfo ();
142 sourceAo.setFormatOfferingId(sourceFo.getId());
143 sourceAo.setActivityId(activity.getId());
144 sourceAo.setTypeKey(LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY);
145 sourceAo.setStateKey(LuiServiceConstants.LUI_AO_STATE_OFFERED_KEY);
146 sourceAo.setActivityCode("A");
147 sourceAo.setDescr(new RichTextHelper ().fromPlain("test activity"));
148 sourceAo.setIsHonorsOffering(Boolean.TRUE);
149 sourceAo.setMaximumEnrollment(100);
150 sourceAo.setMinimumEnrollment(90);
151 sourceAo.setName("my activity offering");
152 ScheduleInfo scheduleInfo = new ScheduleInfo();
153 scheduleInfo.setTypeKey(SchedulingServiceConstants.SCHEDULE_TYPE_SCHEDULE);
154 scheduleInfo.setAtpId(sourceCo.getTermId());
155 scheduleInfo=schedulingService.createSchedule(scheduleInfo.getTypeKey(), scheduleInfo, callContext);
156 sourceAo.setScheduleId(scheduleInfo.getId());
157 sourceAo = coService.createActivityOffering(sourceAo.getFormatOfferingId(), sourceAo.getActivityId(),
158 sourceAo.getTypeKey(), sourceAo, callContext);
159
160
161 TermInfo targetTerm = acalService.getTerm("2013SP", callContext);
162 SocRolloverResultItemInfo item = coService.rolloverCourseOffering(sourceCo.getId(),
163 targetTerm.getId(),
164 optionKeys,
165 callContext);
166 CourseOfferingInfo targetCo = coService.getCourseOffering(item.getTargetCourseOfferingId(), callContext);
167 assertNotNull(targetCo);
168 assertEquals(sourceCo.getCourseId(), targetCo.getCourseId());
169 assertEquals(targetTerm.getId(), targetCo.getTermId());
170
171
172 assertEquals(sourceCo.getTypeKey(), targetCo.getTypeKey());
173 assertEquals(sourceCo.getCourseOfferingTitle(), targetCo.getCourseOfferingTitle());
174
175 List<FormatOfferingInfo> targetFos = coService.getFormatOfferingsByCourseOffering(targetCo.getId(), callContext);
176 assertEquals (1, targetFos.size());
177 FormatOfferingInfo targetFo = targetFos.get(0);
178 assertEquals(sourceFo.getFormatId(), targetFo.getFormatId());
179 assertEquals(targetTerm.getId(), targetFo.getTermId());
180
181
182 assertEquals(sourceFo.getTypeKey(), targetFo.getTypeKey());
183 assertEquals(sourceFo.getName(), targetFo.getName());
184
185 List<ActivityOfferingInfo> targetAos = coService.getActivityOfferingsByFormatOffering(targetFo.getId(), callContext);
186 assertEquals (1, targetAos.size());
187 ActivityOfferingInfo targetAo = targetAos.get(0);
188 assertEquals(sourceAo.getActivityId(), targetAo.getActivityId());
189 assertEquals(targetTerm.getId(), targetAo.getTermId());
190
191
192 assertEquals(sourceAo.getTypeKey(), targetAo.getTypeKey());
193 assertEquals(sourceAo.getName(), targetAo.getName());
194
195 }
196 }