diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2012-11-28 10:55:30 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2012-11-28 10:55:30 +0100 |
commit | 504455bb04ac0e9c752d48a5b3d4ff11f9158a7a (patch) | |
tree | d5eb993a3a749a98e7d98aadeba0d9bd873804ee /sonar-core | |
parent | 4fad8c5ae31af65bd9bed9f5d849205dbb786965 (diff) | |
download | sonarqube-504455bb04ac0e9c752d48a5b3d4ff11f9158a7a.tar.gz sonarqube-504455bb04ac0e9c752d48a5b3d4ff11f9158a7a.zip |
Integration tests : orchestrator.configUrl should support files
Diffstat (limited to 'sonar-core')
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/persistence/AbstractDaoTestCase.java | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/AbstractDaoTestCase.java b/sonar-core/src/test/java/org/sonar/core/persistence/AbstractDaoTestCase.java index a11e3ef5102..95259c05a2b 100644 --- a/sonar-core/src/test/java/org/sonar/core/persistence/AbstractDaoTestCase.java +++ b/sonar-core/src/test/java/org/sonar/core/persistence/AbstractDaoTestCase.java @@ -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); } |