From commits-return-2171-apmail-jackrabbit-commits-archive=jackrabbit.apache.org@jackrabbit.apache.org Sat Apr 01 13:24:32 2006 Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 85418 invoked from network); 1 Apr 2006 13:24:32 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 1 Apr 2006 13:24:32 -0000 Received: (qmail 54799 invoked by uid 500); 1 Apr 2006 13:24:32 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 54702 invoked by uid 500); 1 Apr 2006 13:24:31 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 54693 invoked by uid 99); 1 Apr 2006 13:24:31 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Apr 2006 05:24:31 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Sat, 01 Apr 2006 05:24:31 -0800 Received: (qmail 84326 invoked by uid 65534); 1 Apr 2006 13:24:10 -0000 Message-ID: <20060401132410.84325.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r390668 - /jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/TestRepository.java Date: Sat, 01 Apr 2006 13:24:10 -0000 To: commits@jackrabbit.apache.org From: jukka@apache.org X-Mailer: svnmailer-1.0.7 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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); + } + + }; } /**