View Javadoc

1   /*
2    * To change this template, choose Tools | Templates
3    * and open the template in the editor.
4    */
5   package org.kuali.student.enrollment.class2.courseofferingset.service.impl;
6   
7   import java.text.SimpleDateFormat;
8   import java.util.ArrayList;
9   import java.util.Collections;
10  import java.util.Date;
11  import java.util.List;
12  import javax.annotation.Resource;
13  import org.junit.Before;
14  import org.junit.Test;
15  import static org.junit.Assert.*;
16  import org.junit.runner.RunWith;
17  import org.kuali.student.enrollment.test.util.AttributeTester;
18  import org.kuali.student.enrollment.courseofferingset.dto.SocInfo;
19  import org.kuali.student.enrollment.courseofferingset.dto.SocRolloverResultInfo;
20  import org.kuali.student.enrollment.courseofferingset.dto.SocRolloverResultItemInfo;
21  import org.kuali.student.enrollment.courseofferingset.service.CourseOfferingSetService;
22  import org.kuali.student.r2.common.dto.AttributeInfo;
23  import org.kuali.student.r2.common.dto.ContextInfo;
24  import org.kuali.student.r2.common.dto.StatusInfo;
25  import org.kuali.student.r2.common.exceptions.DoesNotExistException;
26  import org.kuali.student.r2.common.exceptions.ReadOnlyException;
27  import org.kuali.student.r2.common.util.RichTextHelper;
28  import org.kuali.student.r2.common.util.constants.CourseOfferingSetServiceConstants;
29  import org.springframework.test.context.ContextConfiguration;
30  import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
31  
32  /**
33   * Tests the mock persistence implementation to make sure it does basic crud
34   *
35   * @author Kuali Student Team
36   */
37  @RunWith(SpringJUnit4ClassRunner.class)
38  @ContextConfiguration(locations = {"classpath:soc-mock-persistence-impl-test-context.xml"})
39  public class TestCourseOfferingSetServiceMockImpl {
40  
41      @Resource(name = "socService")
42      protected CourseOfferingSetService socService;
43      public static String principalId = "123";
44      public ContextInfo callContext = null;
45  
46      @Before
47      public void setUp() {
48          callContext = new ContextInfo();
49          callContext.setPrincipalId(principalId);
50  //        try {
51  //            loadData();
52  //        } catch (Exception ex) {
53  //            throw new RuntimeException(ex);
54  //        }
55      }
56  
57      @Test
58      public void testCRUD() throws Exception {
59          this.testCRUDSoc();
60          this.testCRUDResult();
61          this.testCRUDResultItem();
62      }
63  
64      private void testCRUDSoc() throws Exception {
65          // create
66          SocInfo orig = new SocInfo();
67          orig.setName("test name");
68          orig.setDescr(new RichTextHelper().toRichTextInfo("description plain 1", "description formatted 1"));
69          orig.setTypeKey(CourseOfferingSetServiceConstants.MAIN_SOC_TYPE_KEY);
70          orig.setStateKey(CourseOfferingSetServiceConstants.DRAFT_SOC_STATE_KEY);
71          orig.setTermId("myTermId");
72          orig.setSubjectArea("ENG");
73          orig.setUnitsContentOwnerId("myUnitId");
74          orig.getAttributes().add(new AttributeTester().toAttribute("key1", "value1"));
75          orig.getAttributes().add(new AttributeTester().toAttribute("key2", "value2"));
76          SocInfo info = socService.createSoc(orig.getTermId(), orig.getTypeKey(), orig, callContext);
77          assertNotNull(info);
78          assertNotNull(info.getId());
79          assertEquals(orig.getName(), info.getName());
80          assertNotNull(info.getDescr());
81          assertEquals(orig.getDescr().getPlain(), info.getDescr().getPlain());
82          assertEquals(orig.getDescr().getFormatted(), info.getDescr().getFormatted());
83          assertEquals(orig.getTypeKey(), info.getTypeKey());
84          assertEquals(orig.getStateKey(), info.getStateKey());
85          assertEquals(orig.getTermId(), info.getTermId());
86          assertEquals(orig.getSubjectArea(), info.getSubjectArea());
87          assertEquals(orig.getUnitsContentOwnerId(), info.getUnitsContentOwnerId());
88          List<AttributeInfo> attrs = info.getAttributes();
89          List<AttributeInfo> attrs2 = new ArrayList<AttributeInfo> ();
90          SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
91          Date date = null;
92          for (AttributeInfo attr : attrs) {
93              if (attr.getKey().equals(CourseOfferingSetServiceConstants.DRAFT_SOC_STATE_KEY)) {
94                  if (date != null) {
95                      fail ("should only be one dynamic attribute for draft state");
96                  }
97                  date = formatter.parse(attr.getValue());
98              } else {
99                  attrs2.add(attr);
100             }
101         }
102         assertNotNull (date);        
103         new AttributeTester().check(orig.getAttributes(), attrs2);
104         assertNotNull(info.getMeta());
105         assertNotNull(info.getMeta().getCreateId());
106         assertNotNull(info.getMeta().getCreateTime());
107 
108         // get
109         orig = info;
110         info = this.socService.getSoc(orig.getId(), callContext);
111         assertNotNull(info);
112         assertEquals(orig.getId(), info.getId());
113         assertEquals(orig.getName(), info.getName());
114         assertNotNull(info.getDescr());
115         assertEquals(orig.getDescr().getPlain(), info.getDescr().getPlain());
116         assertEquals(orig.getDescr().getFormatted(), info.getDescr().getFormatted());
117         assertEquals(orig.getTypeKey(), info.getTypeKey());
118         assertEquals(orig.getStateKey(), info.getStateKey());
119         assertEquals(orig.getTermId(), info.getTermId());
120         assertEquals(orig.getSubjectArea(), info.getSubjectArea());
121         new AttributeTester().check(orig.getAttributes(), info.getAttributes());
122         assertNotNull(info.getMeta());
123         assertEquals(orig.getMeta().getCreateId(), info.getMeta().getCreateId());
124         assertEquals(orig.getMeta().getCreateTime(), info.getMeta().getCreateTime());
125 
126         // update
127         orig = info;
128         orig.setName("test name updated");
129         orig.setDescr(new RichTextHelper().toRichTextInfo("description plain 1 updated",
130                 "description formatted 1 updated"));
131         new AttributeTester().findAttributes(orig.getAttributes(), "key1").get(0).setValue(
132                 "value1Updated");
133         info = this.socService.updateSoc(orig.getId(), orig, callContext);
134         assertNotSame (orig, info);
135         assertEquals(orig.getId(), info.getId());
136         assertEquals(orig.getName(), info.getName());
137         assertNotNull(info.getDescr());
138         assertEquals(orig.getDescr().getPlain(), info.getDescr().getPlain());
139         assertEquals(orig.getDescr().getFormatted(), info.getDescr().getFormatted());
140         assertEquals(orig.getTypeKey(), info.getTypeKey());
141         assertEquals(orig.getStateKey(), info.getStateKey());
142         assertEquals(orig.getTermId(), info.getTermId());
143         assertEquals(orig.getSubjectArea(), info.getSubjectArea());
144         new AttributeTester().check(orig.getAttributes(), info.getAttributes());
145         assertNotNull(info.getMeta());
146         assertEquals(orig.getMeta().getCreateId(), info.getMeta().getCreateId());
147         assertEquals(orig.getMeta().getCreateTime(), info.getMeta().getCreateTime());
148         assertNotNull(info.getMeta().getUpdateId());
149         assertNotNull(info.getMeta().getUpdateTime());
150 
151         // test get after you do the update
152         orig = info;
153         info = this.socService.getSoc(orig.getId(), callContext);
154         assertNotSame (orig, info);
155         assertEquals(orig.getId(), info.getId());
156         assertEquals(orig.getName(), info.getName());
157         assertNotNull(info.getDescr());
158         assertEquals(orig.getDescr().getPlain(), info.getDescr().getPlain());
159         assertEquals(orig.getDescr().getFormatted(), info.getDescr().getFormatted());
160         assertEquals(orig.getTypeKey(), info.getTypeKey());
161         assertEquals(orig.getStateKey(), info.getStateKey());
162         assertEquals(orig.getTermId(), info.getTermId());
163         assertEquals(orig.getSubjectArea(), info.getSubjectArea());
164         new AttributeTester().check(orig.getAttributes(), info.getAttributes());
165         assertNotNull(info.getMeta());
166         assertEquals(orig.getMeta().getCreateId(), info.getMeta().getCreateId());
167         assertEquals(orig.getMeta().getCreateTime(), info.getMeta().getCreateTime());
168         assertEquals(orig.getMeta().getUpdateId(), info.getMeta().getUpdateId());
169         assertEquals(orig.getMeta().getUpdateTime(), info.getMeta().getUpdateTime());
170 
171         // update the state
172         orig = info;
173         orig.setStateKey(CourseOfferingSetServiceConstants.OPEN_SOC_STATE_KEY);        
174         try {
175             info = this.socService.updateSoc(orig.getId(), orig, callContext);
176             fail("should have gotten readonly exception");
177         } catch (ReadOnlyException ex) {
178             // expected
179         }
180         StatusInfo status = this.socService.updateSocState(orig.getId(), CourseOfferingSetServiceConstants.OPEN_SOC_STATE_KEY, callContext);
181         assertEquals (Boolean.TRUE, status.getIsSuccess());
182         info = this.socService.getSoc(orig.getId(), callContext);
183         assertNotSame (orig, info);
184         assertEquals(orig.getId(), info.getId());
185         assertEquals(orig.getName(), info.getName());
186         assertNotNull(info.getDescr());
187         assertEquals(orig.getDescr().getPlain(), info.getDescr().getPlain());
188         assertEquals(orig.getDescr().getFormatted(), info.getDescr().getFormatted());
189         assertEquals(orig.getTypeKey(), info.getTypeKey());
190         assertEquals(orig.getStateKey(), info.getStateKey());
191         assertEquals(orig.getTermId(), info.getTermId());
192         assertEquals(orig.getSubjectArea(), info.getSubjectArea());
193         assertEquals (4, info.getAttributes().size());
194         assertNotNull (info.getAttributeValue(CourseOfferingSetServiceConstants.OPEN_SOC_STATE_KEY));
195 //        new AttributeTester().check(orig.getAttributes(), info.getAttributes());
196         assertNotNull(info.getMeta());
197         assertEquals(orig.getMeta().getCreateId(), info.getMeta().getCreateId());
198         assertEquals(orig.getMeta().getCreateTime(), info.getMeta().getCreateTime());
199         assertNotNull(info.getMeta().getUpdateId());
200         assertNotNull(info.getMeta().getUpdateTime());
201 
202         // delete
203         orig = info;
204         status = this.socService.deleteSoc(orig.getId(), callContext);
205         assertEquals(Boolean.TRUE, status.getIsSuccess());
206 
207         // try getting again
208         try {
209             info = this.socService.getSoc(orig.getId(), callContext);
210             fail("should have thrown does not exist exception");
211         } catch (DoesNotExistException ex) {
212             // expected
213         }
214     }
215 
216     private void testCRUDResult() throws Exception {
217         SocInfo sourceSoc = new SocInfo();
218         sourceSoc.setName("source name");
219         sourceSoc.setDescr(new RichTextHelper().toRichTextInfo("description plain 1", "description formatted 1"));
220         sourceSoc.setTypeKey(CourseOfferingSetServiceConstants.MAIN_SOC_TYPE_KEY);
221         sourceSoc.setStateKey(CourseOfferingSetServiceConstants.DRAFT_SOC_STATE_KEY);
222         sourceSoc.setTermId("myTermId1");
223         sourceSoc = socService.createSoc(sourceSoc.getTermId(), sourceSoc.getTypeKey(), sourceSoc, callContext);
224 
225         SocInfo targetSoc = new SocInfo();
226         targetSoc.setName("target name");
227         targetSoc.setDescr(new RichTextHelper().toRichTextInfo("description plain 1", "description formatted 1"));
228         targetSoc.setTypeKey(CourseOfferingSetServiceConstants.MAIN_SOC_TYPE_KEY);
229         targetSoc.setStateKey(CourseOfferingSetServiceConstants.DRAFT_SOC_STATE_KEY);
230         targetSoc.setTermId("myTermId2");
231         targetSoc = socService.createSoc(targetSoc.getTermId(), targetSoc.getTypeKey(), targetSoc, callContext);
232 
233         // create
234         SocRolloverResultInfo orig = new SocRolloverResultInfo();
235         orig.setMessage(new RichTextHelper().toRichTextInfo("message plain 1", "message formatted 1"));
236         orig.setTypeKey(CourseOfferingSetServiceConstants.ROLLOVER_RESULT_TYPE_KEY);
237         orig.setStateKey(CourseOfferingSetServiceConstants.SUBMITTED_RESULT_STATE_KEY);
238         orig.setItemsExpected(100);
239         orig.setItemsProcessed(1);
240         orig.setSourceSocId(sourceSoc.getId());
241         orig.setTargetSocId(targetSoc.getId());
242         orig.setTargetTermId("my term");
243         orig.getOptionKeys().add("my first option");
244         orig.getOptionKeys().add("my 2nd option");
245         orig.getAttributes().add(new AttributeTester().toAttribute("key1", "value1"));
246         orig.getAttributes().add(new AttributeTester().toAttribute("key2", "value2"));
247         SocRolloverResultInfo info = socService.createSocRolloverResult(orig.getTypeKey(), orig, callContext);
248         assertNotNull(info);
249         assertNotNull(info.getId());
250         assertNotNull(info.getMessage());
251         assertEquals(orig.getMessage().getPlain(), info.getMessage().getPlain());
252         assertEquals(orig.getMessage().getFormatted(), info.getMessage().getFormatted());
253         assertEquals(orig.getTypeKey(), info.getTypeKey());
254         assertEquals(orig.getStateKey(), info.getStateKey());
255         assertEquals(orig.getItemsExpected(), info.getItemsExpected());
256         assertEquals(orig.getItemsProcessed(), info.getItemsProcessed());
257         assertEquals(orig.getSourceSocId(), info.getSourceSocId());
258         assertEquals(orig.getTargetSocId(), info.getTargetSocId());
259         assertEquals(orig.getTargetTermId(), info.getTargetTermId());
260         compareStringList(orig.getOptionKeys(), info.getOptionKeys());
261         new AttributeTester().check(orig.getAttributes(), info.getAttributes());
262         assertNotNull(info.getMeta());
263         assertNotNull(info.getMeta().getCreateId());
264         assertNotNull(info.getMeta().getCreateTime());
265 
266         // get
267         orig = info;
268         info = this.socService.getSocRolloverResult(orig.getId(), callContext);
269         assertNotNull(info);
270         assertEquals(orig.getId(), info.getId());
271         assertNotNull(info.getMessage());
272         assertEquals(orig.getMessage().getPlain(), info.getMessage().getPlain());
273         assertEquals(orig.getMessage().getFormatted(), info.getMessage().getFormatted());
274         assertEquals(orig.getTypeKey(), info.getTypeKey());
275         assertEquals(orig.getStateKey(), info.getStateKey());
276         assertEquals(orig.getItemsExpected(), info.getItemsExpected());
277         assertEquals(orig.getItemsProcessed(), info.getItemsProcessed());
278         assertEquals(orig.getSourceSocId(), info.getSourceSocId());
279         assertEquals(orig.getTargetSocId(), info.getTargetSocId());
280         assertEquals(orig.getTargetTermId(), info.getTargetTermId());
281         compareStringList(orig.getOptionKeys(), info.getOptionKeys());
282         new AttributeTester().check(orig.getAttributes(), info.getAttributes());
283         assertNotNull(info.getMeta());
284         assertEquals(orig.getMeta().getCreateId(), info.getMeta().getCreateId());
285         assertEquals(orig.getMeta().getCreateTime(), info.getMeta().getCreateTime());
286 
287         // update
288         orig = info;
289         orig.setMessage(new RichTextHelper().toRichTextInfo("message plain 1 updated",
290                 "description formatted 1 updated"));
291         orig.setStateKey(CourseOfferingSetServiceConstants.RUNNING_RESULT_STATE_KEY);
292         orig.setItemsExpected(orig.getItemsExpected() + 100);
293         orig.setItemsProcessed(orig.getItemsProcessed() + 100);
294         orig.setTargetTermId("different term");
295         orig.setSourceSocId(targetSoc.getId()); // reverse them!
296         orig.setTargetSocId(sourceSoc.getId());
297         orig.getOptionKeys().remove(0);
298         orig.getOptionKeys().add("added a 3rd option");
299         new AttributeTester().findAttributes(orig.getAttributes(), "key1").get(0).setValue(
300                 "value1Updated");
301         info = this.socService.updateSocRolloverResult(orig.getId(), orig,
302                 callContext);
303         assertNotNull(info);
304         assertEquals(orig.getId(), info.getId());
305         assertNotNull(info.getMessage());
306         assertEquals(orig.getMessage().getPlain(), info.getMessage().getPlain());
307         assertEquals(orig.getMessage().getFormatted(), info.getMessage().getFormatted());
308         assertEquals(orig.getTypeKey(), info.getTypeKey());
309         assertEquals(orig.getStateKey(), info.getStateKey());
310         assertEquals(orig.getItemsExpected(), info.getItemsExpected());
311         assertEquals(orig.getItemsProcessed(), info.getItemsProcessed());
312         assertEquals(orig.getSourceSocId(), info.getSourceSocId());
313         assertEquals(orig.getTargetSocId(), info.getTargetSocId());
314         assertEquals(orig.getTargetTermId(), info.getTargetTermId());
315         compareStringList(orig.getOptionKeys(), info.getOptionKeys());
316         new AttributeTester().check(orig.getAttributes(), info.getAttributes());
317         assertNotNull(info.getMeta());
318         assertEquals(orig.getMeta().getCreateId(), info.getMeta().getCreateId());
319         assertEquals(orig.getMeta().getCreateTime(), info.getMeta().getCreateTime());
320         assertNotNull(info.getMeta().getUpdateId());
321         assertNotNull(info.getMeta().getUpdateTime());
322 
323         // test get after you do the update
324         orig = info;
325         info = this.socService.getSocRolloverResult(orig.getId(), callContext);
326         assertNotNull(info);
327         assertEquals(orig.getId(), info.getId());
328         assertNotNull(info.getMessage());
329         assertEquals(orig.getMessage().getPlain(), info.getMessage().getPlain());
330         assertEquals(orig.getMessage().getFormatted(), info.getMessage().getFormatted());
331         assertEquals(orig.getTypeKey(), info.getTypeKey());
332         assertEquals(orig.getStateKey(), info.getStateKey());
333         assertEquals(orig.getItemsExpected(), info.getItemsExpected());
334         assertEquals(orig.getItemsProcessed(), info.getItemsProcessed());
335         assertEquals(orig.getSourceSocId(), info.getSourceSocId());
336         assertEquals(orig.getTargetSocId(), info.getTargetSocId());
337         assertEquals(orig.getTargetTermId(), info.getTargetTermId());
338         compareStringList(orig.getOptionKeys(), info.getOptionKeys());
339         new AttributeTester().check(orig.getAttributes(), info.getAttributes());
340         assertNotNull(info.getMeta());
341         assertEquals(orig.getMeta().getCreateId(), info.getMeta().getCreateId());
342         assertEquals(orig.getMeta().getCreateTime(), info.getMeta().getCreateTime());
343         assertEquals(orig.getMeta().getUpdateId(), info.getMeta().getUpdateId());
344         assertEquals(orig.getMeta().getUpdateTime(), info.getMeta().getUpdateTime());
345 
346         // delete
347         orig = info;
348         StatusInfo status = this.socService.deleteSocRolloverResult(orig.getId(),
349                 callContext);
350         assertEquals(Boolean.TRUE, status.getIsSuccess());
351 
352         // try getting again
353         try {
354             info = this.socService.getSocRolloverResult(orig.getId(), callContext);
355             fail("should have thrown does not exist exception");
356         } catch (DoesNotExistException ex) {
357             // expected
358         }
359     }
360 
361     private void testCRUDResultItem() throws Exception {
362         SocInfo sourceSoc = new SocInfo();
363         sourceSoc.setName("source name");
364         sourceSoc.setDescr(new RichTextHelper().toRichTextInfo("description plain 1", "description formatted 1"));
365         sourceSoc.setTypeKey(CourseOfferingSetServiceConstants.MAIN_SOC_TYPE_KEY);
366         sourceSoc.setStateKey(CourseOfferingSetServiceConstants.DRAFT_SOC_STATE_KEY);
367         sourceSoc.setTermId("myTermId1");
368         sourceSoc = socService.createSoc(sourceSoc.getTermId(), sourceSoc.getTypeKey(), sourceSoc, callContext);
369 
370         SocInfo targetSoc = new SocInfo();
371         targetSoc.setName("target name");
372         targetSoc.setDescr(new RichTextHelper().toRichTextInfo("description plain 1", "description formatted 1"));
373         targetSoc.setTypeKey(CourseOfferingSetServiceConstants.MAIN_SOC_TYPE_KEY);
374         targetSoc.setStateKey(CourseOfferingSetServiceConstants.DRAFT_SOC_STATE_KEY);
375         targetSoc.setTermId("myTermId2");
376         targetSoc = socService.createSoc(targetSoc.getTermId(), targetSoc.getTypeKey(), targetSoc, callContext);
377 
378         SocRolloverResultInfo result = new SocRolloverResultInfo();
379         result.setMessage(new RichTextHelper().toRichTextInfo("message plain 1", "message formatted 1"));
380         result.setTypeKey(CourseOfferingSetServiceConstants.ROLLOVER_RESULT_TYPE_KEY);
381         result.setStateKey(CourseOfferingSetServiceConstants.SUBMITTED_RESULT_STATE_KEY);
382         result.setItemsExpected(100);
383         result.setItemsProcessed(1);
384         result.setSourceSocId(sourceSoc.getId());
385         result.setTargetSocId(targetSoc.getId());
386         result.setTargetTermId("my term");
387         result.getOptionKeys().add("my first option");
388         result.getOptionKeys().add("my 2nd option");
389         result.getAttributes().add(new AttributeTester().toAttribute("key1", "value1"));
390         result.getAttributes().add(new AttributeTester().toAttribute("key2", "value2"));
391         result = socService.createSocRolloverResult(result.getTypeKey(), result, callContext);
392 
393         // create
394         SocRolloverResultItemInfo orig = new SocRolloverResultItemInfo();
395         orig.setSocRolloverResultId(result.getId());
396         orig.setMessage(new RichTextHelper().toRichTextInfo("message plain 1", "message formatted 1"));
397         orig.setTypeKey(CourseOfferingSetServiceConstants.ROLLOVER_RESULT_TYPE_KEY);
398         orig.setStateKey(CourseOfferingSetServiceConstants.SUBMITTED_RESULT_STATE_KEY);
399         orig.setSourceCourseOfferingId("co1");
400         orig.setTargetCourseOfferingId("co2");
401         orig.getAttributes().add(new AttributeTester().toAttribute("key1", "value1"));
402         orig.getAttributes().add(new AttributeTester().toAttribute("key2", "value2"));
403         SocRolloverResultItemInfo info = socService.createSocRolloverResultItem(orig.getSocRolloverResultId(), orig.getTypeKey(), orig, callContext);
404         assertNotNull(info);
405         assertNotNull(info.getId());
406         assertNotNull(info.getMessage());
407         assertEquals(orig.getMessage().getPlain(), info.getMessage().getPlain());
408         assertEquals(orig.getMessage().getFormatted(), info.getMessage().getFormatted());
409         assertEquals(orig.getTypeKey(), info.getTypeKey());
410         assertEquals(orig.getStateKey(), info.getStateKey());
411         assertEquals(orig.getSourceCourseOfferingId(), info.getSourceCourseOfferingId());
412         assertEquals(orig.getTargetCourseOfferingId(), info.getTargetCourseOfferingId());
413         new AttributeTester().check(orig.getAttributes(), info.getAttributes());
414         assertNotNull(info.getMeta());
415         assertNotNull(info.getMeta().getCreateId());
416         assertNotNull(info.getMeta().getCreateTime());
417 
418         // get
419         orig = info;
420         info = this.socService.getSocRolloverResultItem(orig.getId(), callContext);
421         assertNotNull(info);
422         assertEquals(orig.getId(), info.getId());
423         assertNotNull(info.getMessage());
424         assertEquals(orig.getMessage().getPlain(), info.getMessage().getPlain());
425         assertEquals(orig.getMessage().getFormatted(), info.getMessage().getFormatted());
426         assertEquals(orig.getTypeKey(), info.getTypeKey());
427         assertEquals(orig.getStateKey(), info.getStateKey());
428         assertEquals(orig.getSourceCourseOfferingId(), info.getSourceCourseOfferingId());
429         assertEquals(orig.getTargetCourseOfferingId(), info.getTargetCourseOfferingId());
430         new AttributeTester().check(orig.getAttributes(), info.getAttributes());
431         assertNotNull(info.getMeta());
432         assertEquals(orig.getMeta().getCreateId(), info.getMeta().getCreateId());
433         assertEquals(orig.getMeta().getCreateTime(), info.getMeta().getCreateTime());
434 
435         // update
436         orig = info;
437         orig.setMessage(new RichTextHelper().toRichTextInfo("message plain 1 updated",
438                 "description formatted 1 updated"));
439         orig.setStateKey(CourseOfferingSetServiceConstants.RUNNING_RESULT_STATE_KEY);
440         assertEquals(orig.getSourceCourseOfferingId(), info.getSourceCourseOfferingId());
441         assertEquals(orig.getTargetCourseOfferingId(), info.getTargetCourseOfferingId());
442         orig.setSourceCourseOfferingId("coIdDiff1");
443         orig.setTargetCourseOfferingId("coIddiff2");
444         new AttributeTester().findAttributes(orig.getAttributes(), "key1").get(0).setValue(
445                 "value1Updated");
446         info = this.socService.updateSocRolloverResultItem(orig.getId(), orig,
447                 callContext);
448         assertNotNull(info);
449         assertEquals(orig.getId(), info.getId());
450         assertNotNull(info.getMessage());
451         assertEquals(orig.getMessage().getPlain(), info.getMessage().getPlain());
452         assertEquals(orig.getMessage().getFormatted(), info.getMessage().getFormatted());
453         assertEquals(orig.getTypeKey(), info.getTypeKey());
454         assertEquals(orig.getStateKey(), info.getStateKey());
455         assertEquals(orig.getSourceCourseOfferingId(), info.getSourceCourseOfferingId());
456         assertEquals(orig.getTargetCourseOfferingId(), info.getTargetCourseOfferingId());
457         new AttributeTester().check(orig.getAttributes(), info.getAttributes());
458         assertNotNull(info.getMeta());
459         assertEquals(orig.getMeta().getCreateId(), info.getMeta().getCreateId());
460         assertEquals(orig.getMeta().getCreateTime(), info.getMeta().getCreateTime());
461         assertNotNull(info.getMeta().getUpdateId());
462         assertNotNull(info.getMeta().getUpdateTime());
463 
464         // test get after you do the update
465         orig = info;
466         info = this.socService.getSocRolloverResultItem(orig.getId(), callContext);
467         assertNotNull(info);
468         assertEquals(orig.getId(), info.getId());
469         assertNotNull(info.getMessage());
470         assertEquals(orig.getMessage().getPlain(), info.getMessage().getPlain());
471         assertEquals(orig.getMessage().getFormatted(), info.getMessage().getFormatted());
472         assertEquals(orig.getTypeKey(), info.getTypeKey());
473         assertEquals(orig.getStateKey(), info.getStateKey());
474         assertEquals(orig.getSourceCourseOfferingId(), info.getSourceCourseOfferingId());
475         assertEquals(orig.getTargetCourseOfferingId(), info.getTargetCourseOfferingId());
476         new AttributeTester().check(orig.getAttributes(), info.getAttributes());
477         assertNotNull(info.getMeta());
478         assertEquals(orig.getMeta().getCreateId(), info.getMeta().getCreateId());
479         assertEquals(orig.getMeta().getCreateTime(), info.getMeta().getCreateTime());
480         assertEquals(orig.getMeta().getUpdateId(), info.getMeta().getUpdateId());
481         assertEquals(orig.getMeta().getUpdateTime(), info.getMeta().getUpdateTime());
482 
483         // delete
484         orig = info;
485         StatusInfo status = this.socService.deleteSocRolloverResultItem(orig.getId(),
486                 callContext);
487         assertEquals(Boolean.TRUE, status.getIsSuccess());
488 
489         // try getting again
490         try {
491             info = this.socService.getSocRolloverResultItem(orig.getId(), callContext);
492             fail("should have thrown does not exist exception");
493         } catch (DoesNotExistException ex) {
494             // expected
495         }
496     }
497 
498     private void compareStringList(List<String> list1, List<String> list2) {
499         assertEquals(list1.size(), list2.size());
500         List lst1 = new ArrayList(list1);
501         Collections.sort(lst1);
502         List lst2 = new ArrayList(list2);
503         Collections.sort(lst2);
504         for (int i = 0; i < lst1.size(); i ++) {
505             assertEquals(i + "", lst1.get(i), lst2.get(i));
506         }
507     }
508 }