jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r292294 - in /incubator/jackrabbit/trunk/src: java/org/apache/jackrabbit/core/config/RepositoryConfig.java test/org/apache/jackrabbit/core/config/RepositoryConfigTest.java
Date Wed, 28 Sep 2005 20:46:15 GMT
Author: jukka
Date: Wed Sep 28 13:46:08 2005
New Revision: 292294

URL: http://svn.apache.org/viewcvs?rev=292294&view=rev
Log:
Added RepositoryConfig test cases and better error reporting when attempting to create a duplicate
workspace.

Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/RepositoryConfig.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/RepositoryConfigTest.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/RepositoryConfig.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/RepositoryConfig.java?rev=292294&r1=292293&r2=292294&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/RepositoryConfig.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/RepositoryConfig.java
Wed Sep 28 13:46:08 2005
@@ -296,9 +296,13 @@
 
         // Create the directory, fail if it exists or cannot be created
         if (!directory.mkdir()) {
-            throw new ConfigurationException(
-                    "Failed to create configuration directory for workspace "
-                    + name + ".");
+            if (directory.exists()) {
+                throw new ConfigurationException(
+                        "Workspace directory already exists: " + name);
+            } else {
+                throw new ConfigurationException(
+                        "Failed to create workspace directory: " + name);
+            }
         }
 
         // Create the workspace.xml file using the configuration template.

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/RepositoryConfigTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/RepositoryConfigTest.java?rev=292294&r1=292293&r2=292294&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/RepositoryConfigTest.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/config/RepositoryConfigTest.java
Wed Sep 28 13:46:08 2005
@@ -28,21 +28,46 @@
  */
 public class RepositoryConfigTest extends TestCase {
 
+    private static final String REPOSITORY_XML = "org/apache/jackrabbit/core/config/repository.xml";
+
+    private static final String REPOSITORY_HOME = "target/test-repository";
+
+    private RepositoryConfig config;
+
+    private static void deleteAll(File file) {
+        if (file.exists()) {
+            if (file.isDirectory()) {
+                File[] children = file.listFiles();
+                for (int i = 0; i < children.length; i++) {
+                    deleteAll(children[i]);
+                }
+            }
+            file.delete();
+        }
+    }
+
     /**
-     * Test that a standard repository configuration file is
-     * correctly parsed.
-     *
-     * @throws Exception on errors
+     * Sets up the test case by reading the test repository configuration file.
      */
-    public void testRepositoryXml() throws Exception {
-        InputStream xml = getClass().getClassLoader().getResourceAsStream(
-                "org/apache/jackrabbit/core/config/repository.xml");
-        RepositoryConfig config =
-            RepositoryConfig.create(new InputSource(xml), "target");
+    protected void setUp() throws Exception {
+        ClassLoader loader = getClass().getClassLoader();
+        InputStream xml = loader.getResourceAsStream(REPOSITORY_XML);
+        config = RepositoryConfig.create(new InputSource(xml), REPOSITORY_HOME);
+    }
+
+    protected void tearDown() {
+        deleteAll(new File(REPOSITORY_HOME));
+    }
 
-        assertEquals("target", config.getHomeDir());
+    /**
+     * Test that the repository configuration file is correctly parsed.
+     */
+    public void testRepositoryConfig() throws Exception {
+        assertEquals(REPOSITORY_HOME, config.getHomeDir());
         assertEquals("default", config.getDefaultWorkspaceName());
-        assertEquals("target/workspaces", config.getWorkspacesConfigRootDir());
+        assertEquals(
+                new File(REPOSITORY_HOME, "workspaces").getPath(),
+                config.getWorkspacesConfigRootDir());
         assertEquals("Jackrabbit", config.getAppName());
 
         AccessManagerConfig amc = config.getAccessManagerConfig();
@@ -52,11 +77,35 @@
         assertTrue(amc.getParameters().isEmpty());
 
         VersioningConfig vc = config.getVersioningConfig();
-        assertEquals(new File("target/version"), vc.getHomeDir());
+        assertEquals(new File(REPOSITORY_HOME, "version"), vc.getHomeDir());
         assertEquals(
                 "org.apache.jackrabbit.core.state.obj.ObjectPersistenceManager",
                 vc.getPersistenceManagerConfig().getClassName());
         assertTrue(vc.getPersistenceManagerConfig().getParameters().isEmpty());
+    }
+
+    public void testInit() throws Exception {
+        File workspaces_dir = new File(REPOSITORY_HOME, "workspaces");
+        File workspace_dir = new File(workspaces_dir, "default");
+        File workspace_xml = new File(workspace_dir, "workspace.xml");
+        assertTrue(workspace_xml.exists());
+    }
+
+    public void testCreateWorkspaceConfig() throws Exception {
+        config.createWorkspaceConfig("test-workspace");
+        File workspaces_dir = new File(REPOSITORY_HOME, "workspaces");
+        File workspace_dir = new File(workspaces_dir, "test-workspace");
+        File workspace_xml = new File(workspace_dir, "workspace.xml");
+        assertTrue(workspace_xml.exists());
+    }
+
+    public void testCreateDuplicateWorkspaceConfig() throws Exception {
+        try {
+            config.createWorkspaceConfig("default");
+            fail("No exception thrown when creating a duplicate workspace");
+        } catch (ConfigurationException e) {
+            // test passed
+        }
     }
 
 }



Mime
View raw message