You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2006/03/28 20:02:01 UTC

svn commit: r389558 - in /jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core: TestRepository.java test-repository.xml

Author: jukka
Date: Tue Mar 28 10:02:00 2006
New Revision: 389558

URL: http://svn.apache.org/viewcvs?rev=389558&view=rev
Log:
JCR-368: Add support for simple test cases

Added:
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/TestRepository.java   (with props)
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/test-repository.xml   (with props)

Added: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/TestRepository.java
URL: http://svn.apache.org/viewcvs/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/TestRepository.java?rev=389558&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/TestRepository.java (added)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/TestRepository.java Tue Mar 28 10:02:00 2006
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.core.config.ConfigurationException;
+import org.apache.jackrabbit.core.config.RepositoryConfig;
+
+/**
+ * Utility class for easy handling a test repository. This class contains
+ * a static test repository instance for use by test cases. The
+ * {@link javax.jcr.Repository#login()} method of the test repository
+ * instance should return a session with full read-write access.
+ */
+public class TestRepository {
+
+    /**
+     * Name of the resource containing the test repository configuration.
+     * The test repository configuration is located inside the Jackrabbit
+     * jar file to enforce a standard test environment.
+     */
+    private static final String CONF_RESOURCE = "test-repository.xml";
+
+    /**
+     * Name of the system property that can be used to override the
+     * default test repository location.
+     */
+    private static final String HOME_PROPERTY =
+        "org.apache.jackrabbit.test.repository.home";
+
+    /**
+     * Default test repository location.
+     */
+    private static final String HOME_DEFAULT = "jackrabbit-test-repository";
+
+    /**
+     * The test repository instance.
+     */
+    private static Repository instance = null;
+
+    /**
+     * Returns the test repository instance. If a repository instance has
+     * not yet been registered using {@link #setInstance(Repository)} as
+     * the test repostitory, then a simple {@link TransientRepository}
+     * instance is created with the standard test repository configuration
+     * and the test repository location (either "jackrabbit-test-repository"
+     * or the value of the "org.apache.jackrabbit.test.repository.home"
+     * system property).
+     *
+     * @return test repository instance
+     * @throws RepositoryException if a test repository can not be instantiated
+     */
+    public static synchronized Repository getInstance() throws RepositoryException {
+        try {
+            if (instance == null) {
+                ClassLoader loader = TestRepository.class.getClassLoader();
+                InputStream xml = loader.getResourceAsStream(CONF_RESOURCE);
+                String home = System.getProperty(HOME_PROPERTY, HOME_DEFAULT);
+                RepositoryConfig config = RepositoryConfig.create(xml, home);
+                instance = new TransientRepository(config);
+            }
+            return instance;
+        } catch (ConfigurationException e) {
+            throw new RepositoryException(
+                    "Error in test repository configuration", e);
+        } catch (IOException e) {
+            throw new RepositoryException(
+                    "Error in test repository initialization", e);
+        }
+    }
+
+    /**
+     * Sets the given repository as the test repository instance. This method
+     * is designed for use by the main Jackrabbit test suite to facilitate
+     * smooth integration of standalone test cases.
+     *
+     * @param repository test repository
+     */
+    public static synchronized void setInstance(Repository repository) {
+        instance = repository;
+    }
+
+    /**
+     * Private constructor to prevent instantiation of this class.
+     */
+    private TestRepository() {
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/TestRepository.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/test-repository.xml
URL: http://svn.apache.org/viewcvs/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/test-repository.xml?rev=389558&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/test-repository.xml (added)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/test-repository.xml Tue Mar 28 10:02:00 2006
@@ -0,0 +1,98 @@
+<?xml version="1.0"?>
+<Repository>
+    <!--
+        virtual file system where the repository stores global state
+        (e.g. registered namespaces, custom node types, etc.)
+    -->
+    <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
+        <param name="path" value="${rep.home}/repository"/>
+    </FileSystem>
+
+    <!--
+        security configuration
+    -->
+    <Security appName="Jackrabbit">
+        <!--
+            access manager:
+            class: FQN of class implementing the AccessManager interface
+        -->
+        <AccessManager class="org.apache.jackrabbit.core.security.SimpleAccessManager">
+            <!-- <param name="config" value="${rep.home}/access.xml"/> -->
+        </AccessManager>
+
+        <LoginModule class="org.apache.jackrabbit.core.security.SimpleLoginModule">
+           <!-- anonymous user name ('anonymous' is the default value) -->
+           <param name="anonymousId" value="anonymous"/>
+           <!--
+              default user name to be used instead of the anonymous user
+              when no login credentials are provided (unset by default)
+           -->
+           <param name="defaultUserId" value="superuser"/>
+        </LoginModule>
+    </Security>
+
+    <!--
+        location of workspaces root directory and name of default workspace
+    -->
+    <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default"/>
+    <!--
+        workspace configuration template:
+        used to create the initial workspace if there's no workspace yet
+    -->
+    <Workspace name="${wsp.name}">
+        <!--
+            virtual file system of the workspace:
+            class: FQN of class implementing the FileSystem interface
+        -->
+        <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
+            <param name="path" value="${wsp.home}"/>
+        </FileSystem>
+        <!--
+            persistence manager of the workspace:
+            class: FQN of class implementing the PersistenceManager interface
+        -->
+        <PersistenceManager class="org.apache.jackrabbit.core.state.db.DerbyPersistenceManager">
+          <param name="url" value="jdbc:derby:${wsp.home}/db;create=true"/>
+          <param name="schemaObjectPrefix" value="${wsp.name}_"/>
+        </PersistenceManager>
+        <!--
+            Search index and the file system it uses.
+            class: FQN of class implementing the QueryHandler interface
+        -->
+        <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
+            <param name="path" value="${wsp.home}/index"/>
+        </SearchIndex>
+    </Workspace>
+
+    <!--
+        Configures the versioning
+    -->
+    <Versioning rootPath="${rep.home}/version">
+        <!--
+            Configures the filesystem to use for versioning for the respective
+            persistence manager
+        -->
+        <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
+            <param name="path" value="${rep.home}/version" />
+        </FileSystem>
+        
+        <!--
+            Configures the persistence manager to be used for persisting version state.
+            Please note that the current versioning implementation is based on
+            a 'normal' persistence manager, but this could change in future
+            implementations.
+        -->
+        <PersistenceManager class="org.apache.jackrabbit.core.state.db.DerbyPersistenceManager">
+          <param name="url" value="jdbc:derby:${rep.home}/version/db;create=true"/>
+          <param name="schemaObjectPrefix" value="version_"/>
+        </PersistenceManager>
+    </Versioning>
+
+    <!--
+        Search index for content that is shared repository wide
+        (/jcr:system tree, contains mainly versions)
+    -->
+    <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
+        <param name="path" value="${rep.home}/repository/index"/>
+    </SearchIndex>
+</Repository>

Propchange: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/test-repository.xml
------------------------------------------------------------------------------
    svn:eol-style = native