]> source.dussan.org Git - sonarqube.git/commitdiff
Improve tests
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 19 Aug 2015 08:49:32 +0000 (10:49 +0200)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 19 Aug 2015 08:50:06 +0000 (10:50 +0200)
it/it-tests/src/test/java/batch/IssuesModeTest.java
sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java
sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginInstallerTest.java

index bfd5e33d7ff930f8c671f5dc97867fac6df04a56..0e8ce19844074cbc147e2961629521bc9340eb71 100644 (file)
@@ -5,6 +5,8 @@
  */
 package batch;
 
+import com.sonar.orchestrator.build.BuildFailureException;
+
 import util.ItUtils;
 import com.google.common.collect.Maps;
 import com.sonar.orchestrator.Orchestrator;
@@ -26,7 +28,6 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
 
 import static org.junit.Assert.*;
-
 import static org.assertj.core.api.Assertions.assertThat;
 import org.apache.commons.lang.ObjectUtils;
 import org.json.simple.JSONArray;
@@ -73,6 +74,20 @@ public class IssuesModeTest {
     SonarRunner runner = configureRunnerIssues("shared/xoo-sample");
     orchestrator.executeBuild(runner);
   }
+  
+  @Test
+  public void invalidIncrementalMode() throws IOException {
+    restoreProfile("one-issue-per-line.xml");
+    orchestrator.getServer().provisionProject("sample", "xoo-sample");
+    orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
+    SonarRunner runner = configureRunner("shared/xoo-sample");
+    runner.setProperty("sonar.analysis.mode", "incremental");
+    
+    thrown.expect(BuildFailureException.class);
+    BuildResult res = orchestrator.executeBuild(runner);
+    
+    assertThat(res.getLogs()).contains("Invalid analysis mode: incremental. This mode was removed in SonarQube 5.2");
+  }
 
   // SONAR-5715
   @Test
index 35db83b844ade18bd141778844867250bf157b18..3fd9c588b695844c1fe8988c1ddd0baacf630507 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.batch.bootstrap;
 
 import org.sonar.batch.cache.WSLoaderResult;
-
 import org.sonar.batch.cache.WSLoader;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.Lists;
@@ -99,20 +98,7 @@ public class BatchPluginInstaller implements PluginInstaller {
   File download(final RemotePlugin remote) {
     try {
       final RemotePluginFile file = remote.file();
-      return fileCache.get(file.getFilename(), file.getHash(), new FileCache.Downloader() {
-        @Override
-        public void download(String filename, File toFile) throws IOException {
-          String url = "/deploy/plugins/" + remote.getKey() + "/" + file.getFilename();
-          if (LOG.isDebugEnabled()) {
-            LOG.debug("Download {} to {}", url, toFile.getAbsolutePath());
-          } else {
-            LOG.info("Download {}", file.getFilename());
-          }
-
-          serverClient.download(url, toFile);
-        }
-      });
-
+      return fileCache.get(file.getFilename(), file.getHash(), new FileDownloader(remote.getKey()));
     } catch (Exception e) {
       throw new IllegalStateException("Fail to download plugin: " + remote.getKey(), e);
     }
@@ -140,14 +126,27 @@ public class BatchPluginInstaller implements PluginInstaller {
   private String loadPluginIndex() {
     Profiler profiler = Profiler.create(LOG).startInfo("Load plugins index");
     WSLoaderResult<String> wsResult = wsLoader.loadString(PLUGINS_INDEX_URL);
+    profiler.stopInfo(wsResult.isFromCache());
+    return wsResult.get();
+  }
+
+  private class FileDownloader implements FileCache.Downloader {
+    private String key;
 
-    if (wsResult.isFromCache()) {
-      profiler.stopInfo("Load plugins index (done from cache)");
-    } else {
-      profiler.stopInfo();
+    FileDownloader(String key) {
+      this.key = key;
     }
 
-    return wsResult.get();
-  }
+    @Override
+    public void download(String filename, File toFile) throws IOException {
+      String url = "/deploy/plugins/" + key + "/" + filename;
+      if (LOG.isDebugEnabled()) {
+        LOG.debug("Download {} to {}", url, toFile.getAbsolutePath());
+      } else {
+        LOG.info("Download {}", filename);
+      }
 
+      serverClient.download(url, toFile);
+    }
+  }
 }
index c4f45c14b84ca84caf87afd1e2d23c2a928aee77..c663dbb3ef40f61b57394b8bfd95cf33d9475e38 100644 (file)
@@ -55,7 +55,6 @@ public class BatchPluginInstallerTest {
   public void listRemotePlugins() {
 
     WSLoader wsLoader = mock(WSLoader.class);
-    when(wsLoader.load("/deploy/plugins/index.txt")).thenReturn(new WSLoaderResult<byte[]>("checkstyle\nsqale".getBytes(), true));
     when(wsLoader.loadString("/deploy/plugins/index.txt")).thenReturn(new WSLoaderResult<String>("checkstyle\nsqale", true));
     BatchPluginInstaller installer = new BatchPluginInstaller(wsLoader, serverClient, fileCache, pluginPredicate);