Index: lams_contentrepository/build.xml
===================================================================
RCS file: /usr/local/cvsroot/lams_contentrepository/build.xml,v
diff -u -r1.18 -r1.19
--- lams_contentrepository/build.xml 4 May 2005 05:57:35 -0000 1.18
+++ lams_contentrepository/build.xml 9 May 2005 10:22:37 -0000 1.19
@@ -239,6 +239,12 @@
+
+
+
+
+
+
Index: lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/data/CRResources.java
===================================================================
RCS file: /usr/local/cvsroot/lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/data/Attic/CRResources.java,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/data/CRResources.java 9 May 2005 10:32:37 -0000 1.1
@@ -0,0 +1,61 @@
+/*
+Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+USA
+
+http://www.gnu.org/licenses/gpl.txt
+*/
+package org.lamsfoundation.lams.contentrepository.data;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.net.URL;
+
+
+
+/**
+ * Gives access to the content package zip file used for testing
+ *
+ * @author Fiona Malikoff
+ */
+public class CRResources {
+
+ public static final String singleFileName = "TextFile.txt";
+
+ public static final String zipFileName = "bopcp.zip";
+ public static final String zipFileIncludesFilename = "index.html";
+ public static final int zipFileNumFiles = 6;
+
+ /** Get a single, text file */
+ public static InputStream getSingleFile() throws FileNotFoundException {
+ URL url = CRResources.class.getResource(singleFileName);
+ String path = url.getPath();
+ File myResource = new File(path);
+ return new FileInputStream(myResource);
+ }
+
+ /** Get a zip file. This can be used to test packages or a single binary file */
+ public static InputStream getZipFile() throws FileNotFoundException {
+ URL url = CRResources.class.getResource(zipFileName);
+ String path = url.getPath();
+ File myResource = new File(path);
+ return new FileInputStream(myResource);
+ }
+
+
+}
Index: lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/data/TextFile.txt
===================================================================
RCS file: /usr/local/cvsroot/lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/data/Attic/TextFile.txt,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/data/TextFile.txt 9 May 2005 10:32:37 -0000 1.1
@@ -0,0 +1 @@
+The quick brown fox jumped over the lazy dog.
\ No newline at end of file
Index: lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/data/bopcp.zip
===================================================================
RCS file: /usr/local/cvsroot/lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/data/Attic/bopcp.zip,v
diff -u
Binary files differ
Index: lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/service/BaseTestCase.java
===================================================================
RCS file: /usr/local/cvsroot/lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/service/Attic/BaseTestCase.java,v
diff -u -r1.1 -r1.2
--- lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/service/BaseTestCase.java 18 Apr 2005 00:01:49 -0000 1.1
+++ lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/service/BaseTestCase.java 9 May 2005 10:32:37 -0000 1.2
@@ -48,19 +48,6 @@
protected static final Long TEST_DATA_NODE_ID = new Long(1); // A datanode that should already be in db
protected static final Long TEST_FILE_NODE_ID = new Long(2); // A filenode that should already be in db
- protected final String TEXT_FILEPATH = "D:\\eclipse\\notice.html";
- protected final String TEXT_FILENAME = "notice.html";
- protected final String BINARY_FILEPATH = "D:\\eclipse\\startup.jar";
- protected final String BINARY_FILENAME = "startup.jar";
-
- // directory containing index.html and related files
- // PACKAGE_NUM_FILES should be the number of files in the
- // package excluding the directories e.g 1 html & 6 images = 7
- // no matter how many directories they may be spread across.
- protected final String PACKAGE_DIR_PATH = "C:\\temp\\girakool2003";
- protected final String PACKAGE_TEST_FILE = "images/girafalls3.jpg";
- protected final int PACKAGE_NUM_FILES = 7;
-
public BaseTestCase(){
super();
// Uncomment the following line to get debuggging.
Index: lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/service/TestSimpleRepository.java
===================================================================
RCS file: /usr/local/cvsroot/lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/service/Attic/TestSimpleRepository.java,v
diff -u -r1.1 -r1.2
--- lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/service/TestSimpleRepository.java 18 Apr 2005 00:01:49 -0000 1.1
+++ lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/service/TestSimpleRepository.java 9 May 2005 10:32:37 -0000 1.2
@@ -22,7 +22,7 @@
package org.lamsfoundation.lams.contentrepository.service;
import java.io.File;
-import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
@@ -45,6 +45,9 @@
import org.lamsfoundation.lams.contentrepository.WorkspaceNotFoundException;
import org.lamsfoundation.lams.contentrepository.dao.IFileDAO;
import org.lamsfoundation.lams.contentrepository.dao.file.FileDAO;
+import org.lamsfoundation.lams.contentrepository.data.CRResources;
+import org.lamsfoundation.lams.util.zipfile.ZipFileUtil;
+import org.lamsfoundation.lams.util.zipfile.ZipFileUtilException;
/**
@@ -225,33 +228,41 @@
public void testFileItemDeleteVersion() {
IFileDAO fileDAO = (FileDAO)context.getBean("fileDAO", FileDAO.class);
- NodeKey keys = testAddFileItem(TEXT_FILEPATH, TEXT_FILENAME,null,one);
- checkFileNodeExist(fileDAO, keys.getUuid(), one, 1);
- keys = testAddFileItem(BINARY_FILEPATH, BINARY_FILENAME,keys.getUuid(),two);
- checkFileNodeExist(fileDAO, keys.getUuid(), two, 2);
-
- deleteVersion(keys.getUuid(), two);
- checkFileNodeExist(fileDAO, keys.getUuid(), one, 1);
- checkFileNodeDoesNotExist(fileDAO, keys.getUuid(), two, 1);
-
- deleteVersion(keys.getUuid(), one);
- checkFileNodeDoesNotExist(fileDAO, keys.getUuid(), one, 0);
- checkFileNodeDoesNotExist(fileDAO, keys.getUuid(), two, 0);
+ try {
+ NodeKey keys = testAddFileItem(CRResources.getSingleFile(), CRResources.singleFileName,null,one);
+ checkFileNodeExist(fileDAO, keys.getUuid(), one, 1);
+ keys = testAddFileItem(CRResources.getZipFile(), CRResources.zipFileName,keys.getUuid(),two);
+ checkFileNodeExist(fileDAO, keys.getUuid(), two, 2);
+
+ deleteVersion(keys.getUuid(), two);
+ checkFileNodeExist(fileDAO, keys.getUuid(), one, 1);
+ checkFileNodeDoesNotExist(fileDAO, keys.getUuid(), two, 1);
+
+ deleteVersion(keys.getUuid(), one);
+ checkFileNodeDoesNotExist(fileDAO, keys.getUuid(), one, 0);
+ checkFileNodeDoesNotExist(fileDAO, keys.getUuid(), two, 0);
+ } catch (FileNotFoundException e) {
+ fail("Unexpected exception "+e.getMessage());
+ }
}
/** create a node with two versions and test deleting them using delete node */
public void testFileItemDeleteNode() {
IFileDAO fileDAO = (FileDAO)context.getBean("fileDAO", FileDAO.class);
- NodeKey keys = testAddFileItem(TEXT_FILEPATH, TEXT_FILENAME,null,one);
- checkFileNodeExist(fileDAO, keys.getUuid(), one, 1);
- testAddFileItem(BINARY_FILEPATH, BINARY_FILENAME,keys.getUuid(),two);
- checkFileNodeExist(fileDAO, keys.getUuid(), two, 2);
-
- deleteNode(keys.getUuid());
- checkFileNodeDoesNotExist(fileDAO, keys.getUuid(), one, 0);
- checkFileNodeDoesNotExist(fileDAO, keys.getUuid(), two, 0);
+ try {
+ NodeKey keys = testAddFileItem(CRResources.getSingleFile(), CRResources.singleFileName ,null,one);
+ checkFileNodeExist(fileDAO, keys.getUuid(), one, 1);
+ testAddFileItem(CRResources.getZipFile(), CRResources.zipFileName,keys.getUuid(),two);
+ checkFileNodeExist(fileDAO, keys.getUuid(), two, 2);
+
+ deleteNode(keys.getUuid());
+ checkFileNodeDoesNotExist(fileDAO, keys.getUuid(), one, 0);
+ checkFileNodeDoesNotExist(fileDAO, keys.getUuid(), two, 0);
+ } catch (FileNotFoundException e) {
+ fail("Unexpected exception "+e.getMessage());
+ }
}
/** create a node with two versions and test deleting them using delete node
@@ -263,10 +274,15 @@
IFileDAO fileDAO = (FileDAO)context.getBean("fileDAO", FileDAO.class);
- NodeKey keys = testAddFileItem(TEXT_FILEPATH, TEXT_FILENAME,null,one);
- checkFileNodeExist(fileDAO, keys.getUuid(), one, 1);
- testAddFileItem(BINARY_FILEPATH, BINARY_FILENAME,keys.getUuid(),two);
- checkFileNodeExist(fileDAO, keys.getUuid(), two, 2);
+ NodeKey keys = null;
+ try {
+ keys = testAddFileItem(CRResources.getSingleFile(), CRResources.singleFileName ,null,one);
+ checkFileNodeExist(fileDAO, keys.getUuid(), one, 1);
+ testAddFileItem(CRResources.getZipFile(), CRResources.zipFileName,keys.getUuid(),two);
+ checkFileNodeExist(fileDAO, keys.getUuid(), two, 2);
+ } catch (FileNotFoundException e) {
+ fail("Unexpected exception "+e.getMessage());
+ }
String expectProbPath = null;
try {
@@ -407,30 +423,21 @@
}
}
- private NodeKey testAddFileItem(String filePath, String filename, Long uuid, Long expectedVersion) {
+ private NodeKey testAddFileItem(InputStream file, String filename, Long uuid, Long expectedVersion) {
- InputStream isIn = null;
NodeKey keys = null;
try {
- File file = new File(filePath);
- if ( ! file.exists() || file.isDirectory() ) {
- fail("File "+filePath+" not found on computer or is a directory. Please set this variable to a known file that may be read on this computer."
- +" Note: this is a shortcoming in the test, it is not a failure of the repository.");
- }
-
- isIn = new FileInputStream(file);
-
if ( uuid == null ) {
// new file
- keys = repository.addFileItem(ticket, isIn, filename, null, v1Description);
+ keys = repository.addFileItem(ticket, file, filename, null, v1Description);
assertTrue("File save returns uuid",keys != null && keys.getUuid() != null);
assertTrue("File save got expected version "+expectedVersion,
keys != null && keys.getVersion() != null
&& keys.getVersion().equals(expectedVersion));
} else {
// update existing node
keys = repository.updateFileItem(ticket, uuid, filename,
- isIn, null, v2Description);
+ file, null, v2Description);
assertTrue("File save returns same uuid",keys != null && keys.getUuid().equals(uuid));
assertTrue("File save got expected version "+expectedVersion,
keys != null && keys.getVersion() != null
@@ -440,12 +447,10 @@
} catch (RepositoryCheckedException re) {
failUnexpectedException("testAddFileItem",re);
- } catch (IOException ioe) {
- failUnexpectedException("testAddFileItem",ioe);
} finally {
try {
- if ( isIn != null ) {
- isIn.close();
+ if ( file != null ) {
+ file.close();
}
} catch (IOException ioe1) {
System.err.println("Unable to close file");
@@ -465,25 +470,24 @@
private NodeKey testPackageItem(Long uuid) {
+ String tempDir = null;
String v1Description = "Draft";
String v2Description = "Final";
NodeKey keys = null;
try {
- File directory = new File(PACKAGE_DIR_PATH);
- if ( ! directory.exists() || ! directory.isDirectory() ) {
- fail("Directory "+PACKAGE_DIR_PATH+" not found on computer or is not a directory. Please set this variable to a directory containing an index.html file and related files."
- +" Note: this is a shortcoming in the test, it is not a failure of the repository.");
- }
+ // unpack the zip file so we have a directory to play with
+ tempDir = ZipFileUtil.expandZip(CRResources.getZipFile(), CRResources.zipFileName);
+ File directory = new File(tempDir);
String[] filenames = directory.list();
if ( uuid == null ) {
- keys = repository.addPackageItem(ticket, PACKAGE_DIR_PATH, "index.html", v1Description);
+ keys = repository.addPackageItem(ticket, tempDir, "index.html", v1Description);
assertTrue("Package save returns uuid",keys != null && keys.getUuid() != null);
assertTrue("Package save got version 1",
keys != null && keys.getVersion() != null
&& keys.getVersion().longValue() == 1);
} else {
- keys = repository.updatePackageItem(ticket, uuid, PACKAGE_DIR_PATH, "index.html", v2Description);
+ keys = repository.updatePackageItem(ticket, uuid, tempDir, "index.html", v2Description);
assertTrue("Package save returns uuid",keys != null && keys.getUuid() != null);
assertTrue("Package save got version >1",
keys != null && keys.getVersion() != null
@@ -494,15 +498,15 @@
checkFileInPackage(keys, null);
// now try another file in the package
- checkFileInPackage(keys, PACKAGE_TEST_FILE);
+ checkFileInPackage(keys, CRResources.zipFileIncludesFilename);
// check that there is the expected number of files in pacakge.
// expect an extra node over the number of files (for the package node)
List nodes = repository.getPackageNodes(ticket, keys.getUuid(), null);
assertTrue("Expected number of nodes found. Expected "
- +(PACKAGE_NUM_FILES+1)+" got "
+ +(CRResources.zipFileNumFiles+1)+" got "
+(nodes != null ? nodes.size() : 0 ),
- nodes != null && nodes.size() == (PACKAGE_NUM_FILES+1));
+ nodes != null && nodes.size() == (CRResources.zipFileNumFiles+1));
Iterator iter = nodes.iterator();
if ( iter.hasNext() ) {
SimpleVersionedNode packageNode = (SimpleVersionedNode) iter.next();
@@ -519,7 +523,19 @@
failUnexpectedException("testPackageItem",re);
} catch (IOException ioe) {
failUnexpectedException("testPackageItem",ioe);
+ } catch ( ZipFileUtilException e ) {
+ failUnexpectedException("testPackageItem",e);
+ } finally {
+ // clean up - delete that temporary directory
+ if ( tempDir != null ) {
+ try {
+ ZipFileUtil.deleteDirectory(tempDir);
+ } catch ( ZipFileUtilException e ) {
+ failUnexpectedException("testPackageItem",e);
+ }
+ }
}
+
return keys;
}
Index: lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/service/TestSimpleVersionedNode.java
===================================================================
RCS file: /usr/local/cvsroot/lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/service/Attic/TestSimpleVersionedNode.java,v
diff -u -r1.1 -r1.2
--- lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/service/TestSimpleVersionedNode.java 18 Apr 2005 00:01:49 -0000 1.1
+++ lams_contentrepository/test/java/org/lamsfoundation/lams/contentrepository/service/TestSimpleVersionedNode.java 9 May 2005 10:32:37 -0000 1.2
@@ -21,8 +21,6 @@
package org.lamsfoundation.lams.contentrepository.service;
-import java.io.File;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@@ -50,6 +48,7 @@
import org.lamsfoundation.lams.contentrepository.ValidationException;
import org.lamsfoundation.lams.contentrepository.ValueFormatException;
import org.lamsfoundation.lams.contentrepository.dao.hibernate.WorkspaceDAO;
+import org.lamsfoundation.lams.contentrepository.data.CRResources;
@@ -434,13 +433,22 @@
}
public void testTextFileNode() {
- Long uuid = testFileNodeInternal(TEXT_FILEPATH, TEXT_FILENAME, null);
- testFileNodeInternal(TEXT_FILEPATH, TEXT_FILENAME, uuid);
+ Long uuid;
+ try {
+ uuid = testFileNodeInternal(CRResources.getSingleFile(), CRResources.singleFileName, null);
+ testFileNodeInternal(CRResources.getSingleFile(), CRResources.singleFileName, uuid);
+ } catch (FileNotFoundException e) {
+ fail("Unexpected exception "+e.getMessage());
+ }
}
public void testBinaryFileNode() {
- Long uuid = testFileNodeInternal(BINARY_FILEPATH, BINARY_FILENAME, null);
- testFileNodeInternal(BINARY_FILEPATH, BINARY_FILENAME, uuid);
+ try {
+ Long uuid = testFileNodeInternal(CRResources.getZipFile(), CRResources.zipFileName, null);
+ testFileNodeInternal(CRResources.getZipFile(), CRResources.zipFileName, uuid);
+ } catch (FileNotFoundException e) {
+ fail("Unexpected exception "+e.getMessage());
+ }
}
/*
@@ -449,23 +457,15 @@
* if repositoryEntryExists == true then assume that there should
* already be a file in the directory hence an error will be thrown.
*/
- private Long testFileNodeInternal(String filePath, String filename, Long uuid) {
+ private Long testFileNodeInternal(InputStream is, String filename, Long uuid) {
- FileInputStream is = null;
InputStream newIs = null;
SimpleVersionedNode fileNode = null;
Long newUuid = uuid;
IVersionedNodeAdmin testNode = getTestNode();
try {
- File file = new File(filePath);
- if ( ! file.exists() || file.isDirectory() ) {
- fail("File "+filePath+" not found on computer or is a directory. Please set this variable to a known file that may be read on this computer."
- +" Note: this is a shortcoming in the test, it is not a failure of the repository.");
- }
- is = new FileInputStream(file);
-
// first try adding the file to a data node. Should fail as that's not allowed
try {
testNode.setFile(is, filename, null);
@@ -502,9 +502,6 @@
newIs = fileNode.getFile();
assertTrue("File node has an input stream.",newIs != null);
- } catch (FileNotFoundException fe) {
- fail("File "+filePath+" not found on computer. Please set this variable to a known file that may be read on this computer."
- +" Note: this is a shortcoming in the test, it is not a failure of the repository.");
} catch (FileException fe2) {
if ( uuid != null && fe2.getMessage().indexOf("exists")!=-1) {
assertTrue("File exists error thrown as expected.", true);