View Javadoc

1   package org.kuali.student.enrollment.class2.courseoffering.service.impl;
2   
3   import org.junit.Before;
4   import org.junit.Test;
5   import org.junit.runner.RunWith;
6   import org.kuali.student.common.util.UUIDHelper;
7   import org.kuali.student.enrollment.class1.lui.service.impl.LuiServiceDataLoader;
8   import org.kuali.student.enrollment.class2.acal.util.AcalTestDataLoader;
9   import org.kuali.student.enrollment.class2.acal.util.MockAcalTestDataLoader;
10  import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo;
11  import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
12  import org.kuali.student.enrollment.courseoffering.dto.FinalExam;
13  import org.kuali.student.enrollment.courseoffering.dto.FormatOfferingInfo;
14  import org.kuali.student.enrollment.courseoffering.dto.OfferingInstructorInfo;
15  import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
16  import org.kuali.student.enrollment.lui.dto.LuiSetInfo;
17  import org.kuali.student.enrollment.lui.service.LuiService;
18  import org.kuali.student.lum.lrc.service.util.MockLrcTestDataLoader;
19  import org.kuali.student.r2.common.dto.AttributeInfo;
20  import org.kuali.student.r2.common.dto.ContextInfo;
21  import org.kuali.student.r2.common.dto.MetaInfo;
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.DataValidationErrorException;
25  import org.kuali.student.r2.common.exceptions.DependentObjectsExistException;
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.exceptions.VersionMismatchException;
33  import org.kuali.student.r2.common.util.ContextUtils;
34  import org.kuali.student.r2.common.util.constants.LuServiceConstants;
35  import org.kuali.student.r2.common.util.constants.LuiServiceConstants;
36  import org.kuali.student.r2.core.acal.service.AcademicCalendarService;
37  import org.kuali.student.r2.core.atp.service.AtpService;
38  import org.kuali.student.r2.core.class1.state.dto.LifecycleInfo;
39  import org.kuali.student.r2.core.class1.state.dto.StateInfo;
40  import org.kuali.student.r2.core.class1.state.service.StateService;
41  import org.kuali.student.r2.core.constants.AtpServiceConstants;
42  import org.kuali.student.r2.lum.course.dto.CourseInfo;
43  import org.kuali.student.r2.lum.course.service.CourseService;
44  import org.kuali.student.r2.lum.lrc.service.LRCService;
45  import org.kuali.student.r2.lum.util.constants.LrcServiceConstants;
46  import org.springframework.test.context.ContextConfiguration;
47  import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
48  
49  import javax.annotation.Resource;
50  import java.util.*;
51  
52  import static org.junit.Assert.assertEquals;
53  import static org.junit.Assert.assertNotNull;
54  import static org.junit.Assert.assertTrue;
55  import static org.junit.Assert.fail;
56  
57  @RunWith(SpringJUnit4ClassRunner.class)
58  @ContextConfiguration(locations = {"classpath:co-test-with-mocks-context.xml"})
59  public class TestCourseOfferingServiceImplWithMocks {
60  
61      @Resource(name = "coService")
62      protected CourseOfferingService courseOfferingService;
63      public static String principalId = "123";
64      public ContextInfo callContext = null;
65      @Resource(name = "courseService")
66      protected CourseService courseService;
67      @Resource(name="stateService")
68      protected StateService stateService;
69      @Resource(name = "luiService")
70      protected LuiService luiService;
71      @Resource(name = "acalService")
72      protected AcademicCalendarService acalService;
73      @Resource(name = "atpService")
74      protected AtpService atpService;
75      @Resource(name = "LrcService")
76      protected LRCService lrcService;
77  
78      @Before
79      public void setUp() {
80          callContext = new ContextInfo();
81          callContext.setPrincipalId(principalId);
82          try {
83              new CourseR1TestDataLoader(this.courseService).loadData();
84              new LuiServiceDataLoader(this.luiService).loadData();
85  
86              // due to KSENROLL-4185, data must be loaded into the mock Atp and mock Acal services
87              AcalTestDataLoader acalLoader = new AcalTestDataLoader(this.atpService);
88              acalLoader.loadTerm("testAtpId1", "test1", "2000-01-01 00:00:00.0", "2100-12-31 00:00:00.0", AtpServiceConstants.ATP_FALL_TYPE_KEY, AtpServiceConstants.ATP_OFFICIAL_STATE_KEY, "description 1");
89              new MockAcalTestDataLoader(this.acalService).loadData();
90              new MockLrcTestDataLoader(this.lrcService).loadData();
91  
92              createStateTestData();
93          } catch (Exception ex) {
94              throw new RuntimeException(ex);
95          }
96  
97      }
98  
99      private void createStateTestData() throws Exception {
100 
101         // ActivityOffering state
102         cleanupStateTestData( LuiServiceConstants.LUI_AO_STATE_DRAFT_KEY );
103         cleanupLifecycleTestData( LuiServiceConstants.ACTIVITY_OFFERING_LIFECYCLE_KEY );
104         LifecycleInfo aoLifecycle = addLifecycle( LuiServiceConstants.ACTIVITY_OFFERING_LIFECYCLE_KEY );
105         addState( aoLifecycle, LuiServiceConstants.LUI_AO_STATE_DRAFT_KEY, true );
106 
107         // FormatOffering state
108         cleanupStateTestData( LuiServiceConstants.LUI_FO_STATE_DRAFT_KEY );
109         cleanupLifecycleTestData( LuiServiceConstants.FORMAT_OFFERING_LIFECYCLE_KEY );
110         LifecycleInfo foLifecycle = addLifecycle( LuiServiceConstants.FORMAT_OFFERING_LIFECYCLE_KEY );
111         addState( foLifecycle, LuiServiceConstants.LUI_FO_STATE_DRAFT_KEY, true );
112 
113         // CourseOffering state
114         cleanupStateTestData( LuiServiceConstants.LUI_CO_STATE_DRAFT_KEY );
115         cleanupLifecycleTestData( LuiServiceConstants.COURSE_OFFERING_LIFECYCLE_KEY );
116         LifecycleInfo coLifecycle = addLifecycle( LuiServiceConstants.COURSE_OFFERING_LIFECYCLE_KEY );
117         addState( coLifecycle, LuiServiceConstants.LUI_CO_STATE_DRAFT_KEY, true );
118     }
119 
120     // TODO: temporary stop-gap because SS throws an error about duplicate-data; this cleans state from previous runs
121     private void cleanupStateTestData( String state ) {
122         try {
123             stateService.deleteState( state, callContext );
124         } catch( Exception e ) { }
125     }
126 
127     // TODO: temporary stop-gap because SS throws an error about duplicate-data; this cleans state from previous runs
128     private void cleanupLifecycleTestData( String name ) {
129         try {
130             stateService.deleteLifecycle( name, callContext );
131         } catch( Exception e ) { }
132     }
133 
134     private LifecycleInfo addLifecycle( String name ) throws Exception {
135 
136         LifecycleInfo origLife = new LifecycleInfo();
137         RichTextInfo rti = new RichTextInfo();
138         rti.setFormatted("<b>Formatted</b> lifecycle for testing purposes");
139         rti.setPlain("Plain lifecycle for testing purposes");
140         origLife.setDescr(rti);
141         origLife.setKey( name );
142         origLife.setName( "TEST_NAME" );
143         origLife.setRefObjectUri( "TEST_URI" );
144         AttributeInfo attr = new AttributeInfo();
145         attr.setKey("attribute.key");
146         attr.setValue("attribute value");
147         origLife.getAttributes().add(attr);
148 
149         return stateService.createLifecycle(origLife.getKey(), origLife, callContext);
150     }
151 
152     private StateInfo addState( LifecycleInfo lifecycleInfo, String state, boolean isInitialState ) throws Exception {
153 
154         StateInfo orig = new StateInfo();
155         orig.setKey(state);
156         orig.setLifecycleKey(lifecycleInfo.getKey());
157         RichTextInfo rti = new RichTextInfo();
158         rti.setFormatted("<b>Formatted again</b> state for testing purposes");
159         rti.setPlain("Plain state again for testing purposes");
160         orig.setDescr(rti);
161         orig.setName("Testing state");
162         Date effDate = new Date();
163         orig.setEffectiveDate(effDate);
164         Calendar cal = Calendar.getInstance();
165         cal.set(2022, 8, 23);
166         orig.setExpirationDate(cal.getTime());
167         AttributeInfo attr = new AttributeInfo();
168         attr.setKey("attribute.key");
169         attr.setValue("attribute value");
170         orig.getAttributes().add(attr);
171         orig.setIsInitialState(isInitialState);
172 
173         return stateService.createState(orig.getLifecycleKey(), orig.getKey(), orig, callContext);
174     }
175 
176     @Test
177     public void testCRUD() throws DoesNotExistException,
178             DataValidationErrorException, InvalidParameterException, MissingParameterException,
179             OperationFailedException, PermissionDeniedException, ReadOnlyException, VersionMismatchException,
180             DependentObjectsExistException {
181         CourseOfferingInfo co = this.testCRUDCourseOffering();
182         FormatOfferingInfo fo = this.testCRUDFormatOffering(co);
183         ActivityOfferingInfo ao = this.testCRUDActivityOffering(fo);
184         this.testDeletes(co, fo, ao);
185     }
186     public CourseOfferingInfo testCRUDCourseOffering() throws DoesNotExistException,
187             DataValidationErrorException, InvalidParameterException, MissingParameterException,
188             OperationFailedException, PermissionDeniedException, ReadOnlyException, VersionMismatchException {
189         // get course
190         CourseInfo course;
191         try {
192             course = courseService.getCourse("COURSE1", ContextUtils.getContextInfo());
193         } catch (Exception ex) {
194             throw new RuntimeException(ex);
195         }
196         // create co from course
197         List<String> optionKeys = new ArrayList<String>();
198         CourseOfferingInfo orig = new CourseOfferingInfo();
199         orig.setCourseId(course.getId());
200         orig.setTermId("testAtpId1");
201         orig.setTypeKey(LuiServiceConstants.COURSE_OFFERING_TYPE_KEY);
202         orig.setStateKey(LuiServiceConstants.LUI_CO_STATE_DRAFT_KEY);
203         orig.setCourseOfferingTitle("my name");
204         orig.setWaitlistLevelTypeKey("waitlist key");
205         orig.setHasWaitlist(true);
206         orig.setFinalExamType(FinalExam.STANDARD.toString());
207         orig.setIsEvaluated(true);
208         orig.setIsFeeAtActivityOffering(false);
209         orig.setFundingSource("funding source");
210         orig.setCourseOfferingCode("CODE");
211         orig.setCourseNumberSuffix("");
212         orig.setCourseOfferingTitle("Title");
213         orig.getStudentRegistrationGradingOptions().add(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_AUDIT);
214         orig.getStudentRegistrationGradingOptions().add(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_PASSFAIL);
215         orig.setGradingOptionId(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_LETTER);
216 
217 
218         CourseOfferingInfo info = courseOfferingService.createCourseOffering(orig.getCourseId(), orig.getTermId(), 
219                 orig.getTypeKey(), orig, optionKeys, callContext);
220         assertNotNull(info);
221         assertNotNull(info.getId());
222         assertEquals(orig.getCourseId(), info.getCourseId());
223         assertEquals(orig.getTermId(), info.getTermId());
224         assertEquals(orig.getStateKey(), info.getStateKey());
225         assertEquals(orig.getTypeKey(), info.getTypeKey());
226         assertEquals(orig.getWaitlistLevelTypeKey(), info.getWaitlistLevelTypeKey());
227         assertEquals(orig.getHasWaitlist(), info.getHasWaitlist());
228         assertEquals(orig.getFinalExamType(), info.getFinalExamType());
229         assertEquals(orig.getIsFeeAtActivityOffering(), info.getIsFeeAtActivityOffering());
230         assertEquals(orig.getFundingSource(), info.getFundingSource());
231         assertEquals(course.getCode() + info.getCourseNumberSuffix(), info.getCourseOfferingCode());
232         assertEquals(orig.getCourseNumberSuffix(), info.getCourseNumberSuffix());
233         assertEquals(course.getSubjectArea(), info.getSubjectArea());
234         if (course.getDescr() != null) {
235             assertEquals(course.getDescr().getPlain(), info.getDescr().getPlain());
236             assertEquals(course.getDescr().getFormatted(), info.getDescr().getFormatted());
237         }
238 //        assertEquals(2,info.getStudentRegistrationOptionIds().size());
239 //        assertTrue(info.getStudentRegistrationOptionIds().contains(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_AUDIT));
240 //        assertTrue(info.getStudentRegistrationOptionIds().contains(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_PASSFAIL));
241 //
242 //        assertEquals(2,info.getGradingOptionIds().size());
243 //        assertTrue(info.getGradingOptionIds().contains(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_LETTER));
244 //        assertTrue(info.getGradingOptionIds().contains(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_PERCENTAGE));
245 
246         // TODO: test for these things 
247 //        assertEquals(course.getUnitsContentOwnerOrgIds(), info.getUnitsContentOwnerOrgIds());
248 //        assertEquals(course.getUnitsDeploymentOrgIds(), info.getUnitsDeploymentOrgIds());
249 //        assertEquals(course.getGradingOptions(), info.getGradingOptionIds());
250 //        assertEquals(course.getCreditOptionIds(), info.getCreditOptionIds());
251 
252 
253         // refetch co 
254         orig = info;
255         info = courseOfferingService.getCourseOffering(orig.getId(), callContext);
256         assertNotNull(info);
257         assertEquals(orig.getId(), info.getId());
258         assertEquals(orig.getCourseId(), info.getCourseId());
259         assertEquals(orig.getTermId(), info.getTermId());
260         assertEquals(orig.getStateKey(), info.getStateKey());
261         assertEquals(orig.getTypeKey(), info.getTypeKey());
262 
263         // update co
264         orig = info;
265         orig.setIsHonorsOffering(true);
266         orig.setMaximumEnrollment(40);
267         orig.setMinimumEnrollment(10);
268         List<OfferingInstructorInfo> instructors = new ArrayList<OfferingInstructorInfo>();
269 //        OfferingInstructorInfo instructor = new OfferingInstructorInfo();
270 //        instructor.setPersonId("Pers-1");
271 //        instructor.setPercentageEffort(Float.valueOf("60"));
272 //        instructor.setTypeKey(LprServiceConstants.INSTRUCTOR_MAIN_TYPE_KEY);
273 //        instructor.setStateKey(LprServiceConstants.ASSIGNED_STATE_KEY);
274         // TODO: add this back in and test for it
275 //        instructors.add(instructor);
276         orig.setInstructors(instructors);
277         info = courseOfferingService.updateCourseOffering(orig.getId(), orig, callContext);
278         assertNotNull(info);
279         assertEquals(orig.getId(), info.getId());
280         assertEquals(orig.getCourseId(), info.getCourseId());
281         assertEquals(orig.getTermId(), info.getTermId());
282         assertEquals(orig.getStateKey(), info.getStateKey());
283         assertEquals(orig.getTypeKey(), info.getTypeKey());
284         assertEquals(orig.getIsHonorsOffering(), info.getIsHonorsOffering());
285         assertEquals(orig.getMaximumEnrollment(), info.getMaximumEnrollment());
286         assertEquals(orig.getMinimumEnrollment(), info.getMinimumEnrollment());
287         assertEquals(orig.getInstructors().size(), info.getInstructors().size());
288 //        OfferingInstructorInfo origInst1 = orig.getInstructors().get(0);
289 //        OfferingInstructorInfo infoInst1 = info.getInstructors().get(0);
290 //        assertEquals(origInst1.getPersonId(), infoInst1.getPersonId());
291 //        assertEquals(origInst1.getPercentageEffort(), infoInst1.getPercentageEffort());
292 //        assertEquals(origInst1.getTypeKey(), infoInst1.getTypeKey());
293 //        assertEquals(origInst1.getStateKey(), infoInst1.getStateKey());
294         return info;
295     }
296 
297     private void testDeletes(CourseOfferingInfo co, FormatOfferingInfo fo, ActivityOfferingInfo ao)
298             throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DoesNotExistException, DependentObjectsExistException {
299 
300         // delete activity offering
301         StatusInfo status = this.courseOfferingService.deleteActivityOffering(ao.getId(), callContext);
302         assertNotNull(status);
303         assertEquals(Boolean.TRUE, status.getIsSuccess());
304 
305         try {
306             ao = courseOfferingService.getActivityOffering(ao.getId(), callContext);
307             fail("should have thrown DoesNotExistException");
308         } catch (DoesNotExistException ex) {
309             // expected
310         }
311 
312 
313         // delete fo
314         status = this.courseOfferingService.deleteFormatOffering(fo.getId(), callContext);
315         assertNotNull(status);
316         assertEquals(Boolean.TRUE, status.getIsSuccess());
317 
318         try {
319             fo = courseOfferingService.getFormatOffering(fo.getId(), callContext);
320             fail("should have thrown DoesNotExistException");
321         } catch (DoesNotExistException ex) {
322             // expected
323         }
324 
325         // delete co
326         status = this.courseOfferingService.deleteCourseOffering(co.getId(), callContext);
327         assertNotNull(status);
328         assertEquals(Boolean.TRUE, status.getIsSuccess());
329 
330         try {
331             co = courseOfferingService.getCourseOffering(co.getId(), callContext);
332             fail("should have thrown DoesNotExistException");
333         } catch (DoesNotExistException ex) {
334             // expected
335         }
336     }
337 
338     public FormatOfferingInfo testCRUDFormatOffering(CourseOfferingInfo co)
339             throws DoesNotExistException,
340             InvalidParameterException, MissingParameterException,
341             OperationFailedException, PermissionDeniedException, DataValidationErrorException,
342                    VersionMismatchException, ReadOnlyException, DependentObjectsExistException {
343         FormatOfferingInfo orig = new FormatOfferingInfo();
344         orig.setCourseOfferingId(co.getId());
345         orig.setFormatId("COURSE1-FORMAT1");
346         orig.setActivityOfferingTypeKeys(Arrays.asList(LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY));
347         orig.setTypeKey(LuiServiceConstants.FORMAT_OFFERING_TYPE_KEY);
348         orig.setStateKey(LuiServiceConstants.LUI_FO_STATE_DRAFT_KEY);
349         FormatOfferingInfo info = courseOfferingService.createFormatOffering(orig.getCourseOfferingId(), orig.getFormatId(), orig.getTypeKey(), orig, callContext);
350         assertNotNull(info);
351         assertNotNull(info.getId());
352         assertEquals(orig.getCourseOfferingId(), info.getCourseOfferingId());
353         assertEquals(orig.getStateKey(), info.getStateKey());
354         assertEquals(orig.getTypeKey(), info.getTypeKey());
355         assertEquals(orig.getFormatId(), info.getFormatId());
356         // TODO: turn these tests back on once we get the corresponding JPA entities working 
357 //        assertEquals(orig.getActivityOfferingTypeKeys().size(), info.getActivityOfferingTypeKeys().size());
358 //        assertEquals(orig.getActivityOfferingTypeKeys().get(0), info.getActivityOfferingTypeKeys().get(0));
359 
360         List<FormatOfferingInfo> formats = courseOfferingService.getFormatOfferingsByCourseOffering(co.getId(), callContext);
361         info = formats.get(0);
362         assertNotNull(info);
363         assertNotNull(info.getId());
364         assertEquals(orig.getCourseOfferingId(), info.getCourseOfferingId());
365         assertEquals(orig.getStateKey(), info.getStateKey());
366         assertEquals(orig.getTypeKey(), info.getTypeKey());
367         assertEquals(orig.getFormatId(), info.getFormatId());
368 
369         orig = info;
370         info = courseOfferingService.getFormatOffering(orig.getId(), callContext);
371         assertNotNull(info);
372         assertEquals(orig.getId(), info.getId());
373         assertEquals(orig.getCourseOfferingId(), info.getCourseOfferingId());
374         assertEquals(orig.getStateKey(), info.getStateKey());
375         assertEquals(orig.getTypeKey(), info.getTypeKey());
376         assertEquals(orig.getFormatId(), info.getFormatId());
377 //        assertEquals(orig.getActivityOfferingTypeKeys().size(), info.getActivityOfferingTypeKeys().size());
378 //        assertEquals(orig.getActivityOfferingTypeKeys().get(0), info.getActivityOfferingTypeKeys().get(0));
379 
380         orig = info;
381         orig.setActivityOfferingTypeKeys(Arrays.asList(LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY));
382         info = courseOfferingService.updateFormatOffering(orig.getId(), orig, callContext);
383         assertNotNull(info);
384         assertEquals(orig.getId(), info.getId());
385         assertEquals(orig.getCourseOfferingId(), info.getCourseOfferingId());
386         assertEquals(orig.getStateKey(), info.getStateKey());
387         assertEquals(orig.getTypeKey(), info.getTypeKey());
388         assertEquals(orig.getFormatId(), info.getFormatId());
389 //        assertEquals(orig.getActivityOfferingTypeKeys().size(), info.getActivityOfferingTypeKeys().size());
390 //        assertEquals(orig.getActivityOfferingTypeKeys().get(0), info.getActivityOfferingTypeKeys().get(0));
391         return info;
392     }
393 
394 
395     public ActivityOfferingInfo testCRUDActivityOffering(FormatOfferingInfo fo)
396             throws DoesNotExistException,
397             InvalidParameterException, MissingParameterException,
398             OperationFailedException, PermissionDeniedException, DataValidationErrorException,
399             ReadOnlyException, VersionMismatchException {
400 
401         ActivityOfferingInfo orig = new ActivityOfferingInfo();
402         orig.setFormatOfferingId(fo.getId());
403         orig.setActivityId(fo.getId() + "." + LuServiceConstants.COURSE_ACTIVITY_LECTURE_TYPE_KEY);
404         orig.setTypeKey(LuiServiceConstants.LECTURE_ACTIVITY_OFFERING_TYPE_KEY);
405         orig.setStateKey(LuiServiceConstants.LUI_AO_STATE_DRAFT_KEY);
406         orig.setMinimumEnrollment(100);
407         orig.setMaximumEnrollment(150);
408         orig.setIsEvaluated(true);
409         orig.setIsMaxEnrollmentEstimate(false);
410         orig.setIsHonorsOffering(true);
411         ActivityOfferingInfo info = courseOfferingService.createActivityOffering(orig.getFormatOfferingId(), orig.getActivityId(), orig.getTypeKey(), orig, callContext);
412         assertNotNull(info);
413         assertNotNull(info.getId());
414         assertEquals(orig.getStateKey(), info.getStateKey());
415         assertEquals(orig.getTypeKey(), info.getTypeKey());
416         assertEquals(orig.getFormatOfferingId(), info.getFormatOfferingId());
417         assertEquals(orig.getActivityId(), info.getActivityId());
418         assertEquals(orig.getMinimumEnrollment(), info.getMinimumEnrollment());
419         assertEquals(orig.getMaximumEnrollment(), info.getMaximumEnrollment());
420         assertEquals(orig.getIsEvaluated(), info.getIsEvaluated());
421         assertEquals(orig.getIsMaxEnrollmentEstimate(), info.getIsMaxEnrollmentEstimate());
422         assertEquals(orig.getIsHonorsOffering(), info.getIsHonorsOffering());
423 
424         orig = info;
425         info = courseOfferingService.getActivityOffering(orig.getId(), callContext);
426         assertNotNull(info);
427         assertEquals(orig.getId(), info.getId());
428         assertEquals(orig.getStateKey(), info.getStateKey());
429         assertEquals(orig.getTypeKey(), info.getTypeKey());
430         assertEquals(orig.getFormatOfferingId(), info.getFormatOfferingId());
431         assertEquals(orig.getActivityId(), info.getActivityId());
432         assertEquals(orig.getMinimumEnrollment(), info.getMinimumEnrollment());
433         assertEquals(orig.getMaximumEnrollment(), info.getMaximumEnrollment());
434 
435         orig = info;
436         orig.setMinimumEnrollment(100);
437         info = courseOfferingService.updateActivityOffering(orig.getId(), orig, callContext);
438         assertNotNull(info);
439         assertEquals(orig.getId(), info.getId());
440         assertEquals(orig.getStateKey(), info.getStateKey());
441         assertEquals(orig.getTypeKey(), info.getTypeKey());;
442         assertEquals(orig.getFormatOfferingId(), info.getFormatOfferingId());
443         assertEquals(orig.getActivityId(), info.getActivityId());
444         assertEquals(orig.getMinimumEnrollment(), info.getMinimumEnrollment());
445         assertEquals(orig.getMaximumEnrollment(), info.getMaximumEnrollment());
446         return info;
447 
448     }
449 
450 
451     @Test
452     public void testLuiServiceLuiSetMethods() throws Throwable {
453         System.out.println("starting tests...");
454 
455         String luiSetTypeKey = "test.lui.set.type.key.test";
456         LuiSetInfo luiSetInfo = new LuiSetInfo();
457         RichTextInfo descr = new RichTextInfo();
458         descr.setPlain( "descr" );
459         luiSetInfo.setDescr( descr );
460         luiSetInfo.setStateKey( "test.lui.set.state.key.test" );
461         luiSetInfo.setTypeKey( luiSetTypeKey );
462         luiSetInfo.setName( "name" );
463         luiSetInfo.setEffectiveDate( new Date() );
464         luiSetInfo.setExpirationDate( new Date() );
465         luiSetInfo.setMeta( new MetaInfo() );
466         luiSetInfo.setAttributes( new ArrayList<AttributeInfo>() );
467 
468         // create
469         LuiSetInfo created = luiService.createLuiSet( luiSetTypeKey, luiSetInfo, callContext );
470         assertNotNull(created);
471         assertTrue(UUIDHelper.isUUID(created.getId()));
472 
473         // read
474         LuiSetInfo retrieved = luiService.getLuiSet( created.getId(), callContext );
475         assertNotNull( retrieved );
476         assertEquals( created.getId(), retrieved.getId() );
477 
478         // update
479         retrieved.setName( "updated_name");
480         LuiSetInfo replaced = luiService.updateLuiSet( created.getId(), retrieved, callContext );
481         LuiSetInfo updated = luiService.getLuiSet( created.getId(), callContext );
482         assertNotNull(replaced);
483         assertNotNull(updated);
484         assertEquals(created.getId(), replaced.getId());
485         assertEquals( created.getId(), updated.getId() );
486         assertEquals( created.getName(), replaced.getName() );
487         assertEquals( retrieved.getName(), updated.getName() );
488 
489         // delete
490         StatusInfo deleteStatus = luiService.deleteLuiSet( created.getId(), callContext );
491         assertNotNull(deleteStatus);
492         assertTrue(deleteStatus.getIsSuccess());
493         try {
494             retrieved = luiService.getLuiSet(created.getId(), callContext);
495             fail("should have thrown DoesNotExistException");
496         } catch (DoesNotExistException ex) {
497             // expected
498         }
499 
500         // bulk operation -- get a bunch of luis using a list of their ids
501         List<String> createdLuiSetIds = new ArrayList<String>();
502         createdLuiSetIds.add(luiService.createLuiSet(luiSetTypeKey, luiSetInfo, callContext).getId());
503         createdLuiSetIds.add( luiService.createLuiSet( luiSetTypeKey, luiSetInfo, callContext ).getId() );
504         createdLuiSetIds.add( luiService.createLuiSet( luiSetTypeKey, luiSetInfo, callContext ).getId() );
505         List<LuiSetInfo> bulkRetrieved_luiSets = luiService.getLuiSetsByIds( createdLuiSetIds, callContext );
506         assertNotNull( bulkRetrieved_luiSets );
507         assertTrue( bulkRetrieved_luiSets.size() == 3 );
508         for( LuiSetInfo r : bulkRetrieved_luiSets ) {
509             assertTrue( createdLuiSetIds.contains(r.getId()) );
510         }
511 
512         // bulk operation -- get the list of lui-ids of a lui-set
513         List<String> luiIds = new ArrayList<String>();
514         luiIds.add( UUIDHelper.genStringUUID() );
515         luiIds.add( UUIDHelper.genStringUUID() );
516         luiSetInfo.setLuiIds( luiIds );
517         created = luiService.createLuiSet( luiSetTypeKey, luiSetInfo, callContext );
518         List<String> bulkRetrieved_luiIds = luiService.getLuiIdsFromLuiSet( created.getId(), callContext );
519         assertNotNull(bulkRetrieved_luiIds);
520         assertEquals(luiIds.size(), bulkRetrieved_luiIds.size());
521         assertTrue( bulkRetrieved_luiIds.containsAll(luiIds) );
522 
523         // bulk operation -- get a list of lui-ids that contain a specific lui-id
524         String targetLuiId = UUIDHelper.genStringUUID();
525         List<String> targetLuiIdsList = new ArrayList<String>();
526         targetLuiIdsList.add(targetLuiId);
527         luiSetInfo.setLuiIds( targetLuiIdsList );
528         // create a bunch of lui-sets containing references to that lui-id
529         List<LuiSetInfo> bulkCreated_luiSets = new ArrayList<LuiSetInfo>();
530         bulkCreated_luiSets.add( luiService.createLuiSet( luiSetTypeKey, luiSetInfo, callContext ) );
531         bulkCreated_luiSets.add( luiService.createLuiSet( luiSetTypeKey, luiSetInfo, callContext ) );
532         bulkCreated_luiSets.add( luiService.createLuiSet( luiSetTypeKey, luiSetInfo, callContext ) );
533         bulkRetrieved_luiSets = luiService.getLuiSetsByLui( targetLuiId, callContext );
534         assertNotNull( bulkRetrieved_luiSets );
535         assertEquals( 3, bulkRetrieved_luiSets.size() );
536         for( LuiSetInfo luiSet : bulkRetrieved_luiSets ) {
537             assertTrue( luiSet.getLuiIds().contains( targetLuiId ) );
538         }
539 
540         // bulk operation -- get a list of lui-set ids by lui-set type
541         luiService.createLuiSet( "test.alternate.lui.set.type.key.test", luiSetInfo, callContext );
542         bulkRetrieved_luiIds = luiService.getLuiSetIdsByType( luiSetTypeKey, callContext );
543         assertEquals( 7, bulkRetrieved_luiIds.size() );
544         for( String id : bulkRetrieved_luiIds ) {
545             assertEquals( luiSetTypeKey, luiService.getLuiSet( id, callContext ).getTypeKey() );
546         }
547         assertEquals( 1, luiService.getLuiSetIdsByType( "test.alternate.lui.set.type.key.test", callContext ).size() );
548     }
549 
550 }