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/CourseManagementServiceTest.java $
003: * $Id: CourseManagementServiceTest.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.HashSet;
023: import java.util.List;
024: import java.util.Map;
025: import java.util.Set;
026:
027: import junit.framework.Assert;
028:
029: import org.apache.commons.logging.Log;
030: import org.apache.commons.logging.LogFactory;
031: import org.sakaiproject.coursemanagement.api.AcademicSession;
032: import org.sakaiproject.coursemanagement.api.CourseManagementService;
033: import org.sakaiproject.coursemanagement.api.CourseOffering;
034: import org.sakaiproject.coursemanagement.api.CourseSet;
035: import org.sakaiproject.coursemanagement.api.Section;
036: import org.sakaiproject.coursemanagement.api.exception.IdNotFoundException;
037: import org.sakaiproject.coursemanagement.impl.CourseOfferingCmImpl;
038: import org.sakaiproject.coursemanagement.impl.DataLoader;
039:
040: public class CourseManagementServiceTest extends
041: CourseManagementTestBase {
042: private static final Log log = LogFactory
043: .getLog(CourseManagementServiceTest.class);
044:
045: private CourseManagementService cm;
046: private DataLoader loader;
047:
048: protected void onSetUpBeforeTransaction() throws Exception {
049: }
050:
051: protected void onSetUpInTransaction() throws Exception {
052: cm = (CourseManagementService) applicationContext
053: .getBean(CourseManagementService.class.getName());
054: loader = (DataLoader) applicationContext
055: .getBean(DataLoader.class.getName());
056: loader.load();
057: }
058:
059: public void testGetAcademicSessions() throws Exception {
060: Assert.assertEquals(1, cm.getAcademicSessions().size());
061: }
062:
063: public void testGetCurrentAcademicSessions() throws Exception {
064: Assert.assertEquals(1, cm.getCurrentAcademicSessions().size());
065: }
066:
067: public void testGetAcademicSessionById() throws Exception {
068: AcademicSession term = cm.getAcademicSession("F2006");
069: Assert.assertEquals("Fall 2006", term.getTitle());
070: try {
071: cm.getAcademicSession("bad eid");
072: fail();
073: } catch (IdNotFoundException ide) {
074: }
075: }
076:
077: public void testGetCourseSets() throws Exception {
078: Assert.assertEquals(2, cm.getCourseSets().size());
079: }
080:
081: public void testGetCourseSetsFromCourseOffering() throws Exception {
082: CourseOffering co = cm.getCourseOffering("BIO101_F2006_01");
083: CourseSet bio = cm.getCourseSet("BIO_DEPT");
084: CourseSet bioChem = cm.getCourseSet("BIO_CHEM_GROUP");
085:
086: // Ensure that the CourseSet EIDs can be retrieved from the CourseOffering
087: Assert.assertEquals(2, co.getCourseSetEids().size());
088:
089: // Ensure that the set of CourseSets contains the right objects
090: Set courseSetsFromCo = ((CourseOfferingCmImpl) co)
091: .getCourseSets();
092: Assert.assertTrue(courseSetsFromCo.contains(bio));
093: Assert.assertTrue(courseSetsFromCo.contains(bioChem));
094: }
095:
096: public void testGetChildCourseSets() throws Exception {
097: CourseSet parent = (CourseSet) cm.getCourseSet("BIO_DEPT");
098: Assert.assertEquals(1, cm.getChildCourseSets(parent.getEid())
099: .size());
100:
101: try {
102: cm.getChildCourseSets("bad eid");
103: fail();
104: } catch (IdNotFoundException ide) {
105: }
106: }
107:
108: public void testGetCourseSetMembers() throws Exception {
109: Set members = cm.getCourseSetMemberships("BIO_DEPT");
110: Assert.assertEquals(1, members.size());
111: try {
112: cm.getCourseSetMemberships("bad eid");
113: fail();
114: } catch (IdNotFoundException ide) {
115: }
116: }
117:
118: public void testGetCanonicalCourse() throws Exception {
119: Assert.assertEquals("Biology 101", cm.getCanonicalCourse(
120: "BIO101").getTitle());
121: try {
122: cm.getCanonicalCourse("bad eid");
123: fail();
124: } catch (IdNotFoundException ide) {
125: }
126: }
127:
128: public void testGetEquivalentCanonicalCourses() throws Exception {
129: Set equivalents = cm.getEquivalentCanonicalCourses("BIO101");
130: Assert.assertEquals(1, equivalents.size());
131: Assert.assertTrue(!equivalents.contains(cm
132: .getCanonicalCourse("BIO101")));
133: try {
134: cm.getEquivalentCanonicalCourses("bad eid");
135: fail();
136: } catch (IdNotFoundException ide) {
137: }
138: }
139:
140: public void testGetCanonicalCoursesFromCourseSet() throws Exception {
141: Assert.assertEquals(1, cm.getCanonicalCourses("BIO_DEPT")
142: .size());
143: Assert.assertEquals(2, cm.getCanonicalCourses("BIO_CHEM_GROUP")
144: .size());
145: try {
146: cm.getCanonicalCourses("bad eid");
147: fail();
148: } catch (IdNotFoundException ide) {
149: }
150: }
151:
152: public void testGetCourseOfferingsFromCourseSet() throws Exception {
153: Assert.assertEquals(1, cm.getCourseOfferingsInCourseSet(
154: "BIO_DEPT").size());
155: Assert.assertEquals(2, cm.getCourseOfferingsInCourseSet(
156: "BIO_CHEM_GROUP").size());
157: try {
158: cm.getCourseOfferingsInCourseSet("bad eid");
159: fail();
160: } catch (IdNotFoundException ide) {
161: }
162: }
163:
164: public void testGetCourseOfferingsFromCanonicalCourse()
165: throws Exception {
166: Assert.assertEquals(1, cm.getCourseOfferingsInCanonicalCourse(
167: "BIO101").size());
168: try {
169: cm.getCourseOfferingsInCanonicalCourse("bad eid");
170: fail();
171: } catch (IdNotFoundException ide) {
172: }
173: }
174:
175: public void testGetCourseOffering() throws Exception {
176: Assert.assertNotNull(cm.getCourseOffering("BIO101_F2006_01"));
177: try {
178: cm.getCourseOffering("bad eid");
179: fail();
180: } catch (IdNotFoundException ide) {
181: }
182: }
183:
184: public void testGetEquivalentCourseOfferings() throws Exception {
185: Set equivalents = cm
186: .getEquivalentCourseOfferings("BIO101_F2006_01");
187: Assert.assertEquals(1, equivalents.size());
188: try {
189: cm.getEquivalentCourseOfferings("bad eid");
190: fail();
191: } catch (IdNotFoundException ide) {
192: }
193: }
194:
195: public void testGetSectionByEid() throws Exception {
196: Assert.assertNotNull(cm.getSection("BIO101_F2006_01_SEC01"));
197: }
198:
199: public void testGetSectionMembers() throws Exception {
200: Assert.assertEquals(1, cm.getSectionMemberships(
201: "BIO101_F2006_01_SEC01").size());
202: try {
203: cm.getSectionMemberships("bad eid");
204: fail();
205: } catch (IdNotFoundException ide) {
206: }
207: }
208:
209: public void testGetSectionsFromCourseOffering() throws Exception {
210: Assert
211: .assertEquals(1, cm.getSections("BIO101_F2006_01")
212: .size());
213: try {
214: cm.getSections("bad eid");
215: fail();
216: } catch (IdNotFoundException ide) {
217: }
218: }
219:
220: public void testGetChildSections() throws Exception {
221: Assert.assertEquals(1, cm.getChildSections(
222: "BIO101_F2006_01_SEC01").size());
223: try {
224: cm.getChildSections("bad eid");
225: fail();
226: } catch (IdNotFoundException ide) {
227: }
228: }
229:
230: public void testGetEnrollmentSet() throws Exception {
231: Assert.assertNotNull(cm
232: .getEnrollmentSet("BIO101_F2006_01_ES01"));
233: try {
234: cm.getEnrollmentSet("bad eid");
235: fail();
236: } catch (IdNotFoundException ide) {
237: }
238: }
239:
240: public void testGetEnrollmentSetFromCourseOffering()
241: throws Exception {
242: Assert.assertEquals(1, cm.getEnrollmentSets("BIO101_F2006_01")
243: .size());
244: try {
245: cm.getEnrollmentSets("bad eid");
246: fail();
247: } catch (IdNotFoundException ide) {
248: }
249: }
250:
251: public void testGetEnrollments() throws Exception {
252: Assert.assertEquals(1, cm
253: .getEnrollments("BIO101_F2006_01_ES01").size());
254: try {
255: cm.getEnrollmentSets("bad eid");
256: fail();
257: } catch (IdNotFoundException ide) {
258: }
259: }
260:
261: public void testFindEnrolledSections() throws Exception {
262: // one of the two enrollment records is flagged as 'dropped'
263: Assert.assertEquals(1, cm.findEnrolledSections("josh").size());
264: }
265:
266: public void testGetEnrollment() throws Exception {
267: Assert.assertNotNull(cm.findEnrollment("josh",
268: "BIO101_F2006_01_ES01"));
269: Assert.assertNotNull(cm.findEnrollment("josh",
270: "CHEM101_F2006_01_ES01"));
271: Assert.assertNull(cm.findEnrollment("josh", "bad eid"));
272: }
273:
274: public void testGetOfficialGraders() throws Exception {
275: Set graders = cm
276: .getInstructorsOfRecordIds("BIO101_F2006_01_ES01");
277: Assert.assertTrue(graders.contains("grader1"));
278: Assert.assertTrue(graders.contains("grader2"));
279: Assert.assertTrue(!graders.contains("josh"));
280:
281: try {
282: cm.getInstructorsOfRecordIds("bad eid");
283: fail();
284: } catch (IdNotFoundException ide) {
285: }
286: }
287:
288: public void testIsEnrolled() throws Exception {
289: Set enrollmentSetEids = new HashSet();
290: enrollmentSetEids.add("BIO101_F2006_01_ES01");
291:
292: // We don't care about bad EnrollmentSet eids here... we're just interested in Enrollments
293: enrollmentSetEids.add("bad eid");
294:
295: Assert.assertTrue(cm.isEnrolled("josh", enrollmentSetEids));
296:
297: // Graders are not enrolled
298: Assert.assertTrue(!cm.isEnrolled("grader1", enrollmentSetEids));
299: Assert.assertTrue(!cm.isEnrolled("grader2", enrollmentSetEids));
300: }
301:
302: public void testGetEnrolledEnrollmentSets() throws Exception {
303: // User "josh" is enrolled in two EnrollmentSets. One is only current in 2036.
304: // The other is always current.
305: Set enrSets = cm.findCurrentlyEnrolledEnrollmentSets("josh");
306: Assert.assertEquals(1, enrSets.size());
307: }
308:
309: public void testGetGradableEnrollmentSets() throws Exception {
310: Set gradableEnrollmentSets = cm
311: .findCurrentlyInstructingEnrollmentSets("grader1");
312: Assert.assertEquals(1, gradableEnrollmentSets.size());
313: }
314:
315: public void testFindInstructingSections() throws Exception {
316: Section section = (Section) cm.getSections("BIO101_F2006_01")
317: .iterator().next();
318: log.debug(section.getTitle() + " contains these instructors: "
319: + section.getEnrollmentSet().getOfficialInstructors());
320: Set sections = cm.findInstructingSections("grader1");
321: Assert.assertEquals(1, sections.size());
322: }
323:
324: public void testFindInstructingSectionsByAcademicSession()
325: throws Exception {
326: Set sections = cm.findInstructingSections("grader1", "F2006");
327: Assert.assertEquals(1, sections.size());
328: }
329:
330: public void testGetCourseOfferingsByCourseSetAndAcademicSession()
331: throws Exception {
332: Assert.assertEquals(1, cm.findCourseOfferings("BIO_DEPT",
333: "F2006").size());
334: }
335:
336: public void testIsCourseSetEmpty() throws Exception {
337: Assert.assertTrue(cm.isEmpty("EMPTY_COURSE_SET"));
338: Assert.assertFalse(cm.isEmpty("BIO_DEPT"));
339: Assert.assertFalse(cm.isEmpty("BIO_CHEM_GROUP"));
340: }
341:
342: public void testFindCourseSetByCategory() throws Exception {
343: List courseSets = cm.findCourseSets("DEPT");
344: Assert.assertEquals(1, courseSets.size());
345: Assert.assertEquals("BIO_DEPT", ((CourseSet) courseSets.get(0))
346: .getEid());
347: }
348:
349: public void testFindSectionRoles() throws Exception {
350: Map joshMap = cm.findSectionRoles("josh");
351: // This user is both enrolled and has a membership. This method only returns membership roles.
352: Assert.assertEquals("student", joshMap
353: .get("CHEM101_F2006_01_SEC01"));
354:
355: Map entMap = cm.findSectionRoles("AN_ENTERPRISE_USER");
356: Assert.assertEquals("AN_ENTERPRISE_ROLE", entMap
357: .get("BIO101_F2006_01_SEC01"));
358: }
359:
360: public void testFindCourseOfferingRoles() throws Exception {
361: Map coUserMap = cm.findCourseOfferingRoles("coUser");
362: Assert
363: .assertEquals("coRole1", coUserMap
364: .get("BIO101_F2006_01"));
365: Assert.assertEquals("coRole2", coUserMap
366: .get("CHEM101_F2006_01"));
367: }
368:
369: public void testFindCourseSetRoles() throws Exception {
370: Map deptAdminMap = cm.findCourseSetRoles("user1");
371: Assert.assertEquals("departmentAdmin", deptAdminMap
372: .get("BIO_DEPT"));
373: }
374:
375: public void testFindCategories() throws Exception {
376: List categories = cm.getSectionCategories();
377: Assert.assertEquals(3, categories.size());
378: }
379:
380: public void testFindCategoryDescription() throws Exception {
381: Assert.assertEquals("Lecture", cm
382: .getSectionCategoryDescription("lct"));
383: }
384:
385: }
|