001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/sections/tags/sakai_2-4-1/sections-app/src/test/org/sakaiproject/test/section/dataload/DataLoadTest.java $
003: * $Id: DataLoadTest.java 18134 2006-11-14 18:59:25Z jholtzman@berkeley.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 The Regents of the University of California and The Regents of the University of Michigan
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.test.section.dataload;
021:
022: import java.sql.Time;
023: import java.util.ArrayList;
024: import java.util.Date;
025: import java.util.Iterator;
026: import java.util.List;
027:
028: import org.apache.commons.logging.Log;
029: import org.apache.commons.logging.LogFactory;
030: import org.sakaiproject.section.api.CourseManager;
031: import org.sakaiproject.section.api.SectionManager;
032: import org.sakaiproject.section.api.coursemanagement.Course;
033: import org.sakaiproject.section.api.coursemanagement.CourseSection;
034: import org.sakaiproject.section.api.coursemanagement.User;
035: import org.sakaiproject.section.api.exception.RoleConfigurationException;
036: import org.sakaiproject.section.api.facade.Role;
037: import org.sakaiproject.component.section.support.UserManager;
038: import org.sakaiproject.test.section.SectionsTestBase;
039:
040: public class DataLoadTest extends SectionsTestBase {
041: private static Log log = LogFactory.getLog(DataLoadTest.class);
042:
043: public DataLoadTest() {
044: // Don't roll these tests back, since they are intended to load data
045: setDefaultRollback(false);
046: }
047:
048: protected CourseManager courseManager;
049: protected SectionManager sectionManager;
050: protected UserManager userManager;
051:
052: protected void onSetUpInTransaction() throws Exception {
053: courseManager = (CourseManager) applicationContext
054: .getBean("org.sakaiproject.section.api.CourseManager");
055: sectionManager = (SectionManager) applicationContext
056: .getBean("org.sakaiproject.section.api.SectionManager");
057: userManager = (UserManager) applicationContext
058: .getBean("org.sakaiproject.component.section.support.UserManager");
059: }
060:
061: public void testLoadData() {
062: // Load courses
063: Course course1 = courseManager.createCourse("site1",
064: "A Course for Site #1", false, false, true);
065: Course course2 = courseManager.createCourse("site2",
066: "A Course for Site #2", false, false, false);
067: Course course3 = courseManager.createCourse("site3",
068: "A Course for Site #3", false, false, false);
069:
070: // Load sections
071: CourseSection lab1 = sectionManager.addSection(course1
072: .getUuid(), "Lab 1", "section.category.lab",
073: new Integer(20), "Dank basement lab", new Time(
074: new Date().getTime()), new Time(new Date()
075: .getTime()), true, false, true, false, false,
076: false, false);
077: CourseSection lab2 = sectionManager.addSection(course1
078: .getUuid(), "Lab 2", "section.category.lab",
079: new Integer(20), "Dank basement lab", new Time(
080: new Date().getTime()), new Time(new Date()
081: .getTime()), false, true, false, true, false,
082: false, false);
083: CourseSection disc1 = sectionManager.addSection(course1
084: .getUuid(), "Disc 1", "section.category.discussion",
085: new Integer(30), "Sunny classroom", new Time(new Date()
086: .getTime()), new Time(new Date().getTime()),
087: true, false, true, false, true, false, false);
088:
089: // Load students
090: User studenta = userManager.createUser("studenta",
091: "Joe Student", "Student, Joe", "jstudent");
092: User studentb = userManager.createUser("studentb",
093: "Jane Undergrad", "Undergrad, Jane", "jundergrad");
094: User studentc = userManager.createUser("studentc", "Max Guest",
095: "Guest, Max", "mguest");
096:
097: List studentList = new ArrayList();
098: for (int i = 0; i < 100; i++) {
099: studentList.add(userManager.createUser("student" + i,
100: "Test Student " + i, "Student, Test " + i,
101: "tstudent" + i));
102: }
103:
104: // Load TAs
105: User ta1 = userManager.createUser("ta1", "Mike Grad",
106: "Grad, Mike", "mgrad");
107: User ta2 = userManager.createUser("ta2",
108: "Sara Hyphenated-Elongated-Postdoc",
109: "Hyphenated-Elongated-Postdoc, Sara",
110: "shyphenatedelongatedpostdoc");
111:
112: // Load instructors
113: User instructor1 = userManager.createUser("instructor1",
114: "Bill Economist", "Economist, Bill", "beconomist");
115: User instructor2 = userManager.createUser("instructor2",
116: "Amber Philosopher", "Philosopher, Amber",
117: "aphilosopher");
118:
119: // Load other people
120: userManager.createUser("other1", "Other Person",
121: "Person, Other", "operson");
122:
123: // Load enrollments into the courses
124: courseManager.addEnrollment(studenta, course1);
125: courseManager.addEnrollment(studenta, course2);
126: courseManager.addEnrollment(studenta, course3);
127:
128: courseManager.addEnrollment(studentb, course1);
129: courseManager.addEnrollment(studentb, course2);
130: courseManager.addEnrollment(studentb, course3);
131:
132: courseManager.addEnrollment(studentc, course1);
133: courseManager.addEnrollment(studentc, course2);
134: courseManager.addEnrollment(studentc, course3);
135:
136: for (Iterator iter = studentList.iterator(); iter.hasNext();) {
137: User user = (User) iter.next();
138: courseManager.addEnrollment(user, course1);
139: courseManager.addEnrollment(user, course2);
140: courseManager.addEnrollment(user, course3);
141: }
142:
143: // Load enrollments into sections
144: try {
145: sectionManager.addSectionMembership("studenta",
146: Role.STUDENT, lab1.getUuid());
147: sectionManager.addSectionMembership("studentb",
148: Role.STUDENT, lab2.getUuid());
149: sectionManager.addSectionMembership("studentc",
150: Role.STUDENT, disc1.getUuid());
151: } catch (RoleConfigurationException rce) {
152: log.error(rce);
153: fail();
154: }
155:
156: // Load TAs into the course
157: courseManager.addTA(ta1, course1);
158: courseManager.addTA(ta1, course2);
159: courseManager.addTA(ta1, course3);
160:
161: courseManager.addTA(ta2, course1);
162: courseManager.addTA(ta2, course2);
163: courseManager.addTA(ta2, course3);
164:
165: // Load TAs into the sections
166: try {
167: sectionManager.addSectionMembership("ta1", Role.TA, lab1
168: .getUuid());
169: sectionManager.addSectionMembership("ta1", Role.TA, disc1
170: .getUuid());
171: sectionManager.addSectionMembership("ta2", Role.TA, lab2
172: .getUuid());
173: sectionManager.addSectionMembership("ta2", Role.TA, disc1
174: .getUuid());
175: } catch (RoleConfigurationException rce) {
176: log.error(rce);
177: fail();
178: }
179:
180: // Load instructors into the courses
181: courseManager.addInstructor(instructor1, course1);
182: courseManager.addInstructor(instructor2, course2);
183: courseManager.addInstructor(instructor2, course3);
184: }
185:
186: }
|