1 package org.kuali.student.enrollment.class2.courseoffering.service.impl;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertFalse;
5 import static org.junit.Assert.assertNotNull;
6 import static org.junit.Assert.assertTrue;
7 import static org.junit.Assert.fail;
8
9 import java.util.ArrayList;
10 import java.util.Arrays;
11 import java.util.Calendar;
12 import java.util.Date;
13 import java.util.List;
14
15 import javax.annotation.Resource;
16
17 import junit.framework.Assert;
18
19 import org.apache.commons.collections.CollectionUtils;
20 import org.junit.Before;
21 import org.junit.Ignore;
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.kuali.rice.core.api.criteria.PredicateFactory;
25 import org.kuali.rice.core.api.criteria.QueryByCriteria;
26 import org.kuali.rice.core.api.criteria.QueryByCriteria.Builder;
27 import org.kuali.student.common.test.util.AttributeTester;
28 import org.kuali.student.common.test.util.ListOfStringTester;
29 import org.kuali.student.common.test.util.MetaTester;
30 import org.kuali.student.enrollment.class1.lui.service.impl.LuiServiceDataLoader;
31 import org.kuali.student.enrollment.class2.acal.util.MockAcalTestDataLoader;
32 import org.kuali.student.enrollment.class2.courseoffering.service.RegistrationGroupCodeGenerator;
33 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingClusterInfo;
34 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo;
35 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingSetInfo;
36 import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
37 import org.kuali.student.enrollment.courseoffering.dto.FormatOfferingInfo;
38 import org.kuali.student.enrollment.courseoffering.dto.RegistrationGroupInfo;
39 import org.kuali.student.enrollment.courseoffering.dto.SeatPoolDefinitionInfo;
40 import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
41 import org.kuali.student.enrollment.lui.dto.LuiInfo;
42 import org.kuali.student.enrollment.lui.service.LuiService;
43 import org.kuali.student.r2.common.dto.AttributeInfo;
44 import org.kuali.student.r2.common.dto.BulkStatusInfo;
45 import org.kuali.student.r2.common.dto.ContextInfo;
46 import org.kuali.student.r2.common.dto.RichTextInfo;
47 import org.kuali.student.r2.common.exceptions.AlreadyExistsException;
48 import org.kuali.student.r2.common.exceptions.DataValidationErrorException;
49 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
50 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
51 import org.kuali.student.r2.common.exceptions.MissingParameterException;
52 import org.kuali.student.r2.common.exceptions.OperationFailedException;
53 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
54 import org.kuali.student.r2.common.exceptions.ReadOnlyException;
55 import org.kuali.student.r2.common.util.ContextUtils;
56 import org.kuali.student.r2.common.util.constants.CourseOfferingServiceConstants;
57 import org.kuali.student.r2.common.util.constants.LuiServiceConstants;
58 import org.kuali.student.r2.core.acal.service.AcademicCalendarService;
59 import org.kuali.student.r2.core.class1.state.dto.LifecycleInfo;
60 import org.kuali.student.r2.core.class1.state.dto.StateInfo;
61 import org.kuali.student.r2.core.class1.state.service.StateService;
62 import org.kuali.student.r2.core.class1.type.service.TypeService;
63 import org.kuali.student.r2.core.constants.AtpServiceConstants;
64 import org.kuali.student.r2.core.constants.PopulationServiceConstants;
65 import org.kuali.student.r2.core.population.dto.PopulationInfo;
66 import org.kuali.student.r2.core.population.dto.PopulationRuleInfo;
67 import org.kuali.student.r2.core.population.service.PopulationService;
68 import org.slf4j.Logger;
69 import org.slf4j.LoggerFactory;
70 import org.springframework.test.context.ContextConfiguration;
71 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
72 import org.springframework.test.context.transaction.TransactionConfiguration;
73 import org.springframework.transaction.annotation.Transactional;
74
75
76
77
78
79
80
81
82
83
84
85 @RunWith(SpringJUnit4ClassRunner.class)
86 @ContextConfiguration(locations = {"classpath:co-test-context.xml"})
87 @TransactionConfiguration(transactionManager = "JtaTxManager", defaultRollback = true)
88 @Transactional
89 public class TestCourseOfferingServiceImplM4 {
90
91 private static final Logger log = LoggerFactory.getLogger(TestCourseOfferingServiceImplM4.class);
92
93 @Resource
94 protected CourseOfferingService coServiceImpl;
95 @Resource
96 protected PopulationService populationService;
97 @Resource
98 protected LuiService luiService;
99 @Resource
100 protected AcademicCalendarService acalService;
101 @Resource
102 protected TypeService typeService;
103 @Resource
104 protected StateService stateService;
105
106 protected ContextInfo contextInfo;
107
108 @Resource
109 protected LuiServiceDataLoader dataLoader = new LuiServiceDataLoader();
110
111 protected MockAcalTestDataLoader acalTestDataLoader;
112
113 public static String principalId = "123";
114 public ContextInfo callContext = null;
115
116 @Before
117 public void setup() throws Exception {
118 callContext = new ContextInfo();
119 callContext.setPrincipalId(principalId);
120
121 createStateTestData();
122 }
123
124 private void createStateTestData() throws Exception {
125
126
127 cleanupStateTestData( LuiServiceConstants.LUI_AO_STATE_DRAFT_KEY );
128 cleanupLifecycleTestData( LuiServiceConstants.ACTIVITY_OFFERING_LIFECYCLE_KEY );
129 LifecycleInfo aoLifecycle = addLifecycle( LuiServiceConstants.ACTIVITY_OFFERING_LIFECYCLE_KEY );
130 addState( aoLifecycle, LuiServiceConstants.LUI_AO_STATE_DRAFT_KEY, true );
131
132
133 cleanupStateTestData( LuiServiceConstants.LUI_FO_STATE_PLANNED_KEY );
134 cleanupLifecycleTestData( LuiServiceConstants.FORMAT_OFFERING_LIFECYCLE_KEY );
135 LifecycleInfo foLifecycle = addLifecycle( LuiServiceConstants.FORMAT_OFFERING_LIFECYCLE_KEY );
136 addState( foLifecycle, LuiServiceConstants.LUI_FO_STATE_PLANNED_KEY, true );
137
138
139 cleanupStateTestData( LuiServiceConstants.LUI_CO_STATE_DRAFT_KEY );
140 cleanupLifecycleTestData( LuiServiceConstants.COURSE_OFFERING_LIFECYCLE_KEY );
141 LifecycleInfo coLifecycle = addLifecycle( LuiServiceConstants.COURSE_OFFERING_LIFECYCLE_KEY );
142 addState( coLifecycle, LuiServiceConstants.LUI_CO_STATE_DRAFT_KEY, true );
143
144
145 cleanupStateTestData( LuiServiceConstants.REGISTRATION_GROUP_PENDING_STATE_KEY );
146 cleanupStateTestData( LuiServiceConstants.REGISTRATION_GROUP_OFFERED_STATE_KEY );
147 cleanupLifecycleTestData( LuiServiceConstants.REGISTRATION_GROUP_LIFECYCLE_KEY );
148 LifecycleInfo rgLifecycle = addLifecycle( LuiServiceConstants.REGISTRATION_GROUP_LIFECYCLE_KEY );
149 addState( rgLifecycle, LuiServiceConstants.REGISTRATION_GROUP_PENDING_STATE_KEY, true );
150 addState( rgLifecycle, LuiServiceConstants.REGISTRATION_GROUP_OFFERED_STATE_KEY, true );
151 }
152
153
154 private void cleanupStateTestData( String state ) {
155 try {
156 stateService.deleteState( state, callContext );
157 } catch( Exception e ) { }
158 }
159
160
161 private void cleanupLifecycleTestData( String name ) {
162 try {
163 stateService.deleteLifecycle( name, callContext );
164 } catch( Exception e ) { }
165 }
166
167 private LifecycleInfo addLifecycle( String name ) throws Exception {
168
169 LifecycleInfo origLife = new LifecycleInfo();
170 RichTextInfo rti = new RichTextInfo();
171 rti.setFormatted("<b>Formatted</b> lifecycle for testing purposes");
172 rti.setPlain("Plain lifecycle for testing purposes");
173 origLife.setDescr(rti);
174 origLife.setKey( name );
175 origLife.setName( "TEST_NAME" );
176 origLife.setRefObjectUri( "TEST_URI" );
177 AttributeInfo attr = new AttributeInfo();
178 attr.setKey("attribute.key");
179 attr.setValue("attribute value");
180 origLife.getAttributes().add(attr);
181
182 return stateService.createLifecycle(origLife.getKey(), origLife, callContext);
183 }
184
185 private StateInfo addState( LifecycleInfo lifecycleInfo, String state, boolean isInitialState ) throws Exception {
186
187 StateInfo orig = new StateInfo();
188 orig.setKey(state);
189 orig.setLifecycleKey(lifecycleInfo.getKey());
190 RichTextInfo rti = new RichTextInfo();
191 rti.setFormatted("<b>Formatted again</b> state for testing purposes");
192 rti.setPlain("Plain state again for testing purposes");
193 orig.setDescr(rti);
194 orig.setName("Testing state");
195 Date effDate = new Date();
196 orig.setEffectiveDate(effDate);
197 Calendar cal = Calendar.getInstance();
198 cal.set(2022, 8, 23);
199 orig.setExpirationDate(cal.getTime());
200 AttributeInfo attr = new AttributeInfo();
201 attr.setKey("attribute.key");
202 attr.setValue("attribute value");
203 orig.getAttributes().add(attr);
204 orig.setIsInitialState(isInitialState);
205
206 return stateService.createState(orig.getLifecycleKey(), orig.getKey(), orig, callContext);
207 }
208
209 protected void before() {
210 if(contextInfo == null) {
211 contextInfo = ContextUtils.createDefaultContextInfo();
212 contextInfo.setPrincipalId("admin");
213 contextInfo.setAuthenticatedPrincipalId("admin");
214
215 acalTestDataLoader = new MockAcalTestDataLoader(acalService);
216
217 }
218 try {
219
220 acalTestDataLoader.loadTerm("atpId5", "atpId5", "2000-01-01 00:00:00.0", "2100-12-31 00:00:00.0", AtpServiceConstants.ATP_FALL_TYPE_KEY, AtpServiceConstants.ATP_DRAFT_STATE_KEY, "Desc 101");
221 acalTestDataLoader.loadTerm("atpId8", "atpId8", "2000-01-01 00:00:00.0", "2100-12-31 00:00:00.0", AtpServiceConstants.ATP_FALL_TYPE_KEY, AtpServiceConstants.ATP_DRAFT_STATE_KEY, "Desc 101");
222
223 dataLoader.loadData();
224 FormatOfferingInfo foInfo = coServiceImpl.getFormatOffering("Lui-6", contextInfo);
225 if (foInfo.getActivityOfferingTypeKeys() == null |
226 foInfo.getActivityOfferingTypeKeys().isEmpty()) {
227 List<String> aoTypes = new ArrayList<String>();
228 aoTypes.add(LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY);
229 aoTypes.add(LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY);
230 foInfo.setActivityOfferingTypeKeys(aoTypes);
231 coServiceImpl.updateFormatOffering(foInfo.getId(), foInfo, contextInfo);
232 }
233
234 } catch (Exception ex) {
235 throw new RuntimeException(ex);
236 }
237 }
238
239 private SeatPoolDefinitionInfo _constructSeatPoolDefinitionInfoById(Integer val) {
240 String extension = "";
241 if (val != null) {
242 extension += val;
243 }
244 SeatPoolDefinitionInfo seatPoolDefinitionInfo = new SeatPoolDefinitionInfo();
245 seatPoolDefinitionInfo.setName("TestSeatPoolDefinitionInfo-Id" + extension);
246 seatPoolDefinitionInfo.setStateKey("TestSeatPoolDefinitionInfo-StateKey1" + extension);
247 seatPoolDefinitionInfo.setTypeKey("TestSeatPoolDefinitionInfo-TypeKey1" + extension);
248 seatPoolDefinitionInfo.setExpirationMilestoneTypeKey("TestSeatPoolDefinitionInfo-MilestoneKey1" + extension);
249 seatPoolDefinitionInfo.setIsPercentage(false);
250 seatPoolDefinitionInfo.setSeatLimit(50);
251 seatPoolDefinitionInfo.setProcessingPriority(3);
252 return seatPoolDefinitionInfo;
253 }
254
255 private PopulationInfo _constructPopulationInfo(Integer val) {
256 String extension = "";
257 if (val != null) {
258 extension += val;
259 }
260 PopulationInfo populationInfo = new PopulationInfo();
261 populationInfo.setName("TestPop" + extension);
262 RichTextInfo richTextInfo = new RichTextInfo();
263 richTextInfo.setPlain("plain" + extension);
264 richTextInfo.setFormatted("formatted" + extension);
265 populationInfo.setDescr(richTextInfo);
266 populationInfo.setStateKey(PopulationServiceConstants.POPULATION_ACTIVE_STATE_KEY);
267 populationInfo.setTypeKey(PopulationServiceConstants.POPULATION_STUDENT_TYPE_KEY);
268 return populationInfo;
269 }
270
271 private List<PopulationInfo> _constructPopulationList() {
272 PopulationInfo ref = _constructPopulationInfo(2);
273 PopulationInfo three = _constructPopulationInfo(3);
274 PopulationInfo four = _constructPopulationInfo(4);
275 PopulationInfo five = _constructPopulationInfo(5);
276 List<PopulationInfo> popList = new ArrayList<PopulationInfo>();
277 popList.add(ref);
278 popList.add(three);
279 popList.add(four);
280 popList.add(five);
281 return popList;
282 }
283
284 private PopulationRuleInfo _constructExclusionPopulationRuleInfo() {
285 PopulationRuleInfo populationRuleInfo = new PopulationRuleInfo();
286 populationRuleInfo.setName("TestPopRule");
287 RichTextInfo richTextInfo = new RichTextInfo();
288 richTextInfo.setPlain("rule-plain");
289 richTextInfo.setFormatted("rule-formatted");
290 populationRuleInfo.setDescr(richTextInfo);
291 populationRuleInfo.setStateKey(PopulationServiceConstants.POPULATION_RULE_ACTIVE_STATE_KEY);
292 populationRuleInfo.setTypeKey(PopulationServiceConstants.POPULATION_RULE_TYPE_EXCLUSION_KEY);
293 return populationRuleInfo;
294 }
295
296 private RegistrationGroupInfo _constructRegistrationGroupInfoById(Integer val) {
297 String extension = "";
298 if (val != null) {
299 extension += val;
300 }
301 RegistrationGroupInfo registrationGroupInfo = new RegistrationGroupInfo();
302 registrationGroupInfo.setName("TestRegistrationGroupInfo-Id" + extension);
303 registrationGroupInfo.setStateKey("TestRegistrationGroupInfo-StateKey1" + extension);
304 registrationGroupInfo.setTypeKey("TestRegistrationGroupInfo-TypeKey1" + extension);
305 registrationGroupInfo.setFormatOfferingId("Lui-6");
306 registrationGroupInfo.setCourseOfferingId("Lui-1");
307 registrationGroupInfo.setTermId("20122");
308 registrationGroupInfo.setRegistrationCode("02" + extension);
309
310 List<String> activityOfferingIds = new ArrayList<String>();
311 activityOfferingIds.add("Lui-2");
312 activityOfferingIds.add("Lui-5");
313
314 registrationGroupInfo.setActivityOfferingIds(activityOfferingIds);
315 registrationGroupInfo.setIsGenerated(true);
316 registrationGroupInfo.setTypeKey(LuiServiceConstants.REGISTRATION_GROUP_TYPE_KEY);
317 registrationGroupInfo.setStateKey(LuiServiceConstants.REGISTRATION_GROUP_OFFERED_STATE_KEY);
318 return registrationGroupInfo;
319 }
320
321 private RegistrationGroupInfo _constructRegistrationGroupInfo2() {
322 String extension = "-foo";
323 RegistrationGroupInfo registrationGroupInfo = new RegistrationGroupInfo();
324 registrationGroupInfo.setName("TestRegistrationGroupInfo-Id" + extension);
325 registrationGroupInfo.setStateKey("TestRegistrationGroupInfo-StateKey1" + extension);
326 registrationGroupInfo.setTypeKey("TestRegistrationGroupInfo-TypeKey1" + extension);
327 registrationGroupInfo.setFormatOfferingId("Lui-6");
328 registrationGroupInfo.setCourseOfferingId("Lui-1");
329 registrationGroupInfo.setTermId("20122");
330 registrationGroupInfo.setRegistrationCode("02" + extension);
331
332 List<String> activityOfferingIds = new ArrayList<String>();
333 activityOfferingIds.add("Lui-2");
334 activityOfferingIds.add("Lui-Lab2");
335
336 registrationGroupInfo.setActivityOfferingIds(activityOfferingIds);
337 registrationGroupInfo.setIsGenerated(true);
338 registrationGroupInfo.setTypeKey(LuiServiceConstants.REGISTRATION_GROUP_TYPE_KEY);
339 registrationGroupInfo.setStateKey(LuiServiceConstants.REGISTRATION_GROUP_OFFERED_STATE_KEY);
340 return registrationGroupInfo;
341 }
342
343 protected List<String> extractActivityOfferingIds(List<ActivityOfferingSetInfo> aoList) {
344 List<String> idList = new ArrayList<String>();
345
346 for (ActivityOfferingSetInfo activityOfferingSetInfo : aoList) {
347
348 idList.addAll(activityOfferingSetInfo.getActivityOfferingIds());
349
350 }
351 return idList;
352 }
353
354 protected ActivityOfferingClusterInfo _createAOC() {
355 ActivityOfferingClusterInfo expected;
356 try {
357 ActivityOfferingInfo activities[] = new ActivityOfferingInfo[]{
358 coServiceImpl.getActivityOffering("Lui-5", contextInfo),
359 coServiceImpl.getActivityOffering("Lui-Lab2", contextInfo),
360 coServiceImpl.getActivityOffering("Lui-8", contextInfo)};
361
362 expected = CourseOfferingServiceTestDataUtils.createActivityOfferingCluster("Lui-6", "Default Cluster",
363 Arrays.asList(activities));
364 } catch (Exception ex) {
365 throw new RuntimeException(ex);
366 }
367 return expected;
368 }
369
370
371 @Test
372 public void testRegCodeGenerator() {
373 RegistrationGroupCodeGenerator generator = new FourDigitRegistrationGroupCodeGenerator();
374 CourseOfferingService coService = new FakeCourseOfferingService();
375 try {
376 FormatOfferingInfo foInfo = coService.getFormatOffering("foo", null);
377 generator.initializeGenerator(coService, foInfo, null, null);
378 String prefix = "1";
379 int suffixVal = 1;
380 for (int i = 1; i <= 999; i++) {
381 String code = generator.generateRegistrationGroupCode(foInfo, null, null);
382 String suffix = "" + suffixVal;
383 suffixVal++;
384 if (suffixVal % 100 == 0) {
385 suffixVal++;
386 }
387 while (suffix.length() < 3) {
388 suffix = "0" + suffix;
389 }
390 String expectedCode = prefix + suffix;
391 assertEquals(expectedCode, code);
392 if (suffixVal > 999) {
393 break;
394 }
395 }
396
397 boolean codeGenerated = true;
398 try {
399 generator.generateRegistrationGroupCode(foInfo, null, null);
400 } catch (RuntimeException e) {
401 codeGenerated = false;
402 }
403 assertFalse(codeGenerated);
404 } catch (Exception e) {
405 assert (false);
406 }
407 }
408
409 @Test
410 public void testGetAndRemoveRegistrationGroupsByFormatOffering() {
411 before();
412
413 RegistrationGroupInfo info = _constructRegistrationGroupInfoById(null);
414 RegistrationGroupInfo info2 = _constructRegistrationGroupInfo2();
415 try {
416 String foId = "Lui-6";
417 String aocId = "Aoc-1";
418 coServiceImpl.createRegistrationGroup(foId, aocId, LuiServiceConstants.REGISTRATION_GROUP_TYPE_KEY, info, contextInfo);
419 coServiceImpl.createRegistrationGroup(foId, aocId, LuiServiceConstants.REGISTRATION_GROUP_TYPE_KEY, info2, contextInfo);
420
421 List<RegistrationGroupInfo> rgInfos = coServiceImpl.getRegistrationGroupsByFormatOffering(foId, contextInfo);
422 assertEquals(2, rgInfos.size());
423 for (RegistrationGroupInfo rgInfo : rgInfos) {
424 List<String> aoIds = rgInfo.getActivityOfferingIds();
425 for (String aoId : aoIds) {
426
427 LuiInfo luiInfo = luiService.getLui(aoId, contextInfo);
428 assertNotNull(luiInfo);
429 }
430 }
431
432 coServiceImpl.deleteRegistrationGroupsByFormatOffering(foId, contextInfo);
433 List<RegistrationGroupInfo> rgInfos2 = coServiceImpl.getRegistrationGroupsByFormatOffering(foId, contextInfo);
434 assertEquals(0, rgInfos2.size());
435 for (RegistrationGroupInfo rgInfo : rgInfos) {
436 boolean found = true;
437 try {
438
439 coServiceImpl.getRegistrationGroup(rgInfo.getId(), contextInfo);
440 } catch (DoesNotExistException e) {
441 found = false;
442 }
443 if (found) {
444 assert (false);
445 }
446 }
447 } catch (Exception e) {
448 e.printStackTrace();
449 assert (false);
450 }
451 }
452
453 @Test
454 public void testCreateUpdateRegistrationGroupInfoGet() {
455 before();
456
457 RegistrationGroupInfo info = _constructRegistrationGroupInfoById(null);
458 try {
459 RegistrationGroupInfo created = coServiceImpl.createRegistrationGroup("Lui-6", "Aoc-1", LuiServiceConstants.REGISTRATION_GROUP_TYPE_KEY, info, contextInfo);
460 RegistrationGroupInfo fetched = coServiceImpl.getRegistrationGroup(created.getId(), contextInfo);
461 Assert.assertEquals(created.getName(), fetched.getName());
462 Assert.assertEquals(created.getStateKey(), fetched.getStateKey());
463 Assert.assertEquals(created.getTypeKey(), fetched.getTypeKey());
464 Assert.assertEquals(created.getFormatOfferingId(), fetched.getFormatOfferingId());
465 Assert.assertEquals(created.getRegistrationCode(), fetched.getRegistrationCode());
466 Assert.assertEquals(created.getCourseOfferingId(), fetched.getCourseOfferingId());
467 Assert.assertEquals(created.getId(), fetched.getId());
468
469 List<String> activityOfferingIds = new ArrayList<String>();
470 activityOfferingIds.add("Lui-2");
471 activityOfferingIds.add("Lui-Lab2");
472 fetched.setActivityOfferingIds(null);
473 fetched.setActivityOfferingIds(activityOfferingIds);
474 fetched.setFormatOfferingId(null);
475 fetched.setFormatOfferingId("Lui-7");
476 RegistrationGroupInfo updated = coServiceImpl.updateRegistrationGroup(fetched.getId(), fetched, contextInfo);
477
478 coServiceImpl.deleteRegistrationGroup(updated.getId(), contextInfo);
479
480 try {
481 coServiceImpl.getRegistrationGroup(updated.getId(), contextInfo);
482
483 assert (false);
484 } catch (DoesNotExistException e) {
485 assert (true);
486 }
487 } catch (Exception e) {
488 e.printStackTrace();
489 assert (false);
490 }
491 }
492
493 @Test
494 public void testPopulation() {
495 before();
496 List<PopulationInfo> popList = _constructPopulationList();
497 try {
498 PopulationInfo refCreated = populationService.createPopulation(popList.get(0), contextInfo);
499 PopulationInfo threeCreated = populationService.createPopulation(popList.get(1), contextInfo);
500 PopulationInfo fourCreated = populationService.createPopulation(popList.get(2), contextInfo);
501
502 PopulationRuleInfo ruleInfo = _constructExclusionPopulationRuleInfo();
503 ruleInfo.setReferencePopulationId(refCreated.getId());
504 List<String> childIds = new ArrayList<String>();
505 childIds.add(threeCreated.getId());
506 childIds.add(fourCreated.getId());
507 ruleInfo.setChildPopulationIds(childIds);
508
509 PopulationRuleInfo ruleInfoCreated = populationService.createPopulationRule(ruleInfo, contextInfo);
510
511 PopulationRuleInfo ruleInfoFetched = populationService.getPopulationRule(ruleInfoCreated.getId(), contextInfo);
512 PopulationInfo combined = populationService.createPopulation(popList.get(3), contextInfo);
513 populationService.applyPopulationRuleToPopulation(ruleInfoFetched.getId(), combined.getId(), contextInfo);
514 SeatPoolDefinitionInfo info = _constructSeatPoolDefinitionInfoById(null);
515 info.setPopulationId(combined.getId());
516 SeatPoolDefinitionInfo created = coServiceImpl.createSeatPoolDefinition(info, contextInfo);
517 PopulationInfo retrieved = populationService.getPopulation(created.getPopulationId(), contextInfo);
518 assertEquals(combined.getId(), retrieved.getId());
519 } catch (Exception e) {
520 e.printStackTrace();
521 assert (false);
522 }
523 }
524
525 @Test
526 public void testCreateSeatPoolDefinitionGet() {
527 before();
528 SeatPoolDefinitionInfo info = _constructSeatPoolDefinitionInfoById(null);
529 try {
530 SeatPoolDefinitionInfo created = coServiceImpl.createSeatPoolDefinition(info, contextInfo);
531 SeatPoolDefinitionInfo fetched = coServiceImpl.getSeatPoolDefinition(created.getId(), contextInfo);
532 Assert.assertEquals(info.getName(), fetched.getName());
533 Assert.assertEquals(info.getStateKey(), fetched.getStateKey());
534 Assert.assertEquals(info.getTypeKey(), fetched.getTypeKey());
535 Assert.assertEquals(info.getExpirationMilestoneTypeKey(), fetched.getExpirationMilestoneTypeKey());
536 Assert.assertEquals(info.getIsPercentage(), fetched.getIsPercentage());
537 Assert.assertEquals(info.getSeatLimit(), fetched.getSeatLimit());
538 Assert.assertEquals(info.getProcessingPriority(), fetched.getProcessingPriority());
539 } catch (Exception e) {
540 e.printStackTrace();
541 fail(e.getMessage());
542 }
543 }
544
545 @Test
546 public void testCreateSeatPoolDefinitionUpdateDelete() {
547 before();
548 SeatPoolDefinitionInfo info = _constructSeatPoolDefinitionInfoById(null);
549 try {
550 SeatPoolDefinitionInfo created = coServiceImpl.createSeatPoolDefinition(info, contextInfo);
551 SeatPoolDefinitionInfo fetched = coServiceImpl.getSeatPoolDefinition(created.getId(), contextInfo);
552 fetched.setSeatLimit(5);
553 fetched.setExpirationMilestoneTypeKey(AtpServiceConstants.MILESTONE_SEATPOOL_FIRST_DAY_OF_CLASSES_TYPE_KEY);
554 coServiceImpl.updateSeatPoolDefinition(fetched.getId(), fetched, contextInfo);
555 SeatPoolDefinitionInfo fetched2 = coServiceImpl.getSeatPoolDefinition(created.getId(), contextInfo);
556 assertEquals(new Integer(5), fetched2.getSeatLimit());
557 assertEquals(AtpServiceConstants.MILESTONE_SEATPOOL_FIRST_DAY_OF_CLASSES_TYPE_KEY, fetched2.getExpirationMilestoneTypeKey());
558 coServiceImpl.deleteSeatPoolDefinition(fetched.getId(), contextInfo);
559 boolean found = true;
560 try {
561 coServiceImpl.getSeatPoolDefinition(fetched.getId(), contextInfo);
562 } catch (DoesNotExistException e) {
563 found = false;
564 }
565 if (found) {
566 assert (false);
567 }
568 } catch (Exception e) {
569 e.printStackTrace();
570 assert (false);
571 }
572 }
573
574 @Test
575 public void testGenerateRegistrationGroupsSimple() throws DoesNotExistException,
576 InvalidParameterException, MissingParameterException,
577 OperationFailedException, PermissionDeniedException, AlreadyExistsException {
578
579 before();
580 try {
581
582 coServiceImpl.createActivityOfferingCluster("Lui-6", CourseOfferingServiceConstants.AOC_ROOT_TYPE_KEY, _createAOC(), contextInfo);
583
584
585 List<BulkStatusInfo> status = coServiceImpl.generateRegistrationGroupsForFormatOffering("Lui-6", contextInfo);
586 assertNotNull(status);
587 Assert.assertEquals(2, status.size());
588
589
590 List<RegistrationGroupInfo> rgList = coServiceImpl.getRegistrationGroupsByFormatOffering("Lui-6", contextInfo);
591 Assert.assertEquals(2, rgList.size());
592
593 } catch (Exception e) {
594 e.printStackTrace();
595 fail(e.getMessage());
596 }
597 }
598
599 @Test
600 public void testCreateAOCSimple() {
601 before();
602 try {
603 ActivityOfferingClusterInfo aocInfo = new ActivityOfferingClusterInfo();
604 FormatOfferingInfo foInfo = coServiceImpl.getFormatOffering("Lui-6", contextInfo);
605
606 List<String> aoTypeKeys = new ArrayList<String>();
607 aoTypeKeys.add(LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY);
608 aoTypeKeys.add(LuiServiceConstants.LAB_ACTIVITY_OFFERING_TYPE_KEY);
609 foInfo.setActivityOfferingTypeKeys(aoTypeKeys);
610 coServiceImpl.updateFormatOffering(foInfo.getId(), foInfo, contextInfo);
611
612 aocInfo.setFormatOfferingId(foInfo.getId());
613 aocInfo.setStateKey(CourseOfferingServiceConstants.AOC_ACTIVE_STATE_KEY);
614 aocInfo.setTypeKey(CourseOfferingServiceConstants.AOC_ROOT_TYPE_KEY);
615 ActivityOfferingClusterInfo created =
616 coServiceImpl.createActivityOfferingCluster(foInfo.getId(), aocInfo.getTypeKey(), aocInfo, contextInfo);
617 assertNotNull(created.getActivityOfferingSets());
618 } catch (Exception e) {
619 assert(false);
620 }
621 }
622
623 @Test
624 public void testActivityOfferingClusterCRUDsPlus() throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException {
625
626 before();
627
628 ActivityOfferingClusterInfo expected = _createAOC();
629 new AttributeTester().add2ForCreate(expected.getAttributes());
630
631
632 ActivityOfferingClusterInfo actual = coServiceImpl.createActivityOfferingCluster("Lui-6", CourseOfferingServiceConstants.AOC_ROOT_TYPE_KEY, expected, contextInfo);
633 assertNotNull(actual.getId());
634
635 new AttributeTester().check(expected.getAttributes(), actual.getAttributes());
636 new MetaTester().checkAfterCreate(actual.getMeta());
637
638
639 try {
640
641 ActivityOfferingClusterInfo copy = coServiceImpl.createActivityOfferingCluster("Lui-6", CourseOfferingServiceConstants.AOC_ROOT_TYPE_KEY, expected, contextInfo);
642 assertEquals(copy.getName(), "Default Cluster");
643 copy.setName("Updated");
644
645 coServiceImpl.updateActivityOfferingCluster("Lui-6", copy.getId(), copy, contextInfo) ;
646
647 copy = coServiceImpl.getActivityOfferingCluster(copy.getId(), contextInfo);
648 assertEquals(copy.getName(), "Updated");
649
650 coServiceImpl.deleteActivityOfferingCluster(copy.getId(), contextInfo);
651 boolean found = true;
652 try {
653 coServiceImpl.getActivityOfferingCluster(copy.getId(), contextInfo);
654 } catch (DoesNotExistException e) {
655 found = false;
656 }
657 if (found) {
658 assert (false);
659 }
660 } catch (Exception ex) {
661 throw new RuntimeException("update failed - " + ex);
662 }
663
664
665 new ListOfStringTester().checkExistsAnyOrder(Arrays.asList("Lui-5", "Lui-Lab2", "Lui-8"),
666 extractActivityOfferingIds(actual.getActivityOfferingSets()), true);
667
668
669 List<RegistrationGroupInfo> rgList = coServiceImpl.getRegistrationGroupsByActivityOfferingCluster(actual.getId(), contextInfo);
670 assertEquals(0, rgList.size());
671
672
673 coServiceImpl.generateRegistrationGroupsForCluster(actual.getId(), contextInfo);
674
675 rgList = coServiceImpl.getRegistrationGroupsByActivityOfferingCluster(actual.getId(), contextInfo);
676 assertEquals(2, rgList.size());
677
678
679 coServiceImpl.generateRegistrationGroupsForCluster(actual.getId(), contextInfo);
680
681
682 rgList = coServiceImpl.getRegistrationGroupsByActivityOfferingCluster(actual.getId(), contextInfo);
683 assertEquals(2, rgList.size());
684 }
685
686
687
688
689 @Test
690 @Ignore
691 public void testSearchForMethods () throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException {
692
693 before();
694
695 Builder builder = QueryByCriteria.Builder.create();
696
697
698
699
700 builder.setPredicates(PredicateFactory.equal("luiType", LuiServiceConstants.COURSE_OFFERING_TYPE_KEY));
701
702 List<String> expectedCOIds = coServiceImpl.searchForCourseOfferingIds(builder.build(), callContext);
703
704 log.info (String.format("%d expected", expectedCOIds.size()));
705
706 builder = QueryByCriteria.Builder.create();
707
708 List<String> actualCOIds = coServiceImpl.searchForCourseOfferingIds(builder.build(), callContext);
709
710 log.info (String.format("%d actual", actualCOIds.size()));
711
712 assertEquals(expectedCOIds.size(), actualCOIds.size());
713
714 assertTrue (CollectionUtils.isEqualCollection(expectedCOIds, actualCOIds));
715
716
717
718
719
720 builder = QueryByCriteria.Builder.create();
721
722
723
724
725 builder.setPredicates(PredicateFactory.equal("luiType", LuiServiceConstants.COURSE_OFFERING_TYPE_KEY));
726
727 builder.setMaxResults(2);
728 builder.setStartAtIndex(0);
729
730 List<CourseOfferingInfo> expectedCOs = coServiceImpl.searchForCourseOfferings(builder.build(), callContext);
731
732 log.info (String.format("%d expected", expectedCOs.size()));
733
734 builder = QueryByCriteria.Builder.create();
735
736 builder.setMaxResults(2);
737 builder.setStartAtIndex(0);
738
739 List<CourseOfferingInfo> actualCOs = coServiceImpl.searchForCourseOfferings(builder.build(), callContext);
740
741 log.info (String.format("%d actual", actualCOs.size()));
742
743 assertEquals(expectedCOs.size(), actualCOs.size());
744
745 assertTrue (CollectionUtils.isEqualCollection(expectedCOs, actualCOs));
746
747 }
748
749 }