001 /**
002 * Copyright 2012 The Kuali Foundation
003 *
004 * Licensed under the the Educational Community License, Version 1.0
005 * (the "License"); you may not use this file except in compliance
006 * with the License. You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl1.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.student.enrollment.class2.courseoffering.service.impl;
017
018 import org.apache.log4j.Logger;
019 import org.junit.After;
020 import org.junit.Assert;
021 import org.junit.Before;
022 import org.junit.Ignore;
023 import org.junit.Test;
024 import org.junit.runner.RunWith;
025 import org.kuali.student.enrollment.acal.service.AcademicCalendarService;
026 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingClusterInfo;
027 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo;
028 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingSetInfo;
029 import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
030 import org.kuali.student.enrollment.courseoffering.dto.FormatOfferingInfo;
031 import org.kuali.student.enrollment.courseoffering.dto.OfferingInstructorInfo;
032 import org.kuali.student.enrollment.courseoffering.dto.RegistrationGroupInfo;
033 import org.kuali.student.enrollment.courseoffering.dto.SeatPoolDefinitionInfo;
034 import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
035 import org.kuali.student.enrollment.test.util.AttributeTester;
036 import org.kuali.student.enrollment.test.util.ListOfStringTester;
037 import org.kuali.student.enrollment.test.util.MetaTester;
038 import org.kuali.student.r2.common.dto.AttributeInfo;
039 import org.kuali.student.r2.common.dto.ContextInfo;
040 import org.kuali.student.r2.common.dto.StatusInfo;
041 import org.kuali.student.r2.common.exceptions.AlreadyExistsException;
042 import org.kuali.student.r2.common.exceptions.DataValidationErrorException;
043 import org.kuali.student.r2.common.exceptions.DependentObjectsExistException;
044 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
045 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
046 import org.kuali.student.r2.common.exceptions.MissingParameterException;
047 import org.kuali.student.r2.common.exceptions.OperationFailedException;
048 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
049 import org.kuali.student.r2.common.exceptions.ReadOnlyException;
050 import org.kuali.student.r2.common.exceptions.VersionMismatchException;
051 import org.kuali.student.r2.common.util.ContextUtils;
052 import org.kuali.student.r2.common.util.constants.CourseOfferingServiceConstants;
053 import org.kuali.student.r2.common.util.constants.LprServiceConstants;
054 import org.kuali.student.r2.common.util.constants.LuServiceConstants;
055 import org.kuali.student.r2.common.util.constants.LuiServiceConstants;
056 import org.kuali.student.r2.core.atp.service.AtpService;
057 import org.kuali.student.r2.core.class1.type.dto.TypeInfo;
058 import org.kuali.student.r2.core.constants.AtpServiceConstants;
059 import org.kuali.student.r2.lum.course.dto.CourseInfo;
060 import org.kuali.student.r2.lum.course.service.CourseService;
061 import org.springframework.test.context.ContextConfiguration;
062 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
063
064 import javax.annotation.Resource;
065 import java.util.ArrayList;
066 import java.util.Arrays;
067 import java.util.List;
068
069 import static org.junit.Assert.assertEquals;
070 import static org.junit.Assert.assertNotNull;
071 import static org.junit.Assert.assertNull;
072 import static org.junit.Assert.assertTrue;
073 import static org.junit.Assert.fail;
074
075 /**
076 * @author ocleirig
077 * <p/>
078 * This is a set of unit test cases that runs directly against a mock
079 * implementation of the class 2 course offering service.
080 */
081 @RunWith(SpringJUnit4ClassRunner.class)
082 @ContextConfiguration(locations = {"classpath:co-test-with-class2-mock-context.xml"})
083 public class TestCourseOfferingServiceImplWithClass2Mocks {
084
085 private static final Logger log = Logger
086 .getLogger(TestCourseOfferingServiceImplWithClass2Mocks.class);
087
088 @Resource
089 protected CourseOfferingService coService;
090
091 @Resource
092 protected AcademicCalendarService acalService;
093
094 @Resource
095 protected AtpService atpService;
096
097 @Resource
098 protected CourseService canonicalCourseService;
099
100 @Resource
101 protected CourseOfferingServiceTestDataLoader dataLoader;
102
103 private final boolean testAwareDataLoader;
104
105 /**
106 *
107 */
108 public TestCourseOfferingServiceImplWithClass2Mocks() {
109 this(true);
110 }
111
112
113 protected TestCourseOfferingServiceImplWithClass2Mocks(boolean testAwareDataLoader) {
114 this.testAwareDataLoader = testAwareDataLoader;
115
116 }
117
118
119 public static String principalId = "123";
120 public ContextInfo callContext = null;
121
122 @Before
123 public void setup() throws Exception {
124
125 callContext = new ContextInfo();
126 callContext.setPrincipalId(principalId);
127
128 if (testAwareDataLoader || !dataLoader.isInitialized())
129 dataLoader.beforeTest();
130
131 }
132
133
134 @After
135 public void tearDown() {
136 if (testAwareDataLoader)
137 dataLoader.afterTest();
138 }
139
140 @Test
141 public void testCreateAndGetRegistrationGroup()
142 throws AlreadyExistsException, DoesNotExistException,
143 DataValidationErrorException, InvalidParameterException,
144 MissingParameterException, OperationFailedException,
145 PermissionDeniedException {
146 List<String> activityOfferingIds = new ArrayList<String>();
147
148 activityOfferingIds.add("CO-1:LEC-ONLY:LEC-A");
149
150 String formatOfferingId = "CO-1:LEC-ONLY";
151
152 String activityOfferingClusterId = "fake-aoc-id";
153
154 RegistrationGroupInfo rgLecA = CourseOfferingServiceDataUtils
155 .createRegistrationGroup("CO-1", formatOfferingId, "2012FA",
156 activityOfferingClusterId, activityOfferingIds, "RG-1", "RG-1", true, true,
157 10, LuiServiceConstants.REGISTRATION_GROUP_OPEN_STATE_KEY);
158
159 try {
160 RegistrationGroupInfo created = coService.createRegistrationGroup(
161 formatOfferingId, activityOfferingClusterId,
162 LuiServiceConstants.REGISTRATION_GROUP_TYPE_KEY, rgLecA,
163 callContext);
164 assertNotNull(created);
165
166 RegistrationGroupInfo retrieved = coService.getRegistrationGroup(
167 created.getId(), callContext);
168 assertNotNull(retrieved);
169
170 assertEquals(rgLecA.getFormatOfferingId(),
171 retrieved.getFormatOfferingId());
172 assertEquals(rgLecA.getActivityOfferingClusterId(), retrieved.getActivityOfferingClusterId());
173 assertEquals(rgLecA.getName(), retrieved.getName());
174 assertEquals(rgLecA.getStateKey(), retrieved.getStateKey());
175 assertEquals(rgLecA.getTypeKey(), retrieved.getTypeKey());
176
177 // test getRegistrationGroupsForCourseOffering
178
179 } catch (Exception ex) {
180 log.error("failed from service call:", ex);
181
182 fail("Exception from service call :" + ex.getMessage());
183 }
184 }
185
186
187 @Test
188 public void testCreateActivityOfferintgCluster() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DataValidationErrorException, ReadOnlyException {
189
190 // default cluster is 2x3 = 6 reg groups
191
192 // we want to constrain to not use lec-b
193 // 1x3 = 3 reg groups
194
195 ActivityOfferingInfo activities[] = new ActivityOfferingInfo[]{
196 coService.getActivityOffering("CO-1:LEC-AND-LAB:LEC-A",
197 callContext),
198 coService.getActivityOffering("CO-1:LEC-AND-LAB:LAB-A",
199 callContext),
200 coService.getActivityOffering("CO-1:LEC-AND-LAB:LAB-B",
201 callContext),
202 coService.getActivityOffering("CO-1:LEC-AND-LAB:LAB-C",
203 callContext),};
204
205 ActivityOfferingClusterInfo expected = CourseOfferingServiceDataUtils
206 .createActivityOfferingCluster("CO-1:LEC-AND-LAB", "Default Cluster",
207 Arrays.asList(activities));
208
209 new AttributeTester().add2ForCreate(expected.getAttributes());
210
211 ActivityOfferingClusterInfo actual = coService.createActivityOfferingCluster("CO-1:LEC-AND-LAB", CourseOfferingServiceConstants.AOC_ROOT_TYPE_KEY, expected, callContext);
212
213 assertNotNull(actual.getId());
214 new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
215 new MetaTester().checkAfterCreate(actual.getMeta());
216
217 // check that the union of activity id's matches what we declared
218 new ListOfStringTester().checkExistsAnyOrder(Arrays.asList(new String[]{"CO-1:LEC-AND-LAB:LEC-A", "CO-1:LEC-AND-LAB:LAB-A", "CO-1:LEC-AND-LAB:LAB-B", "CO-1:LEC-AND-LAB:LAB-C"}), extractActivityOfferingIds(actual.getActivityOfferingSets()), true);
219
220
221 List<RegistrationGroupInfo> rgList = coService.getRegistrationGroupsByActivityOfferingCluster(actual.getId(), callContext);
222
223 assertEquals(0, rgList.size());
224
225 coService.generateRegistrationGroupsForCluster(actual.getId(), callContext);
226
227 rgList = coService.getRegistrationGroupsByActivityOfferingCluster(actual.getId(), callContext);
228
229 assertEquals(3, rgList.size());
230
231 coService.generateRegistrationGroupsForCluster(actual.getId(), callContext);
232
233 // verify count stays the same even after calling the method again.
234 rgList = coService.getRegistrationGroupsByActivityOfferingCluster(actual.getId(), callContext);
235
236 assertEquals(3, rgList.size());
237 }
238
239 private List<String> extractActivityOfferingIds(List<ActivityOfferingSetInfo> aoList) {
240 List<String> idList = new ArrayList<String>();
241
242 for (ActivityOfferingSetInfo activityOfferingSetInfo : aoList) {
243
244 idList.addAll(activityOfferingSetInfo.getActivityOfferingIds());
245
246 }
247 return idList;
248 }
249
250 @Test
251 public void testGenerateRegGroupsFromActivityOfferingCluster() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DataValidationErrorException, ReadOnlyException {
252
253 ActivityOfferingInfo activities[] = new ActivityOfferingInfo[]{
254 coService.getActivityOffering("CO-1:LEC-AND-LAB:LEC-A",
255 callContext),
256 coService.getActivityOffering("CO-1:LEC-AND-LAB:LAB-A",
257 callContext),
258 coService.getActivityOffering("CO-1:LEC-AND-LAB:LAB-B",
259 callContext),
260 coService.getActivityOffering("CO-1:LEC-AND-LAB:LAB-C",
261 callContext),};
262
263 ActivityOfferingClusterInfo cluster = CourseOfferingServiceDataUtils
264 .createActivityOfferingCluster("CO-1:LEC-AND-LAB", "Default",
265 Arrays.asList(activities));
266
267 ActivityOfferingClusterInfo created = coService.createActivityOfferingCluster("CO-1:LEC-AND-LAB", CourseOfferingServiceConstants.AOC_ROOT_TYPE_KEY, cluster, callContext);
268
269
270 }
271
272
273 private ActivityOfferingClusterInfo createDefaultActivityOfferingCluster(String formatOfferingId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DataValidationErrorException, ReadOnlyException {
274
275 List<ActivityOfferingInfo> activities = coService.getActivityOfferingsByFormatOffering(formatOfferingId, callContext);
276
277 ActivityOfferingClusterInfo defaultAoc = CourseOfferingServiceDataUtils.createActivityOfferingCluster(formatOfferingId, "Default Cluster", activities);
278
279 defaultAoc = coService.createActivityOfferingCluster(formatOfferingId, CourseOfferingServiceConstants.AOC_ROOT_TYPE_KEY, defaultAoc, callContext);
280
281 Assert.assertNotNull(defaultAoc.getId());
282
283 return defaultAoc;
284 }
285
286 @Test
287 public void testGenerateRegistrationGroupsSimple() throws DoesNotExistException,
288 InvalidParameterException, MissingParameterException,
289 OperationFailedException, PermissionDeniedException, AlreadyExistsException, DataValidationErrorException, ReadOnlyException {
290
291 String formatOfferingId = "CO-1:LEC-AND-LAB";
292
293 createDefaultActivityOfferingCluster(formatOfferingId);
294
295 StatusInfo status = coService
296 .generateRegistrationGroupsForFormatOffering(
297 formatOfferingId, callContext);
298
299 Assert.assertTrue(status.getIsSuccess());
300
301 List<RegistrationGroupInfo> rgList = coService.getRegistrationGroupsByFormatOffering("CO-1:LEC-AND-LAB", callContext);
302
303 Assert.assertEquals(6, rgList.size());
304
305 }
306
307 @Test
308 public void testGenerateAndDeleteRegistrationGroups() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DataValidationErrorException, ReadOnlyException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException, AlreadyExistsException, DependentObjectsExistException {
309
310 ActivityOfferingClusterInfo cluster = createDefaultActivityOfferingCluster("CO-1:LEC-AND-LAB");
311
312 List<RegistrationGroupInfo> rgList = coService.getRegistrationGroupsForCourseOffering("CO-1", callContext);
313
314 assertEquals(0, rgList.size());
315
316 StatusInfo status = coService
317 .generateRegistrationGroupsForFormatOffering(
318 "CO-1:LEC-AND-LAB", callContext);
319
320
321 Assert.assertTrue(status.getIsSuccess());
322
323 rgList = coService.getRegistrationGroupsByFormatOffering("CO-1:LEC-AND-LAB", callContext);
324
325 Assert.assertEquals(6, rgList.size());
326
327 // this is harder so for now just skip
328
329 // FormatOfferingInfo fo = coService.getFormatOffering("CO-1:LEC-AND-LAB", callContext);
330 //
331 // fo.getActivityOfferingTypeKeys().add(LuiServiceConstants.DISCUSSION_ACTIVITY_OFFERING_TYPE_KEY);
332 //
333 // coService.updateFormatOffering(fo.getId(), fo, callContext);
334
335 List<ActivityOfferingInfo> ao = coService.getActivityOfferingsByFormatOffering("CO-1:LEC-AND-LAB", callContext);
336
337 Assert.assertEquals(5, ao.size());
338
339 dataLoader.createLabActivityOfferingForCHEM123("LAB-F", callContext);
340
341 ao = coService.getActivityOfferingsByFormatOffering("CO-1:LEC-AND-LAB", callContext);
342
343 Assert.assertEquals(6, ao.size());
344
345 boolean exception = false;
346
347 try {
348 status = coService
349 .generateRegistrationGroupsForFormatOffering(
350 "CO-1:LEC-AND-LAB", callContext);
351
352 } catch (OperationFailedException e) {
353 exception = true;
354 }
355
356 Assert.assertTrue("Exception should have occured when generating on top of existing reg groups.", exception);
357
358 status = coService.deleteGeneratedRegistrationGroupsByFormatOffering("CO-1:LEC-AND-LAB", callContext);
359
360 assertTrue("Failed to delete existing generated registration groups", status.getIsSuccess());
361
362 status = coService
363 .generateRegistrationGroupsForFormatOffering(
364 "CO-1:LEC-AND-LAB", callContext);
365
366 rgList = coService.getRegistrationGroupsByFormatOffering("CO-1:LEC-AND-LAB", callContext);
367
368 Assert.assertEquals(6, rgList.size());
369
370 // in order to get 8 we need to assign the new AO into the default cluster
371
372 // or just delete the existing default cluster and recreate it.
373
374 coService.deleteRegistrationGroupsForCluster(cluster.getId(), callContext);
375 coService.deleteActivityOfferingCluster(cluster.getId(), callContext);
376
377 createDefaultActivityOfferingCluster("CO-1:LEC-AND-LAB");
378
379 coService.generateRegistrationGroupsForFormatOffering("CO-1:LEC-AND-LAB", callContext);
380
381 rgList = coService.getRegistrationGroupsByFormatOffering("CO-1:LEC-AND-LAB", callContext);
382
383 Assert.assertEquals(8, rgList.size());
384
385
386 }
387
388 @Test
389 public void testServiceSetup() {
390 assertNotNull(coService);
391 }
392
393 /**
394 * **********************************************************************
395 * COURSE TESTS ***********************************************************************
396 */
397 @Test
398 public void testGetCourseOffering() throws DoesNotExistException,
399 InvalidParameterException, MissingParameterException,
400 OperationFailedException, PermissionDeniedException {
401 try {
402 try {
403 coService.getCourseOffering("Lui-blah", callContext);
404 fail("Lui-blah should have thrown DoesNotExistException");
405 } catch (DoesNotExistException enee) {
406 // expected
407 }
408
409 CourseOfferingInfo co = coService.getCourseOffering("CO-1",
410 callContext);
411 assertNotNull(co);
412 assertEquals(LuiServiceConstants.COURSE_OFFERING_PROCESS_STATE_KEYS[0],
413 co.getStateKey());
414 assertEquals(LuiServiceConstants.COURSE_OFFERING_TYPE_KEY,
415 co.getTypeKey());
416 } catch (Exception ex) {
417 fail(ex.getMessage());
418 }
419 }
420
421 @Test
422 public void testGetCourseOfferingIdsByTerm() throws DoesNotExistException,
423 InvalidParameterException, MissingParameterException,
424 OperationFailedException, PermissionDeniedException {
425 List<String> offerings = coService.getCourseOfferingIdsByTerm(
426 "TermId-blah", true, callContext);
427
428 assertEquals(0, offerings.size());
429
430 List<String> idList = coService.getCourseOfferingIdsByTerm("2012FA",
431 true, callContext);
432 assertTrue(idList.size() > 0);
433 }
434
435 @Test
436 public void testGetCourseOfferingsByIds() throws DoesNotExistException,
437 InvalidParameterException, MissingParameterException,
438 OperationFailedException, PermissionDeniedException {
439 List<String> idsList = new ArrayList<String>();
440 idsList.add("test1");
441 idsList.add("test2");
442 idsList.add("test3");
443
444 try {
445 try {
446 coService.getCourseOfferingsByIds(idsList, callContext);
447 fail("idsList should have thrown DoesNotExistException");
448 } catch (DoesNotExistException enee) {
449 // expected
450 }
451
452 idsList.clear();
453
454 idsList.add("CO-1");
455 idsList.add("CO-2");
456
457 List<CourseOfferingInfo> co = coService.getCourseOfferingsByIds(
458 idsList, callContext);
459
460 assertNotNull(co);
461 for (CourseOfferingInfo coItem : co) {
462 assertEquals(LuiServiceConstants.COURSE_OFFERING_PROCESS_STATE_KEYS[0],
463 coItem.getStateKey());
464 assertEquals(LuiServiceConstants.COURSE_OFFERING_TYPE_KEY,
465 coItem.getTypeKey());
466 }
467 } catch (Exception ex) {
468 fail(ex.getMessage());
469 }
470 }
471
472 @Test
473 public void testGetCourseOfferingsByCourseAndTerm()
474 throws DoesNotExistException, InvalidParameterException,
475 MissingParameterException, OperationFailedException,
476 PermissionDeniedException {
477 try {
478 List<CourseOfferingInfo> offerings = coService
479 .getCourseOfferingsByCourseAndTerm("Lui-blah",
480 "TermId-blah", callContext);
481
482 assertEquals(0, offerings.size());
483
484 List<CourseOfferingInfo> co = coService
485 .getCourseOfferingsByCourseAndTerm("CLU-1", "2012FA",
486 callContext);
487 assertTrue(co.size() > 0);
488
489 for (CourseOfferingInfo coItem : co) {
490 assertEquals(LuiServiceConstants.COURSE_OFFERING_PROCESS_STATE_KEYS[0],
491 coItem.getStateKey());
492 assertEquals(LuiServiceConstants.COURSE_OFFERING_TYPE_KEY,
493 coItem.getTypeKey());
494 }
495 } catch (Exception ex) {
496 fail(ex.getMessage());
497 }
498 }
499
500 @Test
501 public void testCreateCourseOffering() throws AlreadyExistsException,
502 DoesNotExistException, DataValidationErrorException,
503 InvalidParameterException, MissingParameterException,
504 OperationFailedException, PermissionDeniedException,
505 ReadOnlyException,
506 DoesNotExistException,
507 InvalidParameterException,
508 MissingParameterException,
509 OperationFailedException,
510 PermissionDeniedException {
511
512 List<CourseOfferingInfo> offerings = coService
513 .getCourseOfferingsByCourse("CLU-1", callContext);
514
515 int expectedOfferings = offerings.size() + 1;
516
517 List<String> optionKeys = new ArrayList<String>();
518 CourseInfo canonicalCourse = this.canonicalCourseService
519 .getCourse("CLU-1", ContextUtils.getContextInfo());
520 CourseOfferingInfo coInfo = CourseOfferingServiceDataUtils
521 .createCourseOffering(canonicalCourse, "2012FA");
522
523 // gets around the unique course code constraint
524 // this is ok for testing.
525 coInfo.setCourseCode(coInfo.getCourseOfferingCode() + "TESTING CREATE");
526
527 CourseOfferingInfo created = coService.createCourseOffering("CLU-1",
528 "2012FA", LuiServiceConstants.COURSE_OFFERING_TYPE_KEY, coInfo,
529 optionKeys, callContext);
530
531 assertNotNull(created);
532 assertEquals("CLU-1", created.getCourseId());
533 assertEquals("2012FA", created.getTermId());
534 assertEquals(LuiServiceConstants.COURSE_OFFERING_PROCESS_STATE_KEYS[0],
535 created.getStateKey());
536 assertEquals(LuiServiceConstants.COURSE_OFFERING_TYPE_KEY,
537 created.getTypeKey());
538 assertEquals("CHEM123", created.getCourseOfferingCode());
539 assertEquals("Chemistry 123", created.getCourseOfferingTitle());
540
541 CourseOfferingInfo retrieved = coService.getCourseOffering(
542 created.getId(), callContext);
543 assertNotNull(retrieved);
544 assertEquals("CLU-1", retrieved.getCourseId());
545 assertEquals("2012FA", retrieved.getTermId());
546 assertEquals(LuiServiceConstants.COURSE_OFFERING_PROCESS_STATE_KEYS[0],
547 retrieved.getStateKey());
548 assertEquals(LuiServiceConstants.COURSE_OFFERING_TYPE_KEY,
549 retrieved.getTypeKey());
550
551 assertEquals("CHEM123", retrieved.getCourseOfferingCode());
552 assertEquals("Chemistry 123", retrieved.getCourseOfferingTitle());
553
554 offerings = coService.getCourseOfferingsByCourse("CLU-1", callContext);
555
556 // we and maybe another test have added one
557 assertEquals(expectedOfferings, offerings.size());
558 }
559
560 @Test
561 public void testUpdateCourseOffering() throws DataValidationErrorException,
562 DoesNotExistException, InvalidParameterException,
563 MissingParameterException, OperationFailedException,
564 PermissionDeniedException, ReadOnlyException,
565 VersionMismatchException {
566 try {
567 CourseOfferingInfo coi = coService.getCourseOffering("CO-2",
568 callContext);
569 assertNotNull(coi);
570
571 coi.setTermId("testAtpId1");
572 coi.setIsHonorsOffering(true);
573 coi.setMaximumEnrollment(40);
574 coi.setMinimumEnrollment(10);
575 List<OfferingInstructorInfo> instructors = new ArrayList<OfferingInstructorInfo>();
576 OfferingInstructorInfo instructor = new OfferingInstructorInfo();
577 instructor.setPersonId("Pers-1");
578 instructor.setPercentageEffort(Float.valueOf("60"));
579 instructor.setTypeKey(LprServiceConstants.INSTRUCTOR_MAIN_TYPE_KEY);
580 instructor.setStateKey(LprServiceConstants.ASSIGNED_STATE_KEY);
581 instructors.add(instructor);
582 coi.setInstructors(instructors);
583 CourseOfferingInfo updated = coService.updateCourseOffering("CO-2",
584 coi, callContext);
585 assertNotNull(updated);
586
587 CourseOfferingInfo retrieved = coService.getCourseOffering("CO-2",
588 callContext);
589 assertNotNull(retrieved);
590
591 assertTrue(retrieved.getIsHonorsOffering());
592 assertEquals(1, retrieved.getInstructors().size());
593 assertEquals(coi.getMaximumEnrollment(),
594 retrieved.getMaximumEnrollment());
595 assertEquals(coi.getMinimumEnrollment(),
596 retrieved.getMinimumEnrollment());
597
598 retrieved.setIsHonorsOffering(false);
599 List<OfferingInstructorInfo> instructors1 = new ArrayList<OfferingInstructorInfo>();
600 OfferingInstructorInfo instructor1 = new OfferingInstructorInfo();
601 instructor1.setPersonId("Pers-2");
602 instructor1.setPercentageEffort(Float.valueOf("60"));
603 instructor1
604 .setTypeKey(LprServiceConstants.INSTRUCTOR_MAIN_TYPE_KEY);
605 instructor1.setStateKey(LprServiceConstants.ASSIGNED_STATE_KEY);
606 instructors1.add(instructor1);
607 OfferingInstructorInfo instructor2 = new OfferingInstructorInfo();
608 instructor2.setPersonId("Pers-1");
609 instructor2.setPercentageEffort(Float.valueOf("30"));
610 instructor2
611 .setTypeKey(LprServiceConstants.INSTRUCTOR_MAIN_TYPE_KEY);
612 instructor2.setStateKey(LprServiceConstants.ASSIGNED_STATE_KEY);
613 instructors1.add(instructor2);
614 retrieved.setInstructors(instructors1);
615 CourseOfferingInfo updated1 = coService.updateCourseOffering(
616 "CO-2", retrieved, callContext);
617 assertNotNull(updated1);
618
619 CourseOfferingInfo retrieved1 = coService.getCourseOffering("CO-2",
620 callContext);
621 assertNotNull(retrieved1);
622 assertEquals(2, retrieved1.getInstructors().size());
623 } catch (Exception ex) {
624 log.error("exception due to", ex);
625 fail("Exception from service call :" + ex.getMessage());
626 }
627 }
628
629 @Test
630 public void testUpdateCourseOfferingWithDynAttrs()
631 throws DataValidationErrorException, DoesNotExistException,
632 InvalidParameterException, MissingParameterException,
633 OperationFailedException, PermissionDeniedException,
634 ReadOnlyException, VersionMismatchException {
635 try {
636
637 CourseOfferingInfo coi = coService.getCourseOffering("CO-2",
638 callContext);
639 assertNotNull(coi);
640
641 coi.setTermId("atpId1");
642
643 // dynamic attributes
644 AttributeTester attributeTester = new AttributeTester();
645
646 List<AttributeInfo> expectedList = new ArrayList<AttributeInfo>();
647
648 attributeTester.add2ForCreate(expectedList);
649
650 coi.getAttributes().addAll(expectedList);
651
652 coi.setFundingSource("state");
653
654 CourseOfferingInfo updated = coService.updateCourseOffering(
655 coi.getId(), coi, callContext);
656 assertNotNull(updated);
657
658 CourseOfferingInfo retrieved = coService.getCourseOffering(
659 coi.getId(), callContext);
660 assertNotNull(retrieved);
661
662 assertEquals("state", coi.getFundingSource());
663
664 attributeTester.check(expectedList, coi.getAttributes());
665
666 // TODO: fix once waitlists are implemented
667 // assertEquals("WaitlistLevelType1",
668 // coi.getWaitlistLevelTypeKey());
669 } catch (Exception ex) {
670 log.error("exception due to ", ex);
671 fail("Exception from service call :" + ex.getMessage());
672 }
673 }
674
675 @Test
676 @Ignore
677 // TODO fix KSENROLL-2671, add back validation decorator and this will work again
678 public void testDeleteFormatOffering() throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DependentObjectsExistException, DoesNotExistException {
679
680 boolean exception = false;
681
682 try {
683 coService.deleteFormatOffering("DOES NOT EXIST", callContext);
684 } catch (DoesNotExistException e) {
685 exception = true;
686 }
687
688 assertTrue("Activity should not exist but seems to.", exception);
689
690 exception = false;
691
692 String formatOfferingId = "CO-1:LEC-ONLY";
693 try {
694 coService.deleteFormatOffering(formatOfferingId, callContext);
695 } catch (DependentObjectsExistException e) {
696 exception = true;
697 }
698
699 assertTrue("Deleted a format that has activities", exception);
700
701 StatusInfo status = coService.deleteFormatOfferingCascaded(formatOfferingId, callContext);
702
703 assertTrue(status.getIsSuccess());
704
705 // verify no activity offerings remain
706 List<ActivityOfferingInfo> aos = coService.getActivityOfferingsByFormatOffering(formatOfferingId, callContext);
707
708 assertEquals(0, aos.size());
709 }
710
711
712 @Test
713 @Ignore
714 // TODO fix KSENROLL-2671, add back validation decorator and this will work again
715 public void testDeleteActivityOffering() throws DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException, AlreadyExistsException, DoesNotExistException {
716
717 SeatPoolDefinitionInfo seatPoolDefinitionInfo = CourseOfferingServiceDataUtils.createSeatPoolDefinition("POP1", "Test Seat Pool", "expiration milestone", false, 12, 5);
718
719 seatPoolDefinitionInfo = coService.createSeatPoolDefinition(seatPoolDefinitionInfo, callContext);
720
721 String activityOfferingId = "CO-1:LEC-ONLY:LEC-A";
722 coService.addSeatPoolDefinitionToActivityOffering(seatPoolDefinitionInfo.getId(), activityOfferingId, callContext);
723
724 boolean exception = false;
725 try {
726 coService.deleteActivityOffering(activityOfferingId, callContext);
727 } catch (DependentObjectsExistException e) {
728 exception = true;
729 }
730
731 assertTrue("Failed to detect associated seat pool for activity offering and abort delete", exception);
732
733 // now cascade the delete
734
735 StatusInfo status = coService.deleteActivityOfferingCascaded(activityOfferingId, callContext);
736
737 assertTrue(status.getIsSuccess());
738
739 // check that the activity offering and seat pool are gone.
740
741 exception = false;
742
743 try {
744 coService.getActivityOffering(activityOfferingId, callContext);
745 } catch (DoesNotExistException e) {
746 exception = true;
747 }
748
749 assertTrue("activity still exists after delete", exception);
750
751 exception = false;
752 try {
753 List<SeatPoolDefinitionInfo> spls = coService.getSeatPoolDefinitionsForActivityOffering(activityOfferingId, callContext);
754 } catch (DoesNotExistException e) {
755 exception = true;
756 }
757
758 assertTrue("activity still exists after delete", exception);
759
760 }
761
762
763 @Test
764 @Ignore
765 // TODO fix KSENROLL-2671, add back validation decorator and this will work again
766 public void testDeleteCourseOffering() throws AlreadyExistsException,
767 DoesNotExistException, DataValidationErrorException,
768 InvalidParameterException, MissingParameterException,
769 OperationFailedException, PermissionDeniedException,
770 ReadOnlyException,
771 DoesNotExistException,
772 InvalidParameterException,
773 MissingParameterException,
774 OperationFailedException,
775 PermissionDeniedException {
776
777 CourseInfo canonicalCourse = canonicalCourseService.getCourse("CLU-1", ContextUtils.getContextInfo());
778
779 // Create a CO
780 CourseOfferingInfo coInfo = CourseOfferingServiceDataUtils
781 .createCourseOffering(canonicalCourse, "2012SP");
782 List<String> optionKeys = new ArrayList<String>();
783 CourseOfferingInfo created = coService.createCourseOffering("CLU-1",
784 "2012SP", LuiServiceConstants.COURSE_OFFERING_TYPE_KEY, coInfo,
785 optionKeys, callContext);
786
787 // Verify that the CO was created
788 assertNotNull(created);
789 assertEquals("CLU-1", created.getCourseId());
790 assertEquals("2012SP", created.getTermId());
791 assertEquals(LuiServiceConstants.COURSE_OFFERING_PROCESS_STATE_KEYS[0],
792 created.getStateKey());
793 assertEquals(LuiServiceConstants.COURSE_OFFERING_TYPE_KEY,
794 created.getTypeKey());
795
796 try {
797 // Delete the course offering and check that the status returned was
798 // a success
799 StatusInfo delResult = coService.deleteCourseOffering(
800 created.getId(), callContext);
801 assertTrue(delResult.getIsSuccess());
802 } catch (Exception ex) {
803 log.error("exception due to ", ex);
804 fail("Exception from service call :" + ex.getMessage());
805 }
806
807 boolean exception = false;
808
809 try {
810 coService.deleteCourseOffering("CO-1", callContext);
811 } catch (DependentObjectsExistException e) {
812 exception = true;
813 }
814
815 assertTrue("Failed to detect dependent objects", exception);
816
817
818 }
819
820 @Test
821 @Ignore // TODO: update cascade to deal with AOC's instead of Reg Groups.
822 public void testDeleteCourseOfferingCascaded() throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, AlreadyExistsException, DataValidationErrorException {
823
824 boolean dependantObjects = false;
825
826 try {
827 coService.deleteCourseOffering("CO-2", callContext);
828 } catch (DependentObjectsExistException e) {
829 dependantObjects = true;
830 }
831
832 assertTrue("No dependent objects exist for CO-2", dependantObjects);
833
834
835 StatusInfo status = coService.generateRegistrationGroupsForFormatOffering("CO-2:LEC-ONLY", callContext);
836
837 List<RegistrationGroupInfo> rgs = coService.getRegistrationGroupsByFormatOffering("CO-2:LEC-ONLY", callContext);
838
839 assertTrue(rgs.size() > 0);
840
841 status = coService.deleteCourseOfferingCascaded("CO-2", callContext);
842
843 assertTrue(status.getIsSuccess());
844
845 List<FormatOfferingInfo> formats = coService.getFormatOfferingsByCourseOffering("CO-2", callContext);
846
847 assertEquals(0, formats.size());
848
849 rgs = coService.getRegistrationGroupsForCourseOffering("CO-2", callContext);
850
851 assertEquals(0, rgs.size());
852
853 }
854
855
856 @Test
857 public void testCreateFormatOffering() throws DoesNotExistException,
858 InvalidParameterException, MissingParameterException,
859 OperationFailedException, PermissionDeniedException {
860 try {
861
862 List<CourseOfferingInfo> coList = coService
863 .getCourseOfferingsByCourse("CLU-1", callContext);
864
865 assertTrue(coList.size() > 0);
866
867 CourseOfferingInfo co = coList.get(0);
868
869 FormatOfferingInfo newFO = CourseOfferingServiceDataUtils
870 .createFormatOffering(co.getId(), "format1",
871 co.getTermId(), "TEST FORMAT OFFERING",
872 LuiServiceConstants.ALL_ACTIVITY_TYPES);
873 FormatOfferingInfo fo = coService.createFormatOffering(co.getId(),
874 "format1", LuiServiceConstants.FORMAT_OFFERING_TYPE_KEY,
875 newFO, callContext);
876 assertNotNull(fo);
877 assertEquals(LuiServiceConstants.LUI_FO_STATE_PLANNED_KEY,
878 fo.getStateKey());
879 assertEquals(LuiServiceConstants.FORMAT_OFFERING_TYPE_KEY,
880 fo.getTypeKey());
881 assertEquals("TEST FORMAT OFFERING", fo.getDescr().getPlain());
882 } catch (Exception ex) {
883 log.error("exception due to ", ex);
884 fail(ex.getMessage());
885 }
886 }
887
888 @Test
889 public void testGetFormatOffering() throws DoesNotExistException,
890 InvalidParameterException, MissingParameterException,
891 OperationFailedException, PermissionDeniedException {
892 try {
893
894 FormatOfferingInfo fo = coService.getFormatOffering(
895 "CO-2:LEC-ONLY", callContext);
896 assertNotNull(fo);
897 assertEquals(LuiServiceConstants.LUI_FO_STATE_PLANNED_KEY,
898 fo.getStateKey());
899 assertEquals(LuiServiceConstants.FORMAT_OFFERING_TYPE_KEY,
900 fo.getTypeKey());
901 assertEquals("Lecture", fo.getDescr().getPlain());
902 } catch (Exception ex) {
903 log.error("exception due to ", ex);
904 fail(ex.getMessage());
905 }
906 }
907
908 @Test
909 public void testCreateAndGetActivityOffering()
910 throws AlreadyExistsException, DataValidationErrorException,
911 InvalidParameterException, MissingParameterException,
912 OperationFailedException, PermissionDeniedException, DoesNotExistException {
913
914 CourseOfferingInfo courseOffering = coService.getCourseOffering("CO-1", callContext);
915
916 List<OfferingInstructorInfo> instructors = new ArrayList<OfferingInstructorInfo>();
917
918 instructors.add(CourseOfferingServiceDataUtils.createInstructor(
919 "Pers-1", "Person One", 60.00F));
920
921 String activityId = CourseOfferingServiceDataUtils
922 .createCanonicalActivityId("CO-1:LEC-ONLY",
923 LuServiceConstants.COURSE_ACTIVITY_LECTURE_TYPE_KEY);
924
925 ActivityOfferingInfo ao = CourseOfferingServiceDataUtils
926 .createActivityOffering("2012FA", courseOffering, "CO-1:LEC-ONLY",
927 "SCHED-ID", activityId, "Lecture", "A",
928 LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY,
929 instructors);
930
931 try {
932 ActivityOfferingInfo created = coService.createActivityOffering(
933 "CO-1:LEC-ONLY", activityId,
934 LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY, ao,
935 callContext);
936 assertNotNull(created);
937
938 ActivityOfferingInfo retrieved = coService.getActivityOffering(
939 created.getId(), callContext);
940 assertNotNull(retrieved);
941
942 assertEquals(created.getActivityId(), retrieved.getActivityId());
943 assertEquals(created.getTermId(), retrieved.getTermId());
944 assertEquals(LuiServiceConstants.LUI_AO_STATE_DRAFT_KEY,
945 retrieved.getStateKey());
946 assertEquals(
947 LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY,
948 retrieved.getTypeKey());
949 assertEquals(1, retrieved.getInstructors().size());
950
951 // test getActivityOfferingsByCourseOffering
952 List<ActivityOfferingInfo> activities = coService
953 .getActivityOfferingsByCourseOffering("CO-1", callContext);
954 assertNotNull(activities);
955 // 3 existing plus this new one
956 // this one should probably not have been added so this test case
957 // may need to be adapted
958 // in the future.
959 assertEquals(8, activities.size());
960
961 boolean foundActivityId = false;
962 boolean foundId = false;
963
964 for (ActivityOfferingInfo activityOfferingInfo : activities) {
965
966 if (activityOfferingInfo.getActivityId().equals(
967 created.getActivityId())) {
968 foundActivityId = true;
969 }
970
971 if (activityOfferingInfo.getId().equals("CO-1:LEC-ONLY:LEC-B"))
972 foundId = true;
973 }
974 assertTrue(foundActivityId);
975 assertTrue(foundId);
976
977 assertEquals(1, activities.get(0).getInstructors().size());
978 } catch (Exception ex) {
979 log.fatal("Exception from serviceCall", ex);
980
981 fail("Exception from service call :" + ex.getMessage());
982 }
983 }
984
985
986 @Test
987 @Ignore
988 public void testUpdateRegistrationGroup() throws InvalidParameterException,
989 DataValidationErrorException, MissingParameterException,
990 DoesNotExistException, VersionMismatchException,
991 PermissionDeniedException, OperationFailedException,
992 ReadOnlyException {
993
994 List<RegistrationGroupInfo> rgList = coService.getRegistrationGroupsByFormatOffering("CO-2:LEC-ONLY", callContext);
995
996 assertEquals(2, rgList.size());
997
998 for (RegistrationGroupInfo regGroup : rgList) {
999
1000 // TODO: find a way to reach in and check that the reg groups are generated properly.
1001 if (regGroup.getId().contains("LEC-A")) {
1002 assertEquals("CO-2", regGroup.getCourseOfferingId());
1003 assertEquals(1, regGroup.getActivityOfferingIds().size());
1004 assertEquals("CO-2:LEC-ONLY:LEC-A", regGroup.getActivityOfferingIds()
1005 .get(0));
1006 } else if (regGroup.getId().contains("LEC-B")) {
1007 regGroup.getActivityOfferingIds().remove(0);
1008 regGroup.getActivityOfferingIds().add("CO-2:LEC-ONLY:LEC-B");
1009 RegistrationGroupInfo updatedRegGroup = coService
1010 .updateRegistrationGroup(regGroup.getId(), regGroup,
1011 callContext);
1012 assertEquals("CO-2", regGroup.getCourseOfferingId());
1013 assertEquals(1, updatedRegGroup.getActivityOfferingIds().size());
1014 assertEquals("CO-2:LEC-ONLY:LEC-B", regGroup.getActivityOfferingIds()
1015 .get(0));
1016 } else {
1017 Assert.fail("invalid reg group with id = " + regGroup.getId());
1018 }
1019 }
1020
1021
1022 }
1023
1024 @Test
1025 public void testDeleteRegistrationGroup() throws InvalidParameterException,
1026 MissingParameterException, DoesNotExistException,
1027 PermissionDeniedException, OperationFailedException {
1028
1029 List<RegistrationGroupInfo> rgList = coService.getRegistrationGroupsByFormatOffering("CO-2:LEC-ONLY", callContext);
1030
1031 assertEquals(2, rgList.size());
1032
1033 RegistrationGroupInfo rg = rgList.get(0);
1034
1035 StatusInfo statusInfo = coService.deleteRegistrationGroup(
1036 rg.getId(), callContext);
1037 assertTrue(statusInfo.getIsSuccess());
1038 try {
1039 coService.getRegistrationGroup(rg.getId(), callContext);
1040 fail("Expected DoesNotExistException.");
1041 } catch (DoesNotExistException e) {
1042 // Expected. Do nothing.
1043 }
1044 }
1045
1046 @Test
1047 public void testGetActivityOfferingType() throws InvalidParameterException,
1048 MissingParameterException, DoesNotExistException,
1049 PermissionDeniedException, OperationFailedException {
1050 TypeInfo validType = coService.getActivityOfferingType(
1051 LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY,
1052 callContext);
1053 assertNotNull(validType);
1054 assertEquals(LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY,
1055 validType.getKey());
1056
1057 TypeInfo shouldBeNull = null;
1058 try {
1059 shouldBeNull = coService.getActivityOfferingType(
1060 "madeUpINAVLIDAoType", callContext);
1061 fail("Expected DoesNotExistException");
1062 } catch (DoesNotExistException e) {
1063 assertNull(shouldBeNull);
1064 }
1065 }
1066
1067 @Test
1068 public void testGetActivityOfferingTypes()
1069 throws InvalidParameterException, MissingParameterException,
1070 PermissionDeniedException, OperationFailedException {
1071 List<TypeInfo> validTypes = coService
1072 .getActivityOfferingTypes(callContext);
1073
1074 assertNotNull(validTypes);
1075 assertTrue("Expecting at least one activity offering type",
1076 !validTypes.isEmpty());
1077
1078 boolean found = false;
1079 for (TypeInfo type : validTypes) {
1080 found = type.getKey().equals(
1081 LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY);
1082 if (found) {
1083 break;
1084 }
1085 }
1086
1087 assertTrue("Expecting to find at least "
1088 + LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY
1089 + " type.", found);
1090 }
1091
1092
1093 @Test
1094 public void testCreateSeatPoolDefinition() throws DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException {
1095
1096 SeatPoolDefinitionInfo mainPool = CourseOfferingServiceDataUtils.createSeatPoolDefinition("EVERYONE", "Lab 123", AtpServiceConstants.MILESTONE_COURSE_SELECTION_PERIOD_END_TYPE_KEY, true, 85, 1);
1097
1098 SeatPoolDefinitionInfo secondaryPool = CourseOfferingServiceDataUtils.createSeatPoolDefinition("EVERYONE", "Lab 123B", AtpServiceConstants.MILESTONE_COURSE_SELECTION_PERIOD_END_TYPE_KEY, true, 15, 2);
1099
1100 mainPool = coService.createSeatPoolDefinition(mainPool, callContext);
1101
1102 secondaryPool = coService.createSeatPoolDefinition(secondaryPool, callContext);
1103
1104 boolean exceptionEncountered = false;
1105 try {
1106 coService.addSeatPoolDefinitionToActivityOffering(mainPool.getId(), "CO-1:LEC-ONLY:LEC-A", callContext);
1107 coService.addSeatPoolDefinitionToActivityOffering(secondaryPool.getId(), "CO-1:LEC-ONLY:LEC-A", callContext);
1108 } catch (AlreadyExistsException e) {
1109 exceptionEncountered = true;
1110 } catch (DoesNotExistException e) {
1111 exceptionEncountered = true;
1112 }
1113
1114 Assert.assertFalse(exceptionEncountered);
1115
1116 try {
1117 List<SeatPoolDefinitionInfo> spds = coService.getSeatPoolDefinitionsForActivityOffering("CO-1:LEC-ONLY:LEC-A", callContext);
1118
1119 Assert.assertEquals(2, spds.size());
1120
1121 } catch (DoesNotExistException e) {
1122 // should not happen
1123 Assert.assertFalse("Activity does not exist exception", true);
1124 }
1125
1126 exceptionEncountered = false;
1127
1128 try {
1129 coService.removeSeatPoolDefinitionFromActivityOffering(mainPool.getId(), "CO-1:LEC-ONLY:LEC-A", callContext);
1130 } catch (DoesNotExistException e) {
1131
1132 exceptionEncountered = true;
1133 }
1134
1135 Assert.assertFalse(exceptionEncountered);
1136
1137 try {
1138 List<SeatPoolDefinitionInfo> spds = coService.getSeatPoolDefinitionsForActivityOffering("CO-1:LEC-ONLY:LEC-A", callContext);
1139
1140 Assert.assertEquals(1, spds.size());
1141
1142 } catch (DoesNotExistException e) {
1143 // should not happen
1144 Assert.assertFalse("Activity does not exist exception", true);
1145 }
1146
1147 }
1148 }