001:
002: /*******************************************************************************
003: * Copyright (c) 2006 The Regents of the University of California
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: ******************************************************************************/package org.sakaiproject.tool.gradebook.test;
017:
018: import java.util.Date;
019: import java.util.List;
020:
021: import junit.framework.Assert;
022:
023: import org.sakaiproject.service.gradebook.shared.ConflictingSpreadsheetNameException;
024: import org.sakaiproject.tool.gradebook.Gradebook;
025: import org.sakaiproject.tool.gradebook.Spreadsheet;
026:
027: /**
028: * User: louis
029: * Date: Jun 13, 2006
030: * Time: 12:16:35 PM
031: */
032: public class SpreadsheetTest extends GradebookTestBase {
033:
034: protected Gradebook gradebook;
035: protected static final String SPT_NAME = "SP1 #1";
036: protected static final String SPT_NAME2 = "SP2 #1";
037: protected static final String SPT_NAME3 = "SP3 #1";
038: protected static final String CONTENT = "one,two,three,four,five,six,seven,eight \n";
039:
040: protected void onSetUpInTransaction() throws Exception {
041: super .onSetUpInTransaction();
042: // Create a gradebook to work with
043: String className = this .getClass().getName();
044: String gradebookName = className + (new Date()).getTime();
045: gradebookFrameworkService.addGradebook(gradebookName,
046: gradebookName);
047:
048: // Set up a holder for enrollments, teaching assignments, and sections.
049: integrationSupport.createCourse(gradebookName, gradebookName,
050: false, false, false);
051:
052: // Grab the gradebook for use in the tests
053: gradebook = gradebookManager.getGradebook(gradebookName);
054: }
055:
056: /**
057: *
058: * @throws Exception
059: */
060: public void testCreateAndUpdateSpreadsheet() throws Exception {
061:
062: Long sptId = gradebookManager.createSpreadsheet(gradebook
063: .getId(), SPT_NAME, "test_uid", new Date(), CONTENT);
064:
065: // Fetch the updated spreadsheet
066: Spreadsheet persistentSpreadsheet = gradebookManager
067: .getSpreadsheet(sptId);
068: // Ensure the DB update was successful
069: Assert.assertEquals(persistentSpreadsheet.getCreator(),
070: "test_uid");
071:
072: // Try to save a new assignment with the same name
073: boolean errorThrown = false;
074: try {
075: gradebookManager.createSpreadsheet(gradebook.getId(),
076: SPT_NAME, "test_uid", new Date(), CONTENT);
077: } catch (ConflictingSpreadsheetNameException e) {
078: errorThrown = true;
079: }
080: Assert.assertTrue(errorThrown);
081:
082: }
083:
084: /**
085: *
086: * @throws Exception
087: */
088: public void testRemoveSpreadsheet() throws Exception {
089:
090: Long id1 = gradebookManager.createSpreadsheet(
091: gradebook.getId(), SPT_NAME, "test_uid", new Date(),
092: CONTENT);
093: Long id2 = gradebookManager.createSpreadsheet(
094: gradebook.getId(), SPT_NAME2, "test_uid", new Date(),
095: CONTENT);
096: Long id3 = gradebookManager.createSpreadsheet(
097: gradebook.getId(), SPT_NAME3, "test_uid", new Date(),
098: CONTENT);
099:
100: List spreadsheets = gradebookManager.getSpreadsheets(gradebook
101: .getId());
102: Spreadsheet spt = gradebookManager.getSpreadsheet(id1);
103:
104: // Remove the spreadsheets.
105: // (We remove all of them to make sure that the calculated course grade can be emptied.)
106: gradebookManager.removeSpreadsheet(id2);
107: gradebookManager.removeSpreadsheet(id3);
108: gradebookManager.removeSpreadsheet(id1);
109:
110: // Get the list of spreadsheets again, and make sure it's missing the removed spreadsheets
111: spreadsheets = gradebookManager.getSpreadsheets(gradebook
112: .getId());
113: Assert.assertTrue(!spreadsheets.contains(spt));
114:
115: // Make sure we can add a new Spreadsheet with the same name as the removed one.
116: // This will throw an exception if it doesn't like the assignment name.
117: gradebookManager.createSpreadsheet(gradebook.getId(), SPT_NAME,
118: "test_uid", new Date(), CONTENT);
119:
120: }
121:
122: }
|