Search in sources :

Example 1 with ProxyRepository

use of org.apache.jackrabbit.commons.repository.ProxyRepository in project jackrabbit by apache.

the class TestRepository method getIntegratedInstance.

/**
     * 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 Repository repository = (Repository) helper.get("repository");
    final Credentials superuser = (Credentials) helper.get("superuserCredentials");
    return new ProxyRepository(new RepositoryFactory() {

        public Repository getRepository() throws RepositoryException {
            return repository;
        }
    }) {

        public Session login(String workspace) throws RepositoryException {
            return repository.login(superuser, workspace);
        }

        public Session login() throws RepositoryException {
            return repository.login(superuser);
        }
    };
}
Also used : BeanMap(org.apache.commons.collections.BeanMap) Repository(javax.jcr.Repository) ProxyRepository(org.apache.jackrabbit.commons.repository.ProxyRepository) ProxyRepository(org.apache.jackrabbit.commons.repository.ProxyRepository) RepositoryException(javax.jcr.RepositoryException) RepositoryFactory(org.apache.jackrabbit.commons.repository.RepositoryFactory) Map(java.util.Map) BeanMap(org.apache.commons.collections.BeanMap) Credentials(javax.jcr.Credentials)

Aggregations

Map (java.util.Map)1 Credentials (javax.jcr.Credentials)1 Repository (javax.jcr.Repository)1 RepositoryException (javax.jcr.RepositoryException)1 BeanMap (org.apache.commons.collections.BeanMap)1 ProxyRepository (org.apache.jackrabbit.commons.repository.ProxyRepository)1 RepositoryFactory (org.apache.jackrabbit.commons.repository.RepositoryFactory)1