jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r390668 - /jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/TestRepository.java
Date Sat, 01 Apr 2006 13:24:10 GMT
Author: jukka
Date: Sat Apr  1 05:24:09 2006
New Revision: 390668

URL: http://svn.apache.org/viewcvs?rev=390668&view=rev
Log:
JCR-368: Integrated the TestRepository class with the Jackrabbit main test suite without a
direct reference to the src/test/java classes.

Modified:
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/TestRepository.java

Modified: 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=390668&r1=390667&r2=390668&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/TestRepository.java
(original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/TestRepository.java
Sat Apr  1 05:24:09 2006
@@ -17,10 +17,14 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Map;
 
+import javax.jcr.Credentials;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 
+import org.apache.commons.collections.BeanMap;
 import org.apache.jackrabbit.core.config.ConfigurationException;
 import org.apache.jackrabbit.core.config.RepositoryConfig;
 
@@ -71,11 +75,19 @@
     public static synchronized Repository getInstance() throws RepositoryException {
         try {
             if (instance == null) {
-                InputStream xml =
-                    TestRepository.class.getResourceAsStream(CONF_RESOURCE);
-                String home = System.getProperty(HOME_PROPERTY, HOME_DEFAULT);
-                RepositoryConfig config = RepositoryConfig.create(xml, home);
-                instance = new TransientRepository(config);
+                try {
+                    // Try to get the main test suite repository
+                    instance = getIntegratedInstance();
+                } catch (RepositoryException e) {
+                    throw e;
+                } catch (Exception e) {
+                    // Not running within the main test suite
+                    InputStream xml =
+                        TestRepository.class.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) {
@@ -85,6 +97,61 @@
             throw new RepositoryException(
                     "Error in test repository initialization", e);
         }
+    }
+
+    /**
+     * Attempts to retrieve the test repository instance used by the
+     * Jackrabbit main test suite without having a direct dependency to any
+     * of the classes in src/test/java. This method assumes that we are
+     * running within the Jackrabbit main test suite if the AbstractJCRTest
+     * class is available. The initialized RepositoryHelper instance is
+     * retrieved from the static "helper" field of the AbstractJCRTest class,
+     * and the underlying repository and configured superuser credentials are
+     * extracted from the helper instance. This information is in turn used
+     * to create a custom Repository adapter that delegates calls to the
+     * underlying repository and uses the superuser credentials for the login
+     * methods where no credentials are passed by the client.
+     *
+     * @return test repository instance
+     * @throws Exception if the test repository could not be retrieved
+     */
+    private static Repository getIntegratedInstance() throws Exception {
+        Class test =
+            Class.forName("org.apache.jackrabbit.test.AbstractJCRTest");
+        Map helper = new BeanMap(test.getField("helper").get(null));
+        final Credentials superuser =
+            (Credentials) helper.get("superuserCredentials");
+        final Repository repository =
+            (Repository) helper.get("repository");
+        return new Repository() {
+
+            public String[] getDescriptorKeys() {
+                return repository.getDescriptorKeys();
+            }
+
+            public String getDescriptor(String key) {
+                return repository.getDescriptor(key);
+            }
+
+            public Session login(Credentials credentials, String workspace)
+                    throws RepositoryException {
+                return repository.login(credentials, workspace);
+            }
+
+            public Session login(Credentials credentials)
+                    throws RepositoryException {
+                return repository.login(credentials);
+            }
+
+            public Session login(String workspace) throws RepositoryException {
+                return repository.login(superuser, workspace);
+            }
+
+            public Session login() throws RepositoryException {
+                return repository.login(superuser);
+            }
+
+        };
     }
 
     /**



Mime
View raw message