You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by js...@apache.org on 2007/09/25 10:53:01 UTC
svn commit: r579129 -
/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/JBIContainer.java
Author: jstrachan
Date: Tue Sep 25 01:52:59 2007
New Revision: 579129
URL: http://svn.apache.org/viewvc?rev=579129&view=rev
Log:
provide the ability to auto-generate the rootDir for working in integration junit test cases
Modified:
incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/JBIContainer.java
Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/JBIContainer.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/JBIContainer.java?rev=579129&r1=579128&r2=579129&view=diff
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/JBIContainer.java (original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/JBIContainer.java Tue Sep 25 01:52:59 2007
@@ -119,7 +119,9 @@
private InitialContext namingContext;
private MBeanServer mbeanServer;
private TransactionManager transactionManager;
- private String rootDir = "." + File.separator + "rootDir";
+ private String rootDir;
+ private String generatedRootDirPrefix = "target/rootDirs/rootDir";
+ private boolean generateRootDir;
private AtomicBoolean started = new AtomicBoolean(false);
private AtomicBoolean containerInitialized = new AtomicBoolean(false);
private IdGenerator idGenerator = new IdGenerator();
@@ -517,6 +519,43 @@
return clientFactory;
}
+ public String getGeneratedRootDirPrefix() {
+ return generatedRootDirPrefix;
+ }
+
+ /**
+ * Sets the prefix used when auto-creating a rootDir property value
+ * which is useful for integration testing inside JUnit test cases
+ * letting each test case create its own empty servicemix install
+ *
+ * @param generatedRootDirPrefix the prefix used to auto-create the
+ * rootDir
+ * @see #setRootDir(String)
+ * @see #setGeneratedRootDirPrefix(String)
+ */
+ public void setGeneratedRootDirPrefix(String generatedRootDirPrefix) {
+ this.generatedRootDirPrefix = generatedRootDirPrefix;
+ }
+
+ public boolean isGenerateRootDir() {
+ return generateRootDir;
+ }
+
+ /**
+ * Creates an auto-generated rootDir which is useful for integration testing
+ * in JUnit test cases allowing installations of deployments inside an empty
+ * installation of ServiceMix
+ *
+ * @param generateRootDir if true this will enable the auto-generation of the rootDir
+ * if the rootDir property is not configured
+ *
+ * @see #setRootDir(String)
+ * @see #setGeneratedRootDirPrefix(String)
+ */
+ public void setGenerateRootDir(boolean generateRootDir) {
+ this.generateRootDir = generateRootDir;
+ }
+
/**
* light weight initialization - default values for mbeanServer, TransactionManager etc are null
*
@@ -544,7 +583,7 @@
}
managementContext.init(this, getMBeanServer());
mbeanServer = this.managementContext.getMBeanServer(); // just in case ManagementContext creates it
- environmentContext.init(this, rootDir);
+ environmentContext.init(this, getRootDir());
clientFactory.init(this);
if (services != null) {
for (int i = 0; i < services.length; i++) {
@@ -758,9 +797,18 @@
* @return the root directory path
*/
public synchronized String getRootDir() {
+ if (rootDir == null) {
+ if (isGenerateRootDir()) {
+ rootDir = createRootDir();
+ } else {
+ rootDir = "." + File.separator + "rootDir";
+ }
+ LOG.debug("Defaulting to rootDir: " + rootDir);
+ }
return this.rootDir;
}
+
/**
* Set the workspace root
*
@@ -1317,4 +1365,18 @@
this.executorFactory = executorFactory;
}
+
+ /**
+ * Creates a new rootDir
+ */
+ protected String createRootDir() {
+ String prefix = getGeneratedRootDirPrefix();
+ for (int i = 1; true; i++) {
+ File file = new File(prefix + i);
+ if (!file.exists()) {
+ file.mkdirs();
+ return file.getAbsolutePath();
+ }
+ }
+ }
}