01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/archive/tags/sakai_2-4-1/import-parsers/common-cartridge/src/java/org/sakaiproject/importer/impl/CommonCartridgeTest.java $
03: * $Id: CommonCartridgeTest.java 17726 2006-11-01 15:39:28Z lance@indiana.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.importer.impl;
21:
22: import java.io.File;
23: import java.io.FileInputStream;
24: import java.io.IOException;
25: import java.util.Collection;
26: import java.util.Iterator;
27:
28: import org.sakaiproject.importer.api.ImportDataSource;
29: import org.sakaiproject.importer.api.ImportFileParser;
30: import org.sakaiproject.importer.impl.importables.Assessment;
31: import org.sakaiproject.importer.impl.importables.HtmlDocument;
32:
33: import junit.framework.TestCase;
34:
35: public class CommonCartridgeTest extends TestCase {
36: private static ImportFileParser parser;
37: private byte[] archiveData;
38:
39: public void setUp() {
40: System.out.println("doing setUp()");
41: try {
42: parser = new CommonCartridgeFileParser();
43: FileInputStream archiveStream = new FileInputStream(
44: new File("/Users/zach/psychology.zip"));
45: archiveData = new byte[archiveStream.available()];
46: archiveStream.read(archiveData, 0, archiveStream
47: .available());
48: archiveStream.close();
49: } catch (IOException e) {
50:
51: }
52: }
53:
54: public void testIsValidArchive() {
55: assertTrue(parser.isValidArchive(archiveData));
56: }
57:
58: public void testCanGetQti() {
59: ImportDataSource ids = parser.parse(archiveData,
60: "/Users/zach/Desktop/psychology");
61: Collection importables = ids.getItemsForCategories(ids
62: .getItemCategories());
63: int numberOfAssessments = 0;
64: int numberOfWebContent = 0;
65: for (Iterator i = importables.iterator(); i.hasNext();) {
66: Object x = i.next();
67: if (x instanceof Assessment) {
68: numberOfAssessments++;
69: } else if (x instanceof HtmlDocument) {
70: numberOfWebContent++;
71: }
72: }
73: System.out.println(ids.getItemCategories().size()
74: + " top-level items");
75: System.out.println(importables.size() + " importables");
76: System.out.println(numberOfAssessments + " assessments");
77: System.out.println(numberOfWebContent + " webcontent");
78: assertTrue("Why no assessments?", numberOfAssessments > 0);
79: }
80:
81: }
|