1 package org.kuali.student.enrollment.class2.courseoffering.service.impl;
2
3 import junit.framework.Assert;
4 import org.junit.Test;
5 import org.junit.runner.RunWith;
6 import org.kuali.student.enrollment.class1.lui.service.impl.LuiServiceDataLoader;
7 import org.kuali.student.enrollment.class2.courseoffering.service.RegistrationGroupCodeGenerator;
8 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingClusterInfo;
9 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo;
10 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingSetInfo;
11 import org.kuali.student.enrollment.courseoffering.dto.FormatOfferingInfo;
12 import org.kuali.student.enrollment.courseoffering.dto.RegistrationGroupInfo;
13 import org.kuali.student.enrollment.courseoffering.dto.SeatPoolDefinitionInfo;
14 import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
15 import org.kuali.student.enrollment.lui.dto.LuiInfo;
16 import org.kuali.student.enrollment.lui.dto.LuiLuiRelationInfo;
17 import org.kuali.student.enrollment.lui.service.LuiService;
18 import org.kuali.student.enrollment.test.util.AttributeTester;
19 import org.kuali.student.enrollment.test.util.ListOfStringTester;
20 import org.kuali.student.enrollment.test.util.MetaTester;
21 import org.kuali.student.r2.common.dto.ContextInfo;
22 import org.kuali.student.r2.common.dto.RichTextInfo;
23 import org.kuali.student.r2.common.dto.StatusInfo;
24 import org.kuali.student.r2.common.exceptions.AlreadyExistsException;
25 import org.kuali.student.r2.common.exceptions.DataValidationErrorException;
26 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
27 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
28 import org.kuali.student.r2.common.exceptions.MissingParameterException;
29 import org.kuali.student.r2.common.exceptions.OperationFailedException;
30 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
31 import org.kuali.student.r2.common.exceptions.ReadOnlyException;
32 import org.kuali.student.r2.common.util.ContextUtils;
33 import org.kuali.student.r2.common.util.constants.CourseOfferingServiceConstants;
34 import org.kuali.student.r2.common.util.constants.LuiServiceConstants;
35 import org.kuali.student.r2.core.atp.service.AtpService;
36 import org.kuali.student.r2.core.class1.atp.service.impl.AtpTestDataLoader;
37 import org.kuali.student.r2.core.constants.AtpServiceConstants;
38 import org.kuali.student.r2.core.constants.PopulationServiceConstants;
39 import org.kuali.student.r2.core.population.dto.PopulationInfo;
40 import org.kuali.student.r2.core.population.dto.PopulationRuleInfo;
41 import org.kuali.student.r2.core.population.service.PopulationService;
42 import org.springframework.test.context.ContextConfiguration;
43 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
44 import org.springframework.test.context.transaction.TransactionConfiguration;
45 import org.springframework.transaction.annotation.Transactional;
46
47 import javax.annotation.Resource;
48 import java.util.ArrayList;
49 import java.util.Arrays;
50 import java.util.List;
51
52 import static org.junit.Assert.assertEquals;
53 import static org.junit.Assert.assertFalse;
54 import static org.junit.Assert.assertNotNull;
55
56
57
58
59
60
61
62
63
64
65
66
67
68 @RunWith(SpringJUnit4ClassRunner.class)
69 @ContextConfiguration(locations = {"classpath:co-test-context.xml"})
70 @TransactionConfiguration(transactionManager = "JtaTxManager", defaultRollback = true)
71 @Transactional
72 public class TestCourseOfferingServiceImplM4 {
73 @Resource
74 private CourseOfferingService coServiceImpl;
75 @Resource
76 private PopulationService populationService;
77 @Resource
78 private LuiService luiService;
79 @Resource
80 private AtpService atpService;
81
82
83 private ContextInfo contextInfo;
84
85 @Resource
86 protected LuiServiceDataLoader dataLoader = new LuiServiceDataLoader();
87 @Resource
88 private AtpTestDataLoader atpTestDataLoader = new AtpTestDataLoader(atpService);
89
90 private void before() {
91 contextInfo = ContextUtils.createDefaultContextInfo();
92 contextInfo.setPrincipalId("admin");
93 contextInfo.setAuthenticatedPrincipalId("admin");
94 try {
95 atpTestDataLoader.loadDataOneRecord();
96 dataLoader.loadData();
97 FormatOfferingInfo foInfo = coServiceImpl.getFormatOffering("Lui-6", contextInfo);
98 if (foInfo.getActivityOfferingTypeKeys() == null |
99 foInfo.getActivityOfferingTypeKeys().isEmpty()) {
100 List<String> aoTypes = new ArrayList<String>();
101 aoTypes.add(LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY);
102 aoTypes.add(LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY);
103 foInfo.setActivityOfferingTypeKeys(aoTypes);
104 coServiceImpl.updateFormatOffering(foInfo.getId(), foInfo, contextInfo);
105 }
106
107 } catch (Exception ex) {
108 throw new RuntimeException(ex);
109 }
110 }
111
112 private SeatPoolDefinitionInfo _constructSeatPoolDefinitionInfoById(Integer val) {
113 String extension = "";
114 if (val != null) {
115 extension += val;
116 }
117 SeatPoolDefinitionInfo seatPoolDefinitionInfo = new SeatPoolDefinitionInfo();
118 seatPoolDefinitionInfo.setName("TestSeatPoolDefinitionInfo-Id" + extension);
119 seatPoolDefinitionInfo.setStateKey("TestSeatPoolDefinitionInfo-StateKey1" + extension);
120 seatPoolDefinitionInfo.setTypeKey("TestSeatPoolDefinitionInfo-TypeKey1" + extension);
121 seatPoolDefinitionInfo.setExpirationMilestoneTypeKey("TestSeatPoolDefinitionInfo-MilestoneKey1" + extension);
122 seatPoolDefinitionInfo.setIsPercentage(false);
123 seatPoolDefinitionInfo.setSeatLimit(50);
124 seatPoolDefinitionInfo.setProcessingPriority(3);
125 return seatPoolDefinitionInfo;
126 }
127
128 private List<SeatPoolDefinitionInfo> _constructSeatPoolDefinitionInfoByIdList() {
129 SeatPoolDefinitionInfo ref = _constructSeatPoolDefinitionInfoById(2);
130 SeatPoolDefinitionInfo three = _constructSeatPoolDefinitionInfoById(3);
131 SeatPoolDefinitionInfo four = _constructSeatPoolDefinitionInfoById(4);
132 SeatPoolDefinitionInfo five = _constructSeatPoolDefinitionInfoById(5);
133 List<SeatPoolDefinitionInfo> poolList = new ArrayList<SeatPoolDefinitionInfo>();
134 poolList.add(ref);
135 poolList.add(three);
136 poolList.add(four);
137 poolList.add(five);
138 return poolList;
139 }
140
141 private PopulationInfo _constructPopulationInfo(Integer val) {
142 String extension = "";
143 if (val != null) {
144 extension += val;
145 }
146 PopulationInfo populationInfo = new PopulationInfo();
147 populationInfo.setName("TestPop" + extension);
148 RichTextInfo richTextInfo = new RichTextInfo();
149 richTextInfo.setPlain("plain" + extension);
150 richTextInfo.setFormatted("formatted" + extension);
151 populationInfo.setDescr(richTextInfo);
152 populationInfo.setStateKey(PopulationServiceConstants.POPULATION_ACTIVE_STATE_KEY);
153 populationInfo.setTypeKey(PopulationServiceConstants.POPULATION_STUDENT_TYPE_KEY);
154 return populationInfo;
155 }
156
157 private List<PopulationInfo> _constructPopulationList() {
158 PopulationInfo ref = _constructPopulationInfo(2);
159 PopulationInfo three = _constructPopulationInfo(3);
160 PopulationInfo four = _constructPopulationInfo(4);
161 PopulationInfo five = _constructPopulationInfo(5);
162 List<PopulationInfo> popList = new ArrayList<PopulationInfo>();
163 popList.add(ref);
164 popList.add(three);
165 popList.add(four);
166 popList.add(five);
167 return popList;
168 }
169
170 private PopulationRuleInfo _constructExclusionPopulationRuleInfo() {
171 PopulationRuleInfo populationRuleInfo = new PopulationRuleInfo();
172 populationRuleInfo.setName("TestPopRule");
173 RichTextInfo richTextInfo = new RichTextInfo();
174 richTextInfo.setPlain("rule-plain");
175 richTextInfo.setFormatted("rule-formatted");
176 populationRuleInfo.setDescr(richTextInfo);
177 populationRuleInfo.setStateKey(PopulationServiceConstants.POPULATION_RULE_ACTIVE_STATE_KEY);
178 populationRuleInfo.setTypeKey(PopulationServiceConstants.POPULATION_RULE_TYPE_EXCLUSION_KEY);
179 return populationRuleInfo;
180 }
181
182 private RegistrationGroupInfo _constructRegistrationGroupInfoById(Integer val) {
183 String extension = "";
184 if (val != null) {
185 extension += val;
186 }
187 RegistrationGroupInfo registrationGroupInfo = new RegistrationGroupInfo();
188 registrationGroupInfo.setName("TestRegistrationGroupInfo-Id" + extension);
189 registrationGroupInfo.setStateKey("TestRegistrationGroupInfo-StateKey1" + extension);
190 registrationGroupInfo.setTypeKey("TestRegistrationGroupInfo-TypeKey1" + extension);
191 registrationGroupInfo.setFormatOfferingId("Lui-6");
192 registrationGroupInfo.setCourseOfferingId("Lui-1");
193 registrationGroupInfo.setTermId("20122");
194 registrationGroupInfo.setRegistrationCode("02" + extension);
195
196 List<String> activityOfferingIds = new ArrayList<String>();
197 activityOfferingIds.add("Lui-2");
198 activityOfferingIds.add("Lui-5");
199
200 registrationGroupInfo.setActivityOfferingIds(activityOfferingIds);
201 registrationGroupInfo.setIsGenerated(true);
202 registrationGroupInfo.setTypeKey(LuiServiceConstants.REGISTRATION_GROUP_TYPE_KEY);
203 registrationGroupInfo.setStateKey(LuiServiceConstants.REGISTRATION_GROUP_OFFERED_STATE_KEY);
204 return registrationGroupInfo;
205 }
206
207 private RegistrationGroupInfo _constructRegistrationGroupInfo2() {
208 String extension = "-foo";
209 RegistrationGroupInfo registrationGroupInfo = new RegistrationGroupInfo();
210 registrationGroupInfo.setName("TestRegistrationGroupInfo-Id" + extension);
211 registrationGroupInfo.setStateKey("TestRegistrationGroupInfo-StateKey1" + extension);
212 registrationGroupInfo.setTypeKey("TestRegistrationGroupInfo-TypeKey1" + extension);
213 registrationGroupInfo.setFormatOfferingId("Lui-6");
214 registrationGroupInfo.setCourseOfferingId("Lui-1");
215 registrationGroupInfo.setTermId("20122");
216 registrationGroupInfo.setRegistrationCode("02" + extension);
217
218 List<String> activityOfferingIds = new ArrayList<String>();
219 activityOfferingIds.add("Lui-2");
220 activityOfferingIds.add("Lui-Lab2");
221
222 registrationGroupInfo.setActivityOfferingIds(activityOfferingIds);
223 registrationGroupInfo.setIsGenerated(true);
224 registrationGroupInfo.setTypeKey(LuiServiceConstants.REGISTRATION_GROUP_TYPE_KEY);
225 registrationGroupInfo.setStateKey(LuiServiceConstants.REGISTRATION_GROUP_OFFERED_STATE_KEY);
226 return registrationGroupInfo;
227 }
228
229 private List<RegistrationGroupInfo> _constructRegistrationGroupInfoByIdList() {
230 RegistrationGroupInfo ref = _constructRegistrationGroupInfoById(2);
231 RegistrationGroupInfo three = _constructRegistrationGroupInfoById(3);
232 RegistrationGroupInfo four = _constructRegistrationGroupInfoById(4);
233 RegistrationGroupInfo five = _constructRegistrationGroupInfoById(5);
234 List<RegistrationGroupInfo> rgList = new ArrayList<RegistrationGroupInfo>();
235 rgList.add(ref);
236 rgList.add(three);
237 rgList.add(four);
238 rgList.add(five);
239 return rgList;
240 }
241
242 private List<String> extractActivityOfferingIds(List<ActivityOfferingSetInfo> aoList) {
243 List<String> idList = new ArrayList<String>();
244
245 for (ActivityOfferingSetInfo activityOfferingSetInfo : aoList) {
246
247 idList.addAll(activityOfferingSetInfo.getActivityOfferingIds());
248
249 }
250 return idList;
251 }
252
253 private ActivityOfferingClusterInfo _createAOC() {
254 ActivityOfferingClusterInfo expected;
255 try {
256 ActivityOfferingInfo activities[] = new ActivityOfferingInfo[]{
257 coServiceImpl.getActivityOffering("Lui-5", contextInfo),
258 coServiceImpl.getActivityOffering("Lui-Lab2", contextInfo),
259 coServiceImpl.getActivityOffering("Lui-8", contextInfo)};
260
261 expected = CourseOfferingServiceDataUtils.createActivityOfferingCluster("Lui-6", "Default Cluster",
262 Arrays.asList(activities));
263 } catch (Exception ex) {
264 throw new RuntimeException(ex);
265 }
266 return expected;
267 }
268
269
270 @Test
271 public void testRegCodeGenerator() {
272 RegistrationGroupCodeGenerator generator = new FourDigitRegistrationGroupCodeGenerator();
273 CourseOfferingService coService = new FakeCourseOfferingService();
274 try {
275 FormatOfferingInfo foInfo = coService.getFormatOffering("foo", null);
276 generator.initializeGenerator(coService, foInfo, null, null);
277 String prefix = "02";
278 for (int i = 1; i <= 99; i++) {
279 String code = generator.generateRegistrationGroupCode(foInfo, null, null);
280 String answer = prefix;
281 if (i < 10) {
282 answer += "0";
283 }
284 answer += i;
285 assertEquals(answer, code);
286 }
287
288 boolean codeGenerated = true;
289 try {
290 generator.generateRegistrationGroupCode(foInfo, null, null);
291 } catch (RuntimeException e) {
292 codeGenerated = false;
293 }
294 assertFalse(codeGenerated);
295 } catch (Exception e) {
296 assert (false);
297 }
298 }
299
300 @Test
301 public void testGetAndRemoveRegistrationGroupsByFormatOffering() {
302 before();
303
304 RegistrationGroupInfo info = _constructRegistrationGroupInfoById(null);
305 RegistrationGroupInfo info2 = _constructRegistrationGroupInfo2();
306 try {
307 String foId = "Lui-6";
308 String aocId = "Aoc-1";
309 RegistrationGroupInfo created = coServiceImpl.createRegistrationGroup(foId, aocId, LuiServiceConstants.REGISTRATION_GROUP_TYPE_KEY, info, contextInfo);
310 RegistrationGroupInfo created2 = coServiceImpl.createRegistrationGroup(foId, aocId, LuiServiceConstants.REGISTRATION_GROUP_TYPE_KEY, info2, contextInfo);
311
312 List<RegistrationGroupInfo> rgInfos = coServiceImpl.getRegistrationGroupsByFormatOffering(foId, contextInfo);
313 assertEquals(2, rgInfos.size());
314 for (RegistrationGroupInfo rgInfo : rgInfos) {
315 List<String> aoIds = rgInfo.getActivityOfferingIds();
316 for (String aoId : aoIds) {
317
318 LuiInfo luiInfo = luiService.getLui(aoId, contextInfo);
319 assertNotNull(luiInfo);
320 }
321 }
322
323 coServiceImpl.deleteRegistrationGroupsByFormatOffering(foId, contextInfo);
324 List<RegistrationGroupInfo> rgInfos2 = coServiceImpl.getRegistrationGroupsByFormatOffering(foId, contextInfo);
325 assertEquals(0, rgInfos2.size());
326 for (RegistrationGroupInfo rgInfo : rgInfos) {
327 boolean found = true;
328 try {
329
330 coServiceImpl.getRegistrationGroup(rgInfo.getId(), contextInfo);
331 } catch (DoesNotExistException e) {
332 found = false;
333 }
334 if (found) {
335 assert (false);
336 }
337 }
338 } catch (Exception e) {
339 e.printStackTrace();
340 assert (false);
341 }
342 }
343
344 @Test
345 public void testCreateUpdateRegistrationGroupInfoGet() {
346 before();
347
348 RegistrationGroupInfo info = _constructRegistrationGroupInfoById(null);
349 try {
350 RegistrationGroupInfo created = coServiceImpl.createRegistrationGroup("Lui-6", "Aoc-1", LuiServiceConstants.REGISTRATION_GROUP_TYPE_KEY, info, contextInfo);
351 RegistrationGroupInfo fetched = coServiceImpl.getRegistrationGroup(created.getId(), contextInfo);
352 Assert.assertEquals(created.getName(), fetched.getName());
353 Assert.assertEquals(created.getStateKey(), fetched.getStateKey());
354 Assert.assertEquals(created.getTypeKey(), fetched.getTypeKey());
355 Assert.assertEquals(created.getFormatOfferingId(), fetched.getFormatOfferingId());
356 Assert.assertEquals(created.getRegistrationCode(), fetched.getRegistrationCode());
357 Assert.assertEquals(created.getCourseOfferingId(), fetched.getCourseOfferingId());
358 Assert.assertEquals(created.getId(), fetched.getId());
359
360 List<LuiLuiRelationInfo> llrs = luiService.getLuiLuiRelationsByLui(fetched.getId(), contextInfo);
361
362 List<String> activityOfferingIds = new ArrayList<String>();
363 activityOfferingIds.add("Lui-2");
364 activityOfferingIds.add("Lui-Lab2");
365 fetched.setActivityOfferingIds(null);
366 fetched.setActivityOfferingIds(activityOfferingIds);
367 fetched.setFormatOfferingId(null);
368 fetched.setFormatOfferingId("Lui-7");
369 RegistrationGroupInfo updated = coServiceImpl.updateRegistrationGroup(fetched.getId(), fetched, contextInfo);
370
371 List<LuiLuiRelationInfo> llrs1 = luiService.getLuiLuiRelationsByLui(updated.getId(), contextInfo);
372 coServiceImpl.deleteRegistrationGroup(updated.getId(), contextInfo);
373
374 List<LuiLuiRelationInfo> llrsAfter = luiService.getLuiLuiRelationsByLui(updated.getId(), contextInfo);
375 try {
376 RegistrationGroupInfo fetchedAfterDelete = coServiceImpl.getRegistrationGroup(updated.getId(), contextInfo);
377
378 assert (false);
379 } catch (DoesNotExistException e) {
380 assert (true);
381 }
382
383 } catch (Exception e) {
384 e.printStackTrace();
385 assert (false);
386 }
387 }
388
389 @Test
390 public void testPopulation() {
391 before();
392 List<PopulationInfo> popList = _constructPopulationList();
393 try {
394 PopulationInfo refCreated = populationService.createPopulation(popList.get(0), contextInfo);
395 PopulationInfo threeCreated = populationService.createPopulation(popList.get(1), contextInfo);
396 PopulationInfo fourCreated = populationService.createPopulation(popList.get(2), contextInfo);
397
398 PopulationRuleInfo ruleInfo = _constructExclusionPopulationRuleInfo();
399 ruleInfo.setReferencePopulationId(refCreated.getId());
400 List<String> childIds = new ArrayList<String>();
401 childIds.add(threeCreated.getId());
402 childIds.add(fourCreated.getId());
403 ruleInfo.setChildPopulationIds(childIds);
404
405 PopulationRuleInfo ruleInfoCreated = populationService.createPopulationRule(ruleInfo, contextInfo);
406
407 PopulationRuleInfo ruleInfoFetched = populationService.getPopulationRule(ruleInfoCreated.getId(), contextInfo);
408 PopulationInfo combined = populationService.createPopulation(popList.get(3), contextInfo);
409 populationService.applyPopulationRuleToPopulation(ruleInfoFetched.getId(), combined.getId(), contextInfo);
410 SeatPoolDefinitionInfo info = _constructSeatPoolDefinitionInfoById(null);
411 info.setPopulationId(combined.getId());
412 SeatPoolDefinitionInfo created = coServiceImpl.createSeatPoolDefinition(info, contextInfo);
413 PopulationInfo retrieved = populationService.getPopulation(created.getPopulationId(), contextInfo);
414 assertEquals(combined.getId(), retrieved.getId());
415 } catch (Exception e) {
416 e.printStackTrace();
417 assert (false);
418 }
419 }
420
421 @Test
422 public void testCreateSeatPoolDefinitionGet() {
423 before();
424 SeatPoolDefinitionInfo info = _constructSeatPoolDefinitionInfoById(null);
425 try {
426 SeatPoolDefinitionInfo created = coServiceImpl.createSeatPoolDefinition(info, contextInfo);
427 SeatPoolDefinitionInfo fetched = coServiceImpl.getSeatPoolDefinition(created.getId(), contextInfo);
428 Assert.assertEquals(info.getName(), fetched.getName());
429 Assert.assertEquals(info.getStateKey(), fetched.getStateKey());
430 Assert.assertEquals(info.getTypeKey(), fetched.getTypeKey());
431 Assert.assertEquals(info.getExpirationMilestoneTypeKey(), fetched.getExpirationMilestoneTypeKey());
432 Assert.assertEquals(info.getIsPercentage(), fetched.getIsPercentage());
433 Assert.assertEquals(info.getSeatLimit(), fetched.getSeatLimit());
434 Assert.assertEquals(info.getProcessingPriority(), fetched.getProcessingPriority());
435 } catch (Exception e) {
436 e.printStackTrace();
437 assert (false);
438 }
439 }
440
441 @Test
442 public void testCreateSeatPoolDefinitionUpdateDelete() {
443 before();
444 SeatPoolDefinitionInfo info = _constructSeatPoolDefinitionInfoById(null);
445 try {
446 SeatPoolDefinitionInfo created = coServiceImpl.createSeatPoolDefinition(info, contextInfo);
447 SeatPoolDefinitionInfo fetched = coServiceImpl.getSeatPoolDefinition(created.getId(), contextInfo);
448 fetched.setSeatLimit(5);
449 fetched.setExpirationMilestoneTypeKey(AtpServiceConstants.MILESTONE_SEATPOOL_FIRST_DAY_OF_CLASSES_TYPE_KEY);
450 coServiceImpl.updateSeatPoolDefinition(fetched.getId(), fetched, contextInfo);
451 SeatPoolDefinitionInfo fetched2 = coServiceImpl.getSeatPoolDefinition(created.getId(), contextInfo);
452 assertEquals(new Integer(5), fetched2.getSeatLimit());
453 assertEquals(AtpServiceConstants.MILESTONE_SEATPOOL_FIRST_DAY_OF_CLASSES_TYPE_KEY, fetched2.getExpirationMilestoneTypeKey());
454 coServiceImpl.deleteSeatPoolDefinition(fetched.getId(), contextInfo);
455 boolean found = true;
456 try {
457 coServiceImpl.getSeatPoolDefinition(fetched.getId(), contextInfo);
458 } catch (DoesNotExistException e) {
459 found = false;
460 }
461 if (found) {
462 assert (false);
463 }
464 } catch (Exception e) {
465 e.printStackTrace();
466 assert (false);
467 }
468 }
469
470 @Test
471 public void testGenerateRegistrationGroupsSimple() throws DoesNotExistException,
472 InvalidParameterException, MissingParameterException,
473 OperationFailedException, PermissionDeniedException, AlreadyExistsException {
474
475 before();
476 try {
477
478 coServiceImpl.createActivityOfferingCluster("Lui-6", CourseOfferingServiceConstants.AOC_ROOT_TYPE_KEY, _createAOC(), contextInfo);
479
480
481 StatusInfo status = coServiceImpl.generateRegistrationGroupsForFormatOffering("Lui-6", contextInfo);
482 assertEquals(true, status.getIsSuccess());
483
484
485 List<RegistrationGroupInfo> rgList = coServiceImpl.getRegistrationGroupsByFormatOffering("Lui-6", contextInfo);
486 Assert.assertEquals(2, rgList.size());
487
488 } catch (Exception e) {
489 e.printStackTrace();
490 assert (false);
491 }
492 }
493
494 @Test
495 public void testCreateAOCSimple() {
496 before();
497 try {
498 ActivityOfferingClusterInfo aocInfo = new ActivityOfferingClusterInfo();
499 FormatOfferingInfo foInfo = coServiceImpl.getFormatOffering("Lui-6", contextInfo);
500
501 List<String> aoTypeKeys = new ArrayList<String>();
502 aoTypeKeys.add(LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY);
503 aoTypeKeys.add(LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY);
504 foInfo.setActivityOfferingTypeKeys(aoTypeKeys);
505 coServiceImpl.updateFormatOffering(foInfo.getId(), foInfo, contextInfo);
506
507 aocInfo.setFormatOfferingId(foInfo.getId());
508 aocInfo.setStateKey(CourseOfferingServiceConstants.AOC_ACTIVE_STATE_KEY);
509 aocInfo.setTypeKey(CourseOfferingServiceConstants.AOC_ROOT_TYPE_KEY);
510 ActivityOfferingClusterInfo created =
511 coServiceImpl.createActivityOfferingCluster(foInfo.getId(), aocInfo.getTypeKey(), aocInfo, contextInfo);
512 assertNotNull(created.getActivityOfferingSets());
513 } catch (Exception e) {
514 assert(false);
515 }
516 }
517
518 @Test
519 public void testActivityOfferingClusterCRUDsPlus() throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException {
520
521 before();
522
523 ActivityOfferingClusterInfo expected = _createAOC();
524 new AttributeTester().add2ForCreate(expected.getAttributes());
525
526
527 ActivityOfferingClusterInfo actual = coServiceImpl.createActivityOfferingCluster("Lui-6", CourseOfferingServiceConstants.AOC_ROOT_TYPE_KEY, expected, contextInfo);
528 assertNotNull(actual.getId());
529
530 new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
531 new MetaTester().checkAfterCreate(actual.getMeta());
532
533
534 try {
535
536 ActivityOfferingClusterInfo copy = coServiceImpl.createActivityOfferingCluster("Lui-6", CourseOfferingServiceConstants.AOC_ROOT_TYPE_KEY, expected, contextInfo);
537 assertEquals(copy.getName(), "Default Cluster");
538 copy.setName("Updated");
539
540 coServiceImpl.updateActivityOfferingCluster("Lui-6", copy.getId(), copy, contextInfo) ;
541
542 copy = coServiceImpl.getActivityOfferingCluster(copy.getId(), contextInfo);
543 assertEquals(copy.getName(), "Updated");
544
545 coServiceImpl.deleteActivityOfferingCluster(copy.getId(), contextInfo);
546 boolean found = true;
547 try {
548 coServiceImpl.getActivityOfferingCluster(copy.getId(), contextInfo);
549 } catch (DoesNotExistException e) {
550 found = false;
551 }
552 if (found) {
553 assert (false);
554 }
555 } catch (Exception ex) {
556 throw new RuntimeException("update failed - " + ex);
557 }
558
559
560 new ListOfStringTester().checkExistsAnyOrder(Arrays.asList(new String[]{"Lui-5", "Lui-Lab2", "Lui-8"}),
561 extractActivityOfferingIds(actual.getActivityOfferingSets()), true);
562
563
564 List<RegistrationGroupInfo> rgList = coServiceImpl.getRegistrationGroupsByActivityOfferingCluster(actual.getId(), contextInfo);
565 assertEquals(0, rgList.size());
566
567
568 coServiceImpl.generateRegistrationGroupsForCluster(actual.getId(), contextInfo);
569
570 rgList = coServiceImpl.getRegistrationGroupsByActivityOfferingCluster(actual.getId(), contextInfo);
571 assertEquals(2, rgList.size());
572
573
574 coServiceImpl.generateRegistrationGroupsForCluster(actual.getId(), contextInfo);
575
576
577 rgList = coServiceImpl.getRegistrationGroupsByActivityOfferingCluster(actual.getId(), contextInfo);
578 assertEquals(2, rgList.size());
579 }
580
581 }