From 61c699b1e625b31a202ed03244d72f7c022379ff Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Wed, 19 Aug 2015 10:49:32 +0200 Subject: [PATCH] Improve tests --- .../src/test/java/batch/IssuesModeTest.java | 17 +++++++- .../batch/bootstrap/BatchPluginInstaller.java | 41 +++++++++---------- .../bootstrap/BatchPluginInstallerTest.java | 1 - 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/it/it-tests/src/test/java/batch/IssuesModeTest.java b/it/it-tests/src/test/java/batch/IssuesModeTest.java index bfd5e33d7ff..0e8ce198440 100644 --- a/it/it-tests/src/test/java/batch/IssuesModeTest.java +++ b/it/it-tests/src/test/java/batch/IssuesModeTest.java @@ -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 diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java index 35db83b844a..3fd9c588b69 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginInstaller.java @@ -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 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); + } + } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginInstallerTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginInstallerTest.java index c4f45c14b84..c663dbb3ef4 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginInstallerTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginInstallerTest.java @@ -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("checkstyle\nsqale".getBytes(), true)); when(wsLoader.loadString("/deploy/plugins/index.txt")).thenReturn(new WSLoaderResult("checkstyle\nsqale", true)); BatchPluginInstaller installer = new BatchPluginInstaller(wsLoader, serverClient, fileCache, pluginPredicate); -- 2.39.5