From 1c62224b6d2f1298e613088a1cba1e1d9904cabf Mon Sep 17 00:00:00 2001 From: jeb228 Date: Thu, 22 Jul 2010 15:22:18 +0000 Subject: [PATCH] NIHVIVO-927 Merge 5386 from branch. --- .../filestorage/backend/FileStorageSetup.java | 20 ++++++++------- .../servlet/setup/UpdateUploadedFiles.java | 24 ++++++++---------- .../backend/FileStorageSetupTest.java | 25 +++++++++++++------ 3 files changed, 38 insertions(+), 31 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/filestorage/backend/FileStorageSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/filestorage/backend/FileStorageSetup.java index 87965e970..e500f389a 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/filestorage/backend/FileStorageSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/filestorage/backend/FileStorageSetup.java @@ -3,7 +3,6 @@ package edu.cornell.mannlib.vitro.webapp.filestorage.backend; import java.io.File; -import java.io.IOException; import java.util.Collection; import java.util.Collections; @@ -11,6 +10,9 @@ import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties; /** @@ -18,6 +20,8 @@ import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties; * context. */ public class FileStorageSetup implements ServletContextListener { + private static final Log log = LogFactory.getLog(FileStorageSetup.class); + /** * The implementation of the {@link FileStorage} system will be stored in * the {@link ServletContext} as an attribute with this name. @@ -43,18 +47,16 @@ public class FileStorageSetup implements ServletContextListener { */ @Override public void contextInitialized(ServletContextEvent sce) { - FileStorage fs; try { File baseDirectory = figureBaseDir(); Collection fileNamespace = confirmDefaultNamespace(); - fs = new FileStorageImpl(baseDirectory, fileNamespace); - } catch (IOException e) { - throw new IllegalStateException( - "Failed to initialize the file system.", e); - } + FileStorage fs = new FileStorageImpl(baseDirectory, fileNamespace); - ServletContext sc = sce.getServletContext(); - sc.setAttribute(ATTRIBUTE_NAME, fs); + ServletContext sc = sce.getServletContext(); + sc.setAttribute(ATTRIBUTE_NAME, fs); + } catch (Exception e) { + log.fatal("Failed to initialize the file system.", e); + } } /** diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/UpdateUploadedFiles.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/UpdateUploadedFiles.java index 94a975a8f..c89f5b7d0 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/UpdateUploadedFiles.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/UpdateUploadedFiles.java @@ -52,10 +52,9 @@ public class UpdateUploadedFiles implements ServletContextListener { + "The ServletContext does not contain an attribute " + "for '" + "webappDaoFactory" + "'. " + "Does the log contain a previous exception from " - + "JenaDataSourceSetup? Have you looked in " - + "localhost.log for such an exception? Is it " - + "possible that web.xml is not set up to run " - + "JenaDataSourceSetup before UpdateUploadedFiles?"); + + "JenaDataSourceSetup? Is it possible that web.xml " + + "is not set up to run JenaDataSourceSetup before " + + "UpdateUploadedFiles?"); } OntModel jenaOntModel = (OntModel) ctx @@ -65,10 +64,9 @@ public class UpdateUploadedFiles implements ServletContextListener { + "The ServletContext does not contain an attribute " + "for '" + JENA_ONT_MODEL_ATTRIBUTE_NAME + "'. " + "Does the log contain a previous exception from " - + "JenaDataSourceSetup? Have you looked in " - + "localhost.log for such an exception? Is it " - + "possible that web.xml is not set up to run " - + "JenaDataSourceSetup before UpdateUploadedFiles?"); + + "JenaDataSourceSetup? Is it possible that web.xml " + + "is not set up to run JenaDataSourceSetup before " + + "UpdateUploadedFiles?"); } FileStorage fileStorage = (FileStorage) ctx @@ -78,10 +76,9 @@ public class UpdateUploadedFiles implements ServletContextListener { + "The ServletContext does not contain an attribute " + "for '" + FileStorageSetup.ATTRIBUTE_NAME + "'. " + "Does the log contain a previous exception from " - + "FileStorageSetup? Have you looked in " - + "localhost.log for such an exception? Is it " - + "possible that web.xml is not set up to run " - + "FileStorageSetup before UpdateUploadedFiles?"); + + "FileStorageSetup? Is it possible that web.xml is " + + "not set up to run FileStorageSetup before " + + "UpdateUploadedFiles?"); } String uploadDirectoryName = ConfigurationProperties @@ -104,8 +101,7 @@ public class UpdateUploadedFiles implements ServletContextListener { fileStorage, uploadDirectory, webappImageDirectory); fsu.update(); } catch (Exception e) { - log.error("Unknown problem", e); - throw new RuntimeException(e); + log.fatal("Unknown problem", e); } } } diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/filestorage/backend/FileStorageSetupTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/filestorage/backend/FileStorageSetupTest.java index 85d9b9635..431a7432e 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/filestorage/backend/FileStorageSetupTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/filestorage/backend/FileStorageSetupTest.java @@ -3,6 +3,7 @@ package edu.cornell.mannlib.vitro.webapp.filestorage.backend; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; import java.io.File; @@ -57,8 +58,8 @@ public class FileStorageSetupTest extends AbstractTestClass { System.setProperty(InitialContext.INITIAL_CONTEXT_FACTORY, InitialContextFactoryStub.class.getName()); InitialContextStub.reset(); - new InitialContext().bind("java:comp/env/path.configuration", propsFile - .getPath()); + new InitialContext().bind("java:comp/env/path.configuration", + propsFile.getPath()); } @Before @@ -77,29 +78,37 @@ public class FileStorageSetupTest extends AbstractTestClass { // tests // ---------------------------------------------------------------------- - @Test(expected = IllegalArgumentException.class) + @Test public void baseDirectoryNotSpecified() { setConfigurationProperties(null, "http://vivo.myDomain.edu/individual/"); fss.contextInitialized(sce); + assertNull("no base directory", + sc.getAttribute(FileStorageSetup.ATTRIBUTE_NAME)); } - @Test(expected = IllegalArgumentException.class) + @Test public void baseDirectoryDoesntExist() throws IOException { setConfigurationProperties("/bogus/Directory", "http://vivo.myDomain.edu/individual/"); fss.contextInitialized(sce); + assertNull("no such directory", + sc.getAttribute(FileStorageSetup.ATTRIBUTE_NAME)); } - @Test(expected = IllegalArgumentException.class) + @Test public void defaultNamespaceNotSpecified() { setConfigurationProperties(tempDir.getPath(), null); fss.contextInitialized(sce); + assertNull("no default namespace", + sc.getAttribute(FileStorageSetup.ATTRIBUTE_NAME)); } - @Test(expected = IllegalArgumentException.class) + @Test public void defaultNamespaceIsBogus() throws IOException { setConfigurationProperties(tempDir.getPath(), "namespace"); fss.contextInitialized(sce); + assertNull("default namespace is bogus", + sc.getAttribute(FileStorageSetup.ATTRIBUTE_NAME)); } @Test @@ -111,8 +120,8 @@ public class FileStorageSetupTest extends AbstractTestClass { Object o = sc.getAttribute(FileStorageSetup.ATTRIBUTE_NAME); FileStorage fs = (FileStorage) o; - assertEquals("implementation class", FileStorageImpl.class, fs - .getClass()); + assertEquals("implementation class", FileStorageImpl.class, + fs.getClass()); } // ----------------------------------------------------------------------