001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/course-management/tags/sakai_2-4-1/cm-impl/hibernate-impl/impl/src/test/org/sakaiproject/coursemanagement/test/ClassPathCMSyncJobTest.java $
003: * $Id: ClassPathCMSyncJobTest.java 20714 2007-01-26 19:47:36Z jholtzman@berkeley.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.coursemanagement.test;
021:
022: import java.util.List;
023:
024: import junit.framework.Assert;
025:
026: import org.sakaiproject.coursemanagement.api.AcademicSession;
027: import org.sakaiproject.coursemanagement.api.CanonicalCourse;
028: import org.sakaiproject.coursemanagement.api.CourseManagementAdministration;
029: import org.sakaiproject.coursemanagement.api.CourseManagementService;
030: import org.sakaiproject.coursemanagement.api.CourseOffering;
031: import org.sakaiproject.coursemanagement.api.CourseSet;
032: import org.sakaiproject.coursemanagement.api.EnrollmentSet;
033: import org.sakaiproject.coursemanagement.api.Membership;
034: import org.sakaiproject.coursemanagement.api.Section;
035: import org.sakaiproject.coursemanagement.api.exception.IdNotFoundException;
036: import org.sakaiproject.coursemanagement.impl.job.ClassPathCMSyncJob;
037:
038: public class ClassPathCMSyncJobTest extends CourseManagementTestBase {
039: private ClassPathCMSyncJob job;
040: private CourseManagementService cmService;
041: private CourseManagementAdministration cmAdmin;
042:
043: protected void onSetUpInTransaction() throws Exception {
044: job = (ClassPathCMSyncJob) applicationContext
045: .getBean(ClassPathCMSyncJob.class.getName());
046: cmService = (CourseManagementService) applicationContext
047: .getBean(CourseManagementService.class.getName());
048: cmAdmin = (CourseManagementAdministration) applicationContext
049: .getBean(CourseManagementAdministration.class.getName());
050: job.syncAllCmObjects();
051: }
052:
053: public void testAcademicSessionsLoaded() throws Exception {
054: // Ensure that the academic sessions were loaded
055: List asList = cmService.getAcademicSessions();
056: Assert.assertEquals(2, asList.size());
057: }
058:
059: public void testAcademicSessionsReconciled() throws Exception {
060: // Update an AS manually
061: AcademicSession academicSession = cmService
062: .getAcademicSession("fall_2006");
063:
064: String oldTitle = academicSession.getTitle();
065:
066: academicSession.setTitle("new title");
067: cmAdmin.updateAcademicSession(academicSession);
068:
069: // Ensure that it was indeed updated
070: Assert.assertEquals("new title", cmService.getAcademicSession(
071: "fall_2006").getTitle());
072:
073: // Reconcile again
074: job.syncAllCmObjects();
075:
076: // Ensure that the reconciliation updated the data
077: Assert.assertEquals(oldTitle, cmService.getAcademicSession(
078: "fall_2006").getTitle());
079: }
080:
081: public void testCanonicalCoursesLoaded() throws Exception {
082: // Ensure that the canonical courses were loaded
083: try {
084: cmService.getCanonicalCourse("biology_101");
085: cmService.getCanonicalCourse("chemistry_101");
086: } catch (IdNotFoundException ide) {
087: fail();
088: }
089: }
090:
091: public void testCanonicalCoursesReconciled() throws Exception {
092: // Update a cc manually
093: CanonicalCourse cc = cmService
094: .getCanonicalCourse("biology_101");
095: String oldTitle = cc.getTitle();
096: cc.setTitle("new title");
097: cmAdmin.updateCanonicalCourse(cc);
098:
099: // Ensure that it was indeed updated
100: Assert.assertEquals("new title", cmService.getCanonicalCourse(
101: "biology_101").getTitle());
102:
103: // Reconcile again
104: job.syncAllCmObjects();
105:
106: // Ensure that the reconciliation updated the data
107: Assert.assertEquals(oldTitle, cmService.getCanonicalCourse(
108: "biology_101").getTitle());
109: }
110:
111: public void testCourseOfferingsLoaded() throws Exception {
112: // Ensure that the course offerings were loaded
113: try {
114: cmService.getCourseOffering("biology_101_01");
115: cmService.getCourseOffering("chemistry_101_01");
116: } catch (IdNotFoundException ide) {
117: fail();
118: }
119: }
120:
121: public void testCourseOfferingsReconciled() throws Exception {
122: // Update a co manually
123: CourseOffering co = cmService
124: .getCourseOffering("biology_101_01");
125: String oldTitle = co.getTitle();
126: co.setTitle("new title");
127: cmAdmin.updateCourseOffering(co);
128:
129: // Ensure that it was indeed updated
130: Assert.assertEquals("new title", cmService.getCourseOffering(
131: "biology_101_01").getTitle());
132:
133: // Reconcile again
134: job.syncAllCmObjects();
135:
136: // Ensure that the reconciliation updated the data
137: Assert.assertEquals(oldTitle, cmService.getCourseOffering(
138: "biology_101_01").getTitle());
139: }
140:
141: public void testCourseOfferingMembersReconciled() throws Exception {
142: // Ensure that the memberships were loaded
143: Membership member = (Membership) cmService
144: .getCourseOfferingMemberships("biology_101_01")
145: .iterator().next();
146: Assert.assertEquals("assistant", member.getRole());
147:
148: // Add a new membership
149: Membership newMember = cmAdmin
150: .addOrUpdateCourseOfferingMembership("foo", "bar",
151: "biology_101_01", "active");
152:
153: // Ensure it was added
154: Assert.assertTrue(cmService.getCourseOfferingMemberships(
155: "biology_101_01").contains(newMember));
156:
157: // Reconcile again
158: job.syncAllCmObjects();
159:
160: // Ensure that the new member was removed
161: Assert.assertFalse(cmService.getCourseOfferingMemberships(
162: "biology_101_01").contains(newMember));
163: }
164:
165: public void testSectionsLoaded() throws Exception {
166: // Ensure that the sections were loaded
167: try {
168: cmService.getSection("biology_101_01_lec01");
169: } catch (IdNotFoundException ide) {
170: fail();
171: }
172: }
173:
174: public void testSectionsReconciled() throws Exception {
175: // Update a sec manually
176: Section sec = cmService.getSection("biology_101_01_lec01");
177: String oldTitle = sec.getTitle();
178: sec.setTitle("new title");
179: cmAdmin.updateSection(sec);
180:
181: // Ensure that it was indeed updated
182: Assert.assertEquals("new title", cmService.getSection(
183: "biology_101_01_lec01").getTitle());
184:
185: // Reconcile again
186: job.syncAllCmObjects();
187:
188: // Ensure that the reconciliation updated the data
189: Assert.assertEquals(oldTitle, cmService.getSection(
190: "biology_101_01_lec01").getTitle());
191: }
192:
193: public void testSectionMembersReconciled() throws Exception {
194: // Ensure that the memberships were loaded
195: Membership member = (Membership) cmService
196: .getSectionMemberships("biology_101_01_lec01")
197: .iterator().next();
198: Assert.assertEquals("assistant", member.getRole());
199:
200: // Add a new membership
201: Membership newMember = cmAdmin.addOrUpdateSectionMembership(
202: "foo", "bar", "biology_101_01_lec01", "active");
203:
204: // Ensure it was added
205: Assert.assertTrue(cmService.getSectionMemberships(
206: "biology_101_01_lec01").contains(newMember));
207:
208: // Reconcile again
209: job.syncAllCmObjects();
210:
211: // Ensure that the new member was removed
212: Assert.assertFalse(cmService.getSectionMemberships(
213: "biology_101_01_lec01").contains(newMember));
214: }
215:
216: public void testEnrollmentSetsLoaded() throws Exception {
217: // Ensure that the enrollmentSets were loaded
218: try {
219: cmService.getEnrollmentSet("biology_101_01_lec01_es");
220: } catch (IdNotFoundException ide) {
221: fail();
222: }
223: }
224:
225: public void testEnrollmentSetsReconciled() throws Exception {
226: // Update a enrollment set manually
227: EnrollmentSet es = cmService
228: .getEnrollmentSet("biology_101_01_lec01_es");
229: String oldTitle = es.getTitle();
230: es.setTitle("new title");
231: cmAdmin.updateEnrollmentSet(es);
232:
233: // Ensure that it was indeed updated
234: Assert.assertEquals("new title", cmService.getEnrollmentSet(
235: "biology_101_01_lec01_es").getTitle());
236:
237: // Reconcile again
238: job.syncAllCmObjects();
239:
240: // Ensure that the reconciliation updated the data
241: Assert.assertEquals(oldTitle, cmService.getEnrollmentSet(
242: "biology_101_01_lec01_es").getTitle());
243: }
244:
245: public void testCourseSetsLoaded() throws Exception {
246: // Ensure that the courseSets were loaded
247: try {
248: cmService.getCourseSet("ucb");
249: } catch (IdNotFoundException ide) {
250: fail();
251: }
252: }
253:
254: public void testCourseSetsReconciled() throws Exception {
255: // Update a course set manually
256: CourseSet es = cmService.getCourseSet("ucb");
257: String oldTitle = es.getTitle();
258: es.setTitle("new title");
259: cmAdmin.updateCourseSet(es);
260:
261: // Ensure that it was indeed updated
262: Assert.assertEquals("new title", cmService.getCourseSet("ucb")
263: .getTitle());
264:
265: // Reconcile again
266: job.syncAllCmObjects();
267:
268: // Ensure that the reconciliation updated the data
269: Assert.assertEquals(oldTitle, cmService.getCourseSet("ucb")
270: .getTitle());
271: }
272:
273: public void testCourseSetMembersReconciled() throws Exception {
274: // Ensure that the memberships were loaded
275: Membership member = (Membership) cmService
276: .getCourseSetMemberships("ucb").iterator().next();
277: Assert.assertEquals("birgeneau", member.getUserId());
278: Assert.assertEquals("president", member.getRole());
279:
280: // Add a new membership
281: Membership newMember = cmAdmin.addOrUpdateCourseSetMembership(
282: "foo", "bar", "ucb", "active");
283:
284: // Ensure it was added
285: Assert.assertTrue(cmService.getCourseSetMemberships("ucb")
286: .contains(newMember));
287:
288: // Reconcile again
289: job.syncAllCmObjects();
290:
291: // Ensure that the new member was removed
292: Assert.assertFalse(cmService.getCourseSetMemberships("ucb")
293: .contains(newMember));
294: }
295:
296: public void testEnrollmentsLoaded() throws Exception {
297: Assert.assertNotNull(cmService.findEnrollment("student1",
298: "biology_101_01_lec01_es"));
299: Assert.assertNotNull(cmService.findEnrollment("student2",
300: "biology_101_01_lec01_es"));
301: }
302:
303: public void testEnrollmentsReconciled() throws Exception {
304: // Remove an enrollment
305: cmAdmin.removeEnrollment("student1", "biology_101_01_lec01_es");
306:
307: // Ensure that it's been dropped
308: Assert.assertTrue(cmService.findEnrollment("student1",
309: "biology_101_01_lec01_es").isDropped());
310:
311: // Reconcile again
312: job.syncAllCmObjects();
313:
314: // Ensure that the reconciliation added the enrollment
315: Assert.assertFalse(cmService.findEnrollment("student1",
316: "biology_101_01_lec01_es").isDropped());
317: }
318:
319: public void testInstructorsLoaded() throws Exception {
320: Assert.assertTrue(cmService.getInstructorsOfRecordIds(
321: "biology_101_01_lec01_es").contains("instructor1"));
322: Assert.assertTrue(cmService.getInstructorsOfRecordIds(
323: "biology_101_01_lec01_es").contains("instructor2"));
324: }
325:
326: public void testInstructorsReconciled() throws Exception {
327: // Remove an instructor
328: EnrollmentSet es = cmService
329: .getEnrollmentSet("biology_101_01_lec01_es");
330: es.getOfficialInstructors().remove("instructor1");
331:
332: // Ensure that the instructor is gone
333: Assert.assertFalse(cmService.getInstructorsOfRecordIds(
334: "biology_101_01_lec01_es").contains("instructor1"));
335:
336: // Reconcile again
337: job.syncAllCmObjects();
338:
339: // Ensure that the reconciliation added the instructor
340: Assert.assertTrue(cmService.getInstructorsOfRecordIds(
341: "biology_101_01_lec01_es").contains("instructor1"));
342: }
343: }
|