1
2
3
4
5 package org.kuali.student.enrollment.class2.courseofferingset.service.impl;
6
7 import org.junit.Ignore;
8 import org.junit.Test;
9 import org.junit.runner.RunWith;
10 import org.kuali.student.common.test.util.AttributeTester;
11 import org.kuali.student.enrollment.courseofferingset.dto.SocInfo;
12 import org.kuali.student.r2.common.dto.StatusInfo;
13 import org.kuali.student.r2.common.util.RichTextHelper;
14 import org.kuali.student.r2.common.util.constants.CourseOfferingSetServiceConstants;
15 import org.kuali.student.r2.common.util.date.DateFormatters;
16 import org.springframework.test.context.ContextConfiguration;
17 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
18 import org.springframework.test.context.transaction.TransactionConfiguration;
19 import org.springframework.transaction.annotation.Transactional;
20
21 import java.util.Date;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertNull;
27 import static org.junit.Assert.assertTrue;
28
29
30
31
32
33
34 @Ignore
35 @RunWith(SpringJUnit4ClassRunner.class)
36 @ContextConfiguration(locations = {"classpath:soc-jpa-persistence-test-context.xml"})
37 @TransactionConfiguration(transactionManager = "JtaTxManager", defaultRollback = true)
38 @Transactional
39 public class TestCourseOfferingSetServiceJpaPersistenceImpl extends TestCourseOfferingSetServiceMockImpl {
40
41 @Test
42 public void testSocSchedulingState() throws Exception {
43 SocInfo orig = new SocInfo();
44 orig.setName("SOC");
45 orig.setDescr(new RichTextHelper().toRichTextInfo("description plain 1", "description formatted 1"));
46 orig.setTypeKey(CourseOfferingSetServiceConstants.MAIN_SOC_TYPE_KEY);
47 orig.setStateKey(CourseOfferingSetServiceConstants.DRAFT_SOC_STATE_KEY);
48 orig.setTermId("myTermId");
49 orig.setSubjectArea("ENG");
50 orig.setUnitsContentOwnerId("myUnitId");
51
52
53
54 String startDateString = DateFormatters.STATE_CHANGE_DATE_FORMATTER.format(new Date());
55
56 orig.getAttributes().add(new AttributeTester().toAttribute(CourseOfferingSetServiceConstants.SOC_SCHEDULING_STATE_IN_PROGRESS, startDateString));
57 SocInfo info = socService.createSoc(orig.getTermId(), orig.getTypeKey(), orig, callContext);
58
59
60 assertEquals(startDateString, DateFormatters.STATE_CHANGE_DATE_FORMATTER.format(info.getLastSchedulingRunStarted()));
61 assertNull(info.getLastSchedulingRunCompleted());
62
63
64 callContext.setCurrentDate(new Date());
65 StatusInfo status = socService.changeSocState(info.getId(), CourseOfferingSetServiceConstants.SOC_SCHEDULING_STATE_COMPLETED, callContext);
66 assertTrue(status.getIsSuccess());
67
68 SocInfo updated = socService.getSoc(info.getId(), callContext);
69
70 assertEquals(startDateString, DateFormatters.STATE_CHANGE_DATE_FORMATTER.format(updated.getLastSchedulingRunStarted()));
71 assertNotNull(updated.getLastSchedulingRunCompleted());
72 assertFalse(updated.getLastSchedulingRunStarted().compareTo(updated.getLastSchedulingRunCompleted()) > 0);
73 }
74
75 @Test
76 public void testUpdateSocState() throws Exception {
77 SocInfo orig = new SocInfo();
78 orig.setName("SOC");
79 orig.setDescr(new RichTextHelper().toRichTextInfo("description plain 1", "description formatted 1"));
80 orig.setTypeKey(CourseOfferingSetServiceConstants.MAIN_SOC_TYPE_KEY);
81 orig.setStateKey(CourseOfferingSetServiceConstants.DRAFT_SOC_STATE_KEY);
82 orig.setTermId("myTermId2");
83 orig.setSubjectArea("ENGL");
84 orig.setUnitsContentOwnerId("myUnitId2");
85 SocInfo info = socService.createSoc(orig.getTermId(), orig.getTypeKey(), orig, callContext);
86
87
88 assertNull(info.getPublishingStarted());
89 assertNull(info.getPublishingCompleted());
90
91
92 StatusInfo status = socService.changeSocState(info.getId(), CourseOfferingSetServiceConstants.PUBLISHING_SOC_STATE_KEY, callContext);
93 assertTrue(status.getIsSuccess());
94
95 SocInfo updated = socService.getSoc(info.getId(), callContext);
96
97
98 assertEquals(CourseOfferingSetServiceConstants.PUBLISHING_SOC_STATE_KEY, updated.getStateKey());
99 assertNotNull(updated.getPublishingStarted());
100 assertNull(updated.getPublishingCompleted());
101
102
103 status = socService.changeSocState(info.getId(), CourseOfferingSetServiceConstants.PUBLISHED_SOC_STATE_KEY, callContext);
104 assertTrue(status.getIsSuccess());
105
106 updated = socService.getSoc(info.getId(), callContext);
107
108
109 assertEquals(CourseOfferingSetServiceConstants.PUBLISHED_SOC_STATE_KEY, updated.getStateKey());
110 assertNotNull(updated.getPublishingStarted());
111 assertNotNull(updated.getPublishingCompleted());
112 }
113 }