001: /**********************************************************************************
002: *
003: * $Id: TestGradebookLoader.java 21205 2007-02-09 20:00:15Z ray@media.berkeley.edu $
004: *
005: ***********************************************************************************
006: *
007: * Copyright (c) 2005 The Regents of the University of California, The MIT Corporation
008: *
009: * Licensed under the Educational Community License, Version 1.0 (the "License");
010: * you may not use this file except in compliance with the License.
011: * You may obtain a copy of the License at
012: *
013: * http://www.opensource.org/licenses/ecl1.php
014: *
015: * Unless required by applicable law or agreed to in writing, software
016: * distributed under the License is distributed on an "AS IS" BASIS,
017: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018: * See the License for the specific language governing permissions and
019: * limitations under the License.
020: *
021: **********************************************************************************/package org.sakaiproject.tool.gradebook.test;
022:
023: import java.util.ArrayList;
024: import java.util.Arrays;
025: import java.util.Date;
026: import java.util.List;
027:
028: import org.sakaiproject.component.section.support.IntegrationSupport;
029: import org.sakaiproject.component.section.support.UserManager;
030: import org.sakaiproject.service.gradebook.shared.GradingScaleDefinition;
031: import org.sakaiproject.tool.gradebook.Gradebook;
032:
033: /**
034: * Create a Gradebook for each site context in the database.
035: */
036: public class TestGradebookLoader extends GradebookLoaderBase {
037: public static String GRADEBOOK_WITH_GRADES = "QA_6";
038:
039: static String ASN_BASE_NAME = "Homework #";
040: static String EXTERNAL_ASN_NAME1 = "External Assessment #1";
041: static String EXTERNAL_ASN_NAME2 = "External Assessment #2";
042: static String ASN_NO_DUE_DATE_NAME = "Fl\u00F8ating Assignment (Due Whenever)";
043: // static String ASN_NO_DUE_DATE_NAME = "F\u4E40\u00F8ating Assignment"; // Test for Chinese support
044: static String ASN_NOT_COUNTED_NAME = "Self-Assessment";
045:
046: protected IntegrationSupport integrationSupport;
047: protected UserManager userManager;
048:
049: public TestGradebookLoader() {
050: // Don't roll these tests back, since they are intended to load data
051: setDefaultRollback(false);
052: }
053:
054: public IntegrationSupport getIntegrationSupport() {
055: return integrationSupport;
056: }
057:
058: public void setIntegrationSupport(
059: IntegrationSupport integrationSupport) {
060: this .integrationSupport = integrationSupport;
061: }
062:
063: private void loadGradingScales() {
064: List<GradingScaleDefinition> newMappings = new ArrayList<GradingScaleDefinition>();
065: GradingScaleDefinition def;
066:
067: def = new GradingScaleDefinition();
068: def.setUid("LetterGradePlusMinusMapping");
069: def.setName("Letter Grades with +/-");
070: def.setGrades(Arrays.asList(new String[] { "A+", "A", "A-",
071: "B+", "B", "B-", "C+", "C", "C-", "D+", "D", "D-", "F",
072: "I", "NR" }));
073: def.setDefaultBottomPercents(Arrays.asList(new Object[] {
074: new Double(100.0), new Double(95.0), new Double(90.0),
075: new Double(87.0), new Double(83.0), new Double(80.0),
076: new Double(77.0), new Double(73.0), new Double(70.0),
077: new Double(67.0), new Double(63.0), new Double(60.0),
078: new Double(0), null, null }));
079: newMappings.add(def);
080:
081: def = new GradingScaleDefinition();
082: def.setUid("LetterGradeMapping");
083: def.setName("Letter Grades");
084: def.setGrades(Arrays.asList(new String[] { "A", "B", "C", "D",
085: "F", "I" }));
086: def.setDefaultBottomPercents(Arrays.asList(new Object[] {
087: new Double(90.0), new Double(80.0), new Double(70.0),
088: new Double(60.0), new Double(0), null }));
089: newMappings.add(def);
090:
091: def = new GradingScaleDefinition();
092: def.setUid("PassNotPassMapping");
093: def.setName("Pass / Not Pass");
094: def.setGrades(Arrays.asList(new String[] { "P", "NP" }));
095: def.setDefaultBottomPercents(Arrays.asList(new Object[] {
096: new Double(75), new Double(0) }));
097: newMappings.add(def);
098:
099: gradebookFrameworkService
100: .setAvailableGradingScales(newMappings);
101: gradebookFrameworkService
102: .setDefaultGradingScale("LetterGradePlusMinusMapping");
103:
104: }
105:
106: public void testLoadGradebooks() throws Exception {
107: loadGradingScales();
108:
109: List gradebooks = new ArrayList();
110: List gradebookUids = new ArrayList();
111:
112: // Create some gradebooks
113: for (int i = 0; i < StandaloneSectionsDataLoader.SITE_UIDS.length; i++) {
114: String gradebookUid = StandaloneSectionsDataLoader.SITE_UIDS[i];
115: gradebookFrameworkService.addGradebook(gradebookUid,
116: StandaloneSectionsDataLoader.SITE_NAMES[i]);
117: gradebookUids.add(gradebookUid);
118: }
119:
120: // Fetch the gradebooks
121: for (int i = 0; i < StandaloneSectionsDataLoader.SITE_UIDS.length; i++) {
122: gradebooks.add(gradebookManager
123: .getGradebook((String) gradebookUids.get(i)));
124: }
125:
126: // Add assignments for gradebook #6
127: Gradebook gb = (Gradebook) gradebooks.get(5);
128: for (int i = 0; i < 7; i++) {
129: int pts = (i + 1) * 10;
130: Date date = new Date();
131: date.setTime(date.getTime() - ((6 - i) * 86400000));
132: gradebookManager.createAssignment(gb.getId(), ASN_BASE_NAME
133: + i, new Double(pts), date, Boolean.FALSE,
134: Boolean.FALSE);
135: }
136:
137: // Add an assignment without a due date.
138: gradebookManager.createAssignment(gb.getId(),
139: ASN_NO_DUE_DATE_NAME, new Double(50), null,
140: Boolean.FALSE, Boolean.FALSE);
141:
142: // Add external assessments
143: gradebookExternalAssessmentService.addExternalAssessment(gb
144: .getUid(), EXTERNAL_ASN_NAME1, "samigo://external1",
145: EXTERNAL_ASN_NAME1, 10, new Date(), "Test and Quiz");
146: gradebookExternalAssessmentService.addExternalAssessment(gb
147: .getUid(), EXTERNAL_ASN_NAME2, null,
148: EXTERNAL_ASN_NAME2, 10, new Date(), "Test and Quiz");
149:
150: // Add an assignment which won't count towards the final grade.
151: gradebookManager.createAssignment(gb.getId(),
152: ASN_NOT_COUNTED_NAME, new Double(100), new Date(),
153: Boolean.TRUE, Boolean.FALSE);
154:
155: // Ensure that this is actually saved to the database
156: setComplete();
157: }
158: }
|