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