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/CourseManagementAdministrationDataLoader.java $
003: * $Id: CourseManagementAdministrationDataLoader.java 18126 2006-11-13 22:43:13Z 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.Calendar;
023: import java.util.HashSet;
024: import java.util.Set;
025:
026: import org.sakaiproject.coursemanagement.api.CourseManagementAdministration;
027: import org.sakaiproject.coursemanagement.api.Section;
028: import org.sakaiproject.coursemanagement.api.SectionCategory;
029: import org.springframework.context.support.ClassPathXmlApplicationContext;
030: import org.sakaiproject.coursemanagement.impl.DataLoader;
031:
032: import junit.framework.TestCase;
033:
034: /**
035: * Loads data into persistence. This is not a junit test per se. It extends TestCase
036: * so it's easy to execute via maven.
037: *
038: * If you want to load data into a database, just modify this class, set your db connection
039: * information in hibernate.dataload.properties, and run 'maven load-data'.
040: *
041: * @author <a href="mailto:jholtzman@berkeley.edu">Josh Holtzman</a>
042: */
043: public class CourseManagementAdministrationDataLoader extends TestCase
044: implements DataLoader {
045: private CourseManagementAdministration cmAdmin;
046:
047: public void testLoadData() throws Exception {
048: ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext(
049: new String[] { "spring-test.xml",
050: "spring-config-dataload.xml" });
051: cmAdmin = (CourseManagementAdministration) ac
052: .getBean(CourseManagementAdministration.class.getName());
053: load();
054: }
055:
056: public void load() throws Exception {
057: // Academic Sessions
058: Calendar startCal = Calendar.getInstance();
059: Calendar endCal = Calendar.getInstance();
060:
061: startCal.set(2006, 8, 1);
062: endCal.set(2006, 12, 1);
063: cmAdmin.createAcademicSession("f2006", "Fall 2006",
064: "The fall term, 2006", startCal.getTime(), endCal
065: .getTime());
066:
067: startCal.set(2007, 3, 1);
068: endCal.set(2007, 6, 1);
069: cmAdmin.createAcademicSession("sp2007", "Spring 2007",
070: "The spring term, 2007", startCal.getTime(), endCal
071: .getTime());
072:
073: cmAdmin.createAcademicSession("IND", "Ongoing Courses",
074: "Ongoing session for independent study", null, null);
075:
076: // Section Categories
077: SectionCategory lectureCategory = cmAdmin.addSectionCategory(
078: "lct", "Lecture");
079: SectionCategory labCategory = cmAdmin.addSectionCategory("lab",
080: "Lab");
081: SectionCategory discussionCategory = cmAdmin
082: .addSectionCategory("dsc", "Discussion");
083: SectionCategory recitationCategory = cmAdmin
084: .addSectionCategory("rec", "Recitation");
085: SectionCategory studioCategory = cmAdmin.addSectionCategory(
086: "sto", "Studio");
087:
088: // Course Sets
089: cmAdmin.createCourseSet("bio", "Biology Department",
090: "We study wet things in the Bio Dept", "DEPT", null);
091: cmAdmin.addOrUpdateCourseSetMembership("da1", "DeptAdmin",
092: "bio", "active");
093:
094: // Canonical Courses
095: cmAdmin.createCanonicalCourse("bio101", "Intro to Biology",
096: "An introduction to biology");
097: cmAdmin
098: .createCanonicalCourse(
099: "indep_study_bio",
100: "Independent Study in Biology",
101: "A self paced independent study in biology. Must be "
102: + "approved and sponsored by biology department faculty.");
103:
104: // Course Offerings
105: startCal.set(2006, 8, 1);
106: endCal.set(2006, 12, 1);
107: cmAdmin.createCourseOffering("bio101_f2006",
108: "Bio 101, Fall 2006", "Intro to Biology, Fall 06",
109: "open", "f2006", "bio101", startCal.getTime(), endCal
110: .getTime());
111: cmAdmin.addCourseOfferingToCourseSet("bio", "bio101_f2006");
112:
113: startCal.set(2007, 3, 1);
114: endCal.set(2007, 6, 1);
115: cmAdmin.createCourseOffering("bio101_sp2007",
116: "Bio 101, Spring 2007", "Intro to Biology, Spring 07",
117: "open", "sp2007", "bio101", startCal.getTime(), endCal
118: .getTime());
119:
120: cmAdmin.createCourseOffering(
121: "indep_study_bio_molecular_research",
122: "Independent study in molecular research",
123: "Details to be determined by student and sponsor",
124: "open", "IND", "indep_study_bio", null, null);
125:
126: // Enrollment sets
127: Set instructors = new HashSet();
128: instructors.add("admin");
129: cmAdmin.createEnrollmentSet("bio101_f2006_lec1",
130: "Bio 101 Lecture", "Bio 101 Lecture. Required.",
131: "lecture", "3", "bio101_f2006", instructors);
132:
133: instructors.clear();
134: instructors.add("ta1");
135: cmAdmin.createEnrollmentSet("bio101_f2006_lab1", "Lab 1",
136: "Lab 1", "lab", "1", "bio101_f2006", instructors);
137:
138: instructors.clear();
139: instructors.add("ta2");
140: cmAdmin.createEnrollmentSet("bio101_f2006_lab2", "Lab 2",
141: "Lab 2", "lab", "1", "bio101_f2006", instructors);
142:
143: // Enrollments
144: cmAdmin.addOrUpdateEnrollment("student1", "bio101_f2006_lec1",
145: "enrolled", "3", "standard");
146: cmAdmin.addOrUpdateEnrollment("student2", "bio101_f2006_lec1",
147: "enrolled", "3", "pass/fail");
148: cmAdmin.addOrUpdateEnrollment("student3", "bio101_f2006_lec1",
149: "waitlisted", "3", "standard");
150:
151: cmAdmin.addOrUpdateEnrollment("student1", "bio101_f2006_lab1",
152: "enrolled", "1", "standard");
153: cmAdmin.addOrUpdateEnrollment("student2", "bio101_f2006_lab1",
154: "enrolled", "1", "pass/fail");
155:
156: cmAdmin.addOrUpdateEnrollment("student3", "bio101_f2006_lab2",
157: "waitlisted", "1", "standard");
158:
159: // Sections
160: Section lec1 = cmAdmin.createSection("bio101_f2006_lec1",
161: "Bio 101, Lecture",
162: "Intro to Biology, Fall 06, Lecture", lectureCategory
163: .getCategoryCode(), null, "bio101_f2006",
164: "bio101_f2006_lec1");
165: cmAdmin.createSection("bio101_f2006_lab1", "Lab 1",
166: "Intro to Biology, Fall 06, Lab 1", labCategory
167: .getCategoryCode(), null, "bio101_f2006",
168: "bio101_f2006_lab1");
169: cmAdmin.createSection("bio101_f2006_lab2", "Lab 2",
170: "Intro to Biology, Fall 06, Lab 2", labCategory
171: .getCategoryCode(), null, "bio101_f2006",
172: "bio101_f2006_lab2");
173:
174: // Meetings
175: Set lecMeetings = new HashSet();
176: lecMeetings.add(cmAdmin.newSectionMeeting("bio101_f2006_lec1",
177: "a location", null, null, "somenotes"));
178: lecMeetings.add(cmAdmin.newSectionMeeting("bio101_f2006_lec1",
179: "another location", null, null, "some other notes"));
180: lec1.setMeetings(lecMeetings);
181: cmAdmin.updateSection(lec1);
182:
183: }
184:
185: }
|