use of org.apache.jackrabbit.commons.repository.RepositoryFactory 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);
}
};
}
Aggregations