Change to make BaseTest usable from a module
authorMartin Taal <martin.taal@openbravo.com>
Thu, 02 Jul 2009 17:45:44 +0200
changeset 4090 16f2ebad805f
parent 4089 dafdea02ffcf
child 4091 ea548cdfff91
Change to make BaseTest usable from a module
src-test/org/openbravo/test/base/BaseTest.java
--- a/src-test/org/openbravo/test/base/BaseTest.java	Thu Jul 02 17:25:21 2009 +0530
+++ b/src-test/org/openbravo/test/base/BaseTest.java	Thu Jul 02 17:45:44 2009 +0200
@@ -82,19 +82,26 @@
     // get the location of the current class file
     final URL url = this.getClass().getResource(getClass().getSimpleName() + ".class");
     File f = new File(url.getPath());
-    // go up 7 levels
-    for (int i = 0; i < 7; i++) {
+    File propertiesFile = null;
+    while (f.getParentFile() != null && f.getParentFile().exists()) {
       f = f.getParentFile();
+      final File configDirectory = new File(f, "config");
+      if (configDirectory.exists()) {
+        propertiesFile = new File(configDirectory, "Openbravo.properties");
+        if (propertiesFile.exists()) {
+          // found it and break
+          break;
+        }
+      }
     }
-    final File configDirectory = new File(f, "config");
-    f = new File(configDirectory, "Openbravo.properties");
-    if (!f.exists()) {
+    if (propertiesFile == null) {
       throw new OBException("The testrun assumes that it is run from "
           + "within eclipse and that the Openbravo.properties "
           + "file is located as a grandchild of the 7th ancestor " + "of this class");
     }
-    OBPropertiesProvider.getInstance().setProperties(f.getAbsolutePath());
-    OBConfigFileProvider.getInstance().setFileLocation(configDirectory.getAbsolutePath());
+    OBPropertiesProvider.getInstance().setProperties(propertiesFile.getAbsolutePath());
+    OBConfigFileProvider.getInstance().setFileLocation(
+        propertiesFile.getParentFile().getAbsolutePath());
   }
 
   /**