Author: mreutegg
Date: Tue Jan 18 06:25:08 2005
New Revision: 125509
URL: http://svn.apache.org/viewcvs?view=rev&rev=125509
Log:
Extended helper and stub classes to support multiple instantiation. stub now also supports configuration on the api level.
Modified:
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/RepositoryHelper.java
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/RepositoryStub.java
Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/RepositoryHelper.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/RepositoryHelper.java?view=diff&rev=125509&p1=incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/RepositoryHelper.java&r1=125508&p2=incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/RepositoryHelper.java&r2=125509
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/RepositoryHelper.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/RepositoryHelper.java Tue Jan 18 06:25:08 2005
@@ -19,6 +19,8 @@
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import java.util.Map;
+import java.util.HashMap;
/**
* Utility class to get access to {@link javax.jcr.Session} instances.
@@ -26,14 +28,43 @@
public class RepositoryHelper {
/**
+ * Repository stub reference.
+ */
+ private RepositoryStub repoStub;
+
+ /**
+ * Overlay configuration.
+ */
+ private Map configuration = new HashMap();
+
+ /**
+ * Creates a repository helper with configuration from
+ * repositoryStubImpl.properties file.
+ */
+ public RepositoryHelper() {
+ }
+
+ /**
+ * Creates a repository helper with additional configuration parameters.
+ *
+ * @param config configuration which overlays the values from the property
+ * file.
+ */
+ public RepositoryHelper(Map config) {
+ configuration.putAll(config);
+ }
+
+ /**
* Returns the repository instance to test.
* @return the repository instance to test.
* @throws RepositoryException if the repository could not be obtained.
*/
public Repository getRepository() throws RepositoryException {
try {
- RepositoryStub repStub = RepositoryStub.getInstance();
- return repStub.getRepository();
+ if (repoStub == null) {
+ repoStub = RepositoryStub.getInstance(configuration);
+ }
+ return repoStub.getRepository();
} catch (RepositoryStubException e) {
throw new RepositoryException("Failed to get Repository instance.", e);
}
@@ -58,12 +89,7 @@
* @throws RepositoryException if login to the repository failed.
*/
public Session getSuperuserSession(String workspaceName) throws RepositoryException {
- try {
- RepositoryStub repStub = RepositoryStub.getInstance();
- return repStub.getRepository().login(repStub.getSuperuserCredentials(), workspaceName);
- } catch (RepositoryStubException e) {
- throw new RepositoryException("Failed to login to Repository.", e);
- }
+ return getRepository().login(repoStub.getSuperuserCredentials(), workspaceName);
}
/**
@@ -83,12 +109,7 @@
* @throws RepositoryException if login to the repository failed.
*/
public Session getReadWriteSession(String workspaceName) throws RepositoryException {
- try {
- RepositoryStub repStub = RepositoryStub.getInstance();
- return repStub.getRepository().login(repStub.getReadWriteCredentials(), workspaceName);
- } catch (RepositoryStubException e) {
- throw new RepositoryException("Failed to login to Repository.", e);
- }
+ return getRepository().login(repoStub.getReadWriteCredentials(), workspaceName);
}
/**
@@ -108,12 +129,7 @@
* @throws RepositoryException if login to the repository failed.
*/
public Session getReadOnlySession(String workspaceName) throws RepositoryException {
- try {
- RepositoryStub repStub = RepositoryStub.getInstance();
- return repStub.getRepository().login(repStub.getReadOnlyCredentials(), workspaceName);
- } catch (RepositoryStubException e) {
- throw new RepositoryException("Failed to login to Repository.", e);
- }
+ return getRepository().login(repoStub.getReadOnlyCredentials(), workspaceName);
}
/**
@@ -129,10 +145,8 @@
* @throws RepositoryException if the configuration file cannot be found.
*/
public String getProperty(String name) throws RepositoryException {
- try {
- return RepositoryStub.getInstance().getProperty(name);
- } catch (RepositoryStubException e) {
- throw new RepositoryException("Failed to obtain Repository instance.", e);
- }
+ // force assignment of repoStub
+ getRepository();
+ return repoStub.getProperty(name);
}
}
Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/RepositoryStub.java
Url: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/RepositoryStub.java?view=diff&rev=125509&p1=incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/RepositoryStub.java&r1=125508&p2=incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/RepositoryStub.java&r2=125509
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/RepositoryStub.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/RepositoryStub.java Tue Jan 18 06:25:08 2005
@@ -26,6 +26,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Properties;
+import java.util.Map;
/**
* The RepositoryStub is the entry point to the JCR Repository
@@ -68,8 +69,6 @@
public static final String PROP_WORKSPACE_NAME = "workspacename";
- protected static RepositoryStub instance;
-
protected final Properties environment;
protected SimpleCredentials superuser;
@@ -107,36 +106,37 @@
*
-Djavax.jcr.tck.properties is
* not set, then the TCK tries to load the file repositoryStubImpl.properties
* as a resource from the ClassLoader of this RepositryStub class.configuration map.
*
+ * @param configuration a Map of additional configuration entries.
* @return a RepositoryStub implementation.
* @throws RepositoryStubException
*/
- public static synchronized RepositoryStub getInstance() throws RepositoryStubException {
- if (instance == null) {
- Properties props = null;
- String implProp = System.getProperty(STUB_IMPL_SYS_PROPS);
- if (implProp != null) {
- File implPropFile = new File(implProp);
- if (implPropFile.exists()) {
- props = new Properties();
- try {
- props.load(new FileInputStream(implPropFile));
- } catch (IOException e) {
- throw new RepositoryStubException("Unable to load config file: "
- + implProp + " " + e.toString());
- }
- } else {
- throw new RepositoryStubException("File does not exist: " + implProp);
+ static synchronized RepositoryStub getInstance(Map configuration)
+ throws RepositoryStubException {
+ Properties props = null;
+ RepositoryStub stub = null;
+ String implProp = System.getProperty(STUB_IMPL_SYS_PROPS);
+ if (implProp != null) {
+ File implPropFile = new File(implProp);
+ if (implPropFile.exists()) {
+ props = new Properties();
+ try {
+ props.load(new FileInputStream(implPropFile));
+ } catch (IOException e) {
+ throw new RepositoryStubException("Unable to load config file: "
+ + implProp + " " + e.toString());
}
+ } else {
+ throw new RepositoryStubException("File does not exist: " + implProp);
}
+ }
- if (props == null) {
- InputStream is = RepositoryStub.class.getClassLoader().getResourceAsStream(STUB_IMPL_PROPS);
- if (is == null) {
- throw new RepositoryStubException(STUB_IMPL_PROPS + " not found in classpath!");
- }
+ if (props == null) {
+ InputStream is = RepositoryStub.class.getClassLoader().getResourceAsStream(STUB_IMPL_PROPS);
+ if (is != null) {
try {
props = new Properties();
props.load(is);
@@ -145,30 +145,34 @@
+ STUB_IMPL_PROPS + ": " + e.toString());
}
}
+ }
- try {
- String className = props.getProperty(PROP_STUB_IMPL_CLASS);
- if (className == null || className.length() == 0) {
- throw new RepositoryStubException("Property " + PROP_STUB_IMPL_CLASS + " not defined!");
- }
- Class stubClass = Class.forName(className);
- Constructor constr = stubClass.getConstructor(new Class[]{Properties.class});
- instance = (RepositoryStub) constr.newInstance(new Object[]{props});
- } catch (ClassCastException e) {
- throw new RepositoryStubException(e.toString());
- } catch (NoSuchMethodException e) {
- throw new RepositoryStubException(e.toString());
- } catch (ClassNotFoundException e) {
- throw new RepositoryStubException(e.toString());
- } catch (InstantiationException e) {
- throw new RepositoryStubException(e.toString());
- } catch (IllegalAccessException e) {
- throw new RepositoryStubException(e.toString());
- } catch (InvocationTargetException e) {
- throw new RepositoryStubException(e.toString());
+ // overlay with configuration parameter
+ props.putAll(configuration);
+
+ try {
+ String className = props.getProperty(PROP_STUB_IMPL_CLASS);
+ if (className == null || className.length() == 0) {
+ throw new RepositoryStubException("Property " + PROP_STUB_IMPL_CLASS + " not defined!");
}
+ Class stubClass = Class.forName(className);
+ Constructor constr = stubClass.getConstructor(new Class[]{Properties.class});
+ stub = (RepositoryStub) constr.newInstance(new Object[]{props});
+ } catch (ClassCastException e) {
+ throw new RepositoryStubException(e.toString());
+ } catch (NoSuchMethodException e) {
+ throw new RepositoryStubException(e.toString());
+ } catch (ClassNotFoundException e) {
+ throw new RepositoryStubException(e.toString());
+ } catch (InstantiationException e) {
+ throw new RepositoryStubException(e.toString());
+ } catch (IllegalAccessException e) {
+ throw new RepositoryStubException(e.toString());
+ } catch (InvocationTargetException e) {
+ throw new RepositoryStubException(e.toString());
}
- return instance;
+
+ return stub;
}
/**