]> source.dussan.org Git - sonarqube.git/commitdiff
Better error message when wrapper.conf is not correct
authorSimon Brandhof <simon.brandhof@gmail.com>
Wed, 23 Oct 2013 15:03:19 +0000 (17:03 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Wed, 23 Oct 2013 15:03:19 +0000 (17:03 +0200)
sonar-application/src/main/java/org/sonar/application/Env.java
sonar-application/src/test/java/org/sonar/application/EnvTest.java
sonar-application/src/test/java/org/sonar/application/StartServerTest.java

index 53f25a9b8d716eeb05c4a384a2499e1cdd5b81f3..168664f0d0a43cf2711e367b0771ff21ea8eef49 100644 (file)
@@ -24,17 +24,23 @@ import org.apache.commons.io.FileUtils;
 import java.io.File;
 import java.io.IOException;
 import java.net.URISyntaxException;
+import java.net.URL;
 
 class Env {
 
+  static final String ERROR_MESSAGE = "Do not copy-paste the configuration files (conf directory) from the old version. Update the content of the new files instead.";
   private final File confFile;
 
-  Env(File confFile) {
-    this.confFile = confFile;
+  // visible for testing
+  Env(URL confUrl) throws URISyntaxException {
+    if (confUrl == null) {
+      throw new IllegalStateException(ERROR_MESSAGE);
+    }
+    this.confFile = new File(confUrl.toURI());
   }
 
   Env() throws URISyntaxException {
-    this(new File(Env.class.getResource("/sonar.properties").toURI()));
+    this(Env.class.getResource("/sonar.properties"));
   }
 
   File rootDir() {
index 277498402971924a09acfbb4b4a84cbd5d9f1508..1400cc8f4ee0173de46e910e30ee2f32480c6f67 100644 (file)
@@ -27,6 +27,7 @@ import org.junit.rules.TemporaryFolder;
 import java.io.File;
 
 import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.fail;
 
 public class EnvTest {
 
@@ -48,7 +49,7 @@ public class EnvTest {
     FileUtils.touch(confFile);
     FileUtils.touch(logFile);
 
-    Env env = new Env(confFile);
+    Env env = new Env(confFile.toURL());
 
     assertThat(env.rootDir()).isDirectory().exists().isEqualTo(home);
     assertThat(env.file("conf/sonar.properties")).isFile().exists().isEqualTo(confFile);
@@ -65,7 +66,7 @@ public class EnvTest {
     FileUtils.touch(confFile);
     FileUtils.touch(logFile);
 
-    Env env = new Env(confFile);
+    Env env = new Env(confFile.toURL());
 
     File data = env.freshDir("data/h2");
     assertThat(data).isDirectory().exists();
@@ -80,7 +81,19 @@ public class EnvTest {
 
   @Test
   public void temp_dir_should_be_writable() throws Exception {
-    new Env(temp.newFile()).verifyWritableTempDir();
+    new Env(temp.newFile().toURL()).verifyWritableTempDir();
     // do not fail
   }
+
+  @Test
+  public void fail_if_conf_file_not_found() throws Exception {
+    try {
+      // note that "new Env(null)" would be exact, but let's
+      // keep "new Env()" for increasing code coverage :-)
+      new Env();
+      fail();
+    } catch (IllegalStateException e) {
+      assertThat(e).hasMessage(Env.ERROR_MESSAGE);
+    }
+  }
 }
index 1a7c9b7e76968b00cb83d68840debedb52273cc5..590385d939a013fcdc4fa6cc7c4db29bca68a1fe 100644 (file)
@@ -41,7 +41,7 @@ public class StartServerTest {
   public TemporaryFolder temp = new TemporaryFolder();
 
   @Before
-  public void prepare_app() throws IOException {
+  public void prepare_app() throws Exception {
     File confFile = new File("src/test/fake-app/conf/sonar.properties");
     if (!confFile.exists()) {
       confFile = new File("sonar-application/src/test/fake-app/conf/sonar.properties");
@@ -49,7 +49,7 @@ public class StartServerTest {
 
     File rootDir = temp.newFolder();
     FileUtils.copyDirectory(confFile.getParentFile().getParentFile(), rootDir);
-    env = new Env(new File(rootDir, "conf/sonar.properties"));
+    env = new Env(new File(rootDir, "conf/sonar.properties").toURL());
     starter = new StartServer(env);
   }