View Javadoc

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