001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/sections/tags/sakai_2-4-1/sections-app/src/test/org/sakaiproject/test/section/dataload/GradebookDataLoader.java $
003: * $Id: GradebookDataLoader.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.util.ArrayList;
023: import java.util.Iterator;
024: import java.util.List;
025:
026: import org.apache.commons.logging.Log;
027: import org.apache.commons.logging.LogFactory;
028: import org.sakaiproject.section.api.CourseManager;
029: import org.sakaiproject.section.api.SectionManager;
030: import org.sakaiproject.section.api.coursemanagement.Course;
031: import org.sakaiproject.section.api.coursemanagement.User;
032: import org.sakaiproject.component.section.support.UserManager;
033: import org.sakaiproject.test.section.SectionsTestBase;
034:
035: public class GradebookDataLoader extends SectionsTestBase {
036: private static Log log = LogFactory
037: .getLog(GradebookDataLoader.class);
038:
039: public static final String[] SITE_UIDS = { "QA_1", "QA_2", "QA_3",
040: "QA_4", "QA_5", "QA_6", "QA_7", "QA_8", };
041: public static final String[] SITE_NAMES = {
042: "QA Site #1 [no students, 1 instructor, no self reg, no self switch, external]",
043: "QA Site #2 [10 students, 1 instructor, no self reg, no self switch, internal]",
044: "QA Site #3 [10 students, 1 instructor, no self reg, no self switch, internal]",
045: "QA Site #4 [10 students, 1 instructor, no self reg, no self switch, internal]",
046: "QA Site #5 [50 students, 1 instructor, no self reg, no self switch, internal]",
047: "QA Site #6 [50 students, 1 instructor, no self reg, no self switch, internal]",
048: "QA Site #7 [150 students, 1 instructor, no self reg, no self switch, internal]",
049: "QA Site #8 [400 students, 1 instructor, no self reg, no self switch, internal]", };
050: public static boolean[] SITE_SELF_REG = { false, false, false,
051: false, false, false, false, false, };
052: public static boolean[] SITE_SELF_SWITCH = { false, false, false,
053: false, false, false, false, false, };
054: public static boolean[] SITE_EXTERNALLY_MANAGED = { true, false,
055: false, false, false, false, false, false, };
056:
057: /** Special users */
058: public final static String AUTHID_TEACHER_ALL = "authid_teacher";
059: public final static String AUTHID_TEACHER_AND_STUDENT = "authid_teacher_student";
060: public final static String AUTHID_STUDENT_ALL = "stu_0";
061: public final static String AUTHID_NO_SITE = "authid_nowhere";
062: public final static String AUTHID_STUDENT_PREFIX = "stu_";
063:
064: /** Special sites */
065: public static int SITE_AMBIGUOUS_TEACHER = 2;
066: public static int SITE_AMBIGUOUS_STUDENT = 6;
067:
068: public GradebookDataLoader() {
069: // Don't roll these tests back, since they are intended to load data
070: setDefaultRollback(false);
071: }
072:
073: protected CourseManager courseManager;
074: protected SectionManager sectionManager;
075: protected UserManager userManager;
076:
077: protected void onSetUpInTransaction() throws Exception {
078: courseManager = (CourseManager) applicationContext
079: .getBean("org.sakaiproject.section.api.CourseManager");
080: sectionManager = (SectionManager) applicationContext
081: .getBean("org.sakaiproject.section.api.SectionManager");
082: userManager = (UserManager) applicationContext
083: .getBean("org.sakaiproject.component.section.support.UserManager");
084: }
085:
086: public void testLoadData() {
087: // Load courses. (No sections yet!)
088: List sites = new ArrayList(SITE_UIDS.length);
089: for (int i = 0; i < SITE_UIDS.length; i++) {
090: sites.add(courseManager.createCourse(SITE_UIDS[i],
091: SITE_NAMES[i], SITE_SELF_REG[i],
092: SITE_SELF_SWITCH[i], SITE_EXTERNALLY_MANAGED[i]));
093: }
094:
095: // Load users.
096: User teacherAll = userManager.createUser(AUTHID_TEACHER_ALL,
097: "Bizzy Teacher", "Teacher, Bizzy", "uTeacher");
098: User teacherStudent = userManager.createUser(
099: AUTHID_TEACHER_AND_STUDENT, "Teaching Assistant",
100: "Assistant, Teaching", "uTA");
101: List students = new ArrayList(400);
102:
103: for (int i = 0; i < 400; i++) {
104: String firstName;
105: String lastName;
106: switch (i) {
107: case 0:
108: firstName = "Abby Lynn";
109: lastName = "Astudent";
110: break;
111: case 1:
112: firstName = "Mary";
113: lastName = "LongLastNameThatExceedsTheMaximumInTheGradebook";
114: break;
115: case 3:
116: firstName = "Susan";
117: lastName = "Smith-Morris";
118: break;
119: case 4:
120: firstName = "Nathan Q., Jr.";
121: lastName = "Brewster";
122: break;
123: case 5:
124: firstName = "Carol Lee";
125: lastName = "Williams";
126: break;
127: case 6:
128: firstName = "Kim";
129: lastName = "Jones Parker";
130: break;
131: case 7:
132: firstName = "Joe";
133: lastName = "Brown";
134: break;
135: case 8:
136: firstName = "Joe";
137: lastName = "Brown";
138: break;
139: case 9:
140: firstName = "Sarah Jane";
141: lastName = "Miller";
142: break;
143: case 10:
144: firstName = "Rachel";
145: lastName = "Wilson";
146: break;
147: case 11:
148: firstName = "Ali";
149: lastName = "Moore";
150: break;
151: case 12:
152: firstName = "Chen-Wai";
153: lastName = "Taylor";
154: break;
155: case 13:
156: firstName = "Samuel Taylor Coleridge";
157: lastName = "Ascot";
158: break;
159: case 14:
160: firstName = "Jane Quincy";
161: lastName = "Brandenburg";
162: break;
163: case 15:
164: firstName = "Thor";
165: lastName = "Mj\u00F8lner";
166: break;
167: case 16:
168: firstName = "Lazy";
169: lastName = "Etudient1";
170: break;
171: case 17:
172: firstName = "Lazy";
173: lastName = "Etudient2";
174: break;
175: default:
176: firstName = "First Middle";
177: lastName = "LastName" + i;
178: }
179: String uidPrefix = (i != 3) ? "uid_" : "uID_";
180: students.add(userManager.createUser(AUTHID_STUDENT_PREFIX
181: + i, firstName + " " + lastName, lastName + ", "
182: + firstName, uidPrefix + i));
183: }
184: User nobody = userManager.createUser(AUTHID_NO_SITE,
185: "Johnny Nobody", "Nobody, Johnny", AUTHID_NO_SITE);
186:
187: // No TAs yet.
188:
189: // Load enrollments into the courses.
190: for (int i = 0; i < students.size(); i++) {
191: // Everyone is added to Site 8.
192: courseManager.addEnrollment((User) students.get(i),
193: (Course) sites.get(7));
194:
195: // The first 150 students are added to Site 7.
196: if (i < 150) {
197: courseManager.addEnrollment((User) students.get(i),
198: (Course) sites.get(6));
199:
200: // The first 50 students are added to Site 5 and 6, but 6 contains a special student....
201: if (i < 50) {
202: courseManager.addEnrollment((User) students.get(i),
203: (Course) sites.get(4));
204: if (i < 49) {
205: courseManager.addEnrollment((User) students
206: .get(i), (Course) sites.get(5));
207:
208: // The first 10 students are added to Site 2, 3, and 4.
209: if (i < 10) {
210: courseManager.addEnrollment((User) students
211: .get(i), (Course) sites.get(3));
212: courseManager.addEnrollment((User) students
213: .get(i), (Course) sites.get(2));
214: courseManager.addEnrollment((User) students
215: .get(i), (Course) sites.get(1));
216: }
217: }
218: }
219: }
220: }
221:
222: // Load instructors into the courses.
223: for (Iterator iter = sites.iterator(); iter.hasNext();) {
224: courseManager.addInstructor(teacherAll, (Course) iter
225: .next());
226: }
227:
228: // Load the ambiguous one.
229: courseManager.addInstructor(teacherStudent, (Course) sites
230: .get(SITE_AMBIGUOUS_TEACHER));
231: courseManager.addEnrollment(teacherStudent, (Course) sites
232: .get(SITE_AMBIGUOUS_STUDENT));
233: }
234:
235: }
|