]> source.dussan.org Git - sonarqube.git/commitdiff
Integration tests : orchestrator.configUrl should support files
authorSimon Brandhof <simon.brandhof@gmail.com>
Wed, 28 Nov 2012 09:55:30 +0000 (10:55 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Wed, 28 Nov 2012 09:55:30 +0000 (10:55 +0100)
sonar-core/src/test/java/org/sonar/core/persistence/AbstractDaoTestCase.java

index a11e3ef5102924b3b6ebb96becae1b8feef0b8b8..95259c05a2b2c2156b5bcc35b94c39d72a958b03 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.core.persistence;
 
 import com.google.common.collect.Maps;
 import com.google.common.io.Closeables;
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.text.StrSubstitutor;
 import org.dbunit.Assertion;
@@ -45,6 +46,7 @@ import org.slf4j.LoggerFactory;
 import org.sonar.api.config.Settings;
 import org.sonar.core.config.Logback;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.HttpURLConnection;
@@ -94,15 +96,23 @@ public abstract class AbstractDaoTestCase {
   }
 
   private void loadOrchestratorSettings(Settings settings) throws URISyntaxException, IOException {
-    URI uri = new URI(settings.getString("orchestrator.configUrl"));
-    HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection();
-    int responseCode = connection.getResponseCode();
-    if (responseCode >= 400) {
-      throw new IllegalStateException("Fail to request: " + uri + ". Status code=" + responseCode);
-    }
-
-    InputStream input = connection.getInputStream();
+    String url = settings.getString("orchestrator.configUrl");
+    URI uri = new URI(url);
+    InputStream input = null;
     try {
+      if (url.startsWith("file:")) {
+        File file = new File(uri);
+        input = FileUtils.openInputStream(file);
+      } else {
+        HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection();
+        int responseCode = connection.getResponseCode();
+        if (responseCode >= 400) {
+          throw new IllegalStateException("Fail to request: " + uri + ". Status code=" + responseCode);
+        }
+
+        input = connection.getInputStream();
+
+      }
       Properties props = new Properties();
       props.load(input);
       settings.addProperties(props);
@@ -110,7 +120,6 @@ public abstract class AbstractDaoTestCase {
         String interpolatedValue = StrSubstitutor.replace(entry.getValue(), System.getenv(), "${", "}");
         settings.setProperty(entry.getKey(), interpolatedValue);
       }
-
     } finally {
       IOUtils.closeQuietly(input);
     }