diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-05-06 22:08:31 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-05-11 10:24:03 +0200 |
commit | 1b0e00bd132798475390145f52ab429ddb8c301c (patch) | |
tree | cc5a16f6dec34b8da1e182ee9ff6de3cd3c07ecd /sonar-batch/src/test/java/org/sonar | |
parent | 53b12f3331f7985de42b1917965d3cae8aa71a15 (diff) | |
download | sonarqube-1b0e00bd132798475390145f52ab429ddb8c301c.tar.gz sonarqube-1b0e00bd132798475390145f52ab429ddb8c301c.zip |
SONAR-6517 apply feedback
Diffstat (limited to 'sonar-batch/src/test/java/org/sonar')
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginExploderTest.java (renamed from sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginUnzipperTest.java) | 20 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginPredicateTest.java | 13 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java | 291 |
3 files changed, 76 insertions, 248 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginUnzipperTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginExploderTest.java index 06a25148775..3d080e35d82 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginUnzipperTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginExploderTest.java @@ -25,7 +25,7 @@ import org.junit.ClassRule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.core.platform.PluginInfo; -import org.sonar.core.platform.UnzippedPlugin; +import org.sonar.core.platform.ExplodedPlugin; import org.sonar.home.cache.FileCache; import org.sonar.home.cache.FileCacheBuilder; @@ -34,29 +34,29 @@ import java.io.IOException; import static org.assertj.core.api.Assertions.assertThat; -public class BatchPluginUnzipperTest { +public class BatchPluginExploderTest { @ClassRule public static TemporaryFolder temp = new TemporaryFolder(); File userHome; - BatchPluginUnzipper underTest; + BatchPluginExploder underTest; @Before public void setUp() throws IOException { userHome = temp.newFolder(); FileCache fileCache = new FileCacheBuilder().setUserHome(userHome).build(); - underTest = new BatchPluginUnzipper(fileCache); + underTest = new BatchPluginExploder(fileCache); } @Test public void copy_and_extract_libs() throws IOException { File fileFromCache = getFileFromCache("sonar-checkstyle-plugin-2.8.jar"); - UnzippedPlugin unzipped = underTest.unzip(PluginInfo.create(fileFromCache)); + ExplodedPlugin exploded = underTest.explode(PluginInfo.create(fileFromCache)); - assertThat(unzipped.getKey()).isEqualTo("checkstyle"); - assertThat(unzipped.getMain()).isFile().exists(); - assertThat(unzipped.getLibs()).extracting("name").containsOnly("antlr-2.7.6.jar", "checkstyle-5.1.jar", "commons-cli-1.0.jar"); + assertThat(exploded.getKey()).isEqualTo("checkstyle"); + assertThat(exploded.getMain()).isFile().exists(); + assertThat(exploded.getLibs()).extracting("name").containsOnly("antlr-2.7.6.jar", "checkstyle-5.1.jar", "commons-cli-1.0.jar"); assertThat(new File(fileFromCache.getParent(), "sonar-checkstyle-plugin-2.8.jar")).exists(); assertThat(new File(fileFromCache.getParent(), "sonar-checkstyle-plugin-2.8.jar_unzip/META-INF/lib/checkstyle-5.1.jar")).exists(); } @@ -64,7 +64,7 @@ public class BatchPluginUnzipperTest { @Test public void extract_only_libs() throws IOException { File fileFromCache = getFileFromCache("sonar-checkstyle-plugin-2.8.jar"); - underTest.unzip(PluginInfo.create(fileFromCache)); + underTest.explode(PluginInfo.create(fileFromCache)); assertThat(new File(fileFromCache.getParent(), "sonar-checkstyle-plugin-2.8.jar")).exists(); assertThat(new File(fileFromCache.getParent(), "sonar-checkstyle-plugin-2.8.jar_unzip/META-INF/MANIFEST.MF")).doesNotExist(); @@ -72,7 +72,7 @@ public class BatchPluginUnzipperTest { } File getFileFromCache(String filename) throws IOException { - File src = FileUtils.toFile(BatchPluginUnzipperTest.class.getResource("/org/sonar/batch/bootstrap/BatchPluginUnzipperTest/" + filename)); + File src = FileUtils.toFile(BatchPluginExploderTest.class.getResource("/org/sonar/batch/bootstrap/BatchPluginUnzipperTest/" + filename)); File destFile = new File(new File(userHome, "" + filename.hashCode()), filename); FileUtils.copyFile(src, destFile); return destFile; diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginPredicateTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginPredicateTest.java index 95d9f18eb4c..57176404845 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginPredicateTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginPredicateTest.java @@ -67,7 +67,7 @@ public class BatchPluginPredicateTest { } @Test - public void accept_core_plugin_even_if_in_exclusions() { + public void accept_core_plugin_even_if_declared_in_exclusions() { when(mode.isPreview()).thenReturn(true); settings.setProperty(CoreProperties.PREVIEW_EXCLUDE_PLUGINS, "core,findbugs"); BatchPluginPredicate predicate = new BatchPluginPredicate(settings, mode); @@ -75,7 +75,7 @@ public class BatchPluginPredicateTest { } @Test - public void both_inclusions_and_exclusions() { + public void verify_both_inclusions_and_exclusions() { when(mode.isPreview()).thenReturn(true); settings .setProperty(CoreProperties.PREVIEW_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs") @@ -87,7 +87,7 @@ public class BatchPluginPredicateTest { } @Test - public void only_exclusions() { + public void test_exclusions_without_any_inclusions() { when(mode.isPreview()).thenReturn(true); settings.setProperty(CoreProperties.PREVIEW_EXCLUDE_PLUGINS, "checkstyle,pmd,findbugs"); BatchPluginPredicate predicate = new BatchPluginPredicate(settings, mode); @@ -96,8 +96,13 @@ public class BatchPluginPredicateTest { assertThat(predicate.apply("cobertura")).isTrue(); } + /** + * The properties sonar.dryRun.includePlugins and sonar.dryRun.excludePlugins + * are deprecated. They are replaced by sonar.preview.includePlugins and + * sonar.preview.excludePlugins. + */ @Test - public void deprecated_dry_run_settings() { + public void support_deprecated_dry_run_settings() { when(mode.isPreview()).thenReturn(true); settings .setProperty(CoreProperties.DRY_RUN_INCLUDE_PLUGINS, "cockpit") diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java index 7c82edbb64f..cafee2bebf2 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java @@ -17,237 +17,60 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -///* -// * SonarQube, open source software quality management tool. -// * Copyright (C) 2008-2014 SonarSource -// * mailto:contact AT sonarsource DOT com -// * -// * SonarQube is free software; you can redistribute it and/or -// * modify it under the terms of the GNU Lesser General Public -// * License as published by the Free Software Foundation; either -// * version 3 of the License, or (at your option) any later version. -// * -// * SonarQube is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// * Lesser General Public License for more details. -// * -// * You should have received a copy of the GNU Lesser General Public License -// * along with this program; if not, write to the Free Software Foundation, -// * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -// */ -//package org.sonar.batch.bootstrap; -// -//import com.google.common.io.Resources; -//import org.apache.commons.io.FileUtils; -//import org.junit.After; -//import org.junit.Before; -//import org.junit.Rule; -//import org.junit.Test; -//import org.junit.rules.TemporaryFolder; -//import org.sonar.api.CoreProperties; -//import org.sonar.api.config.Settings; -//import org.sonar.core.plugins.RemotePlugin; -//import org.sonar.home.cache.FileCache; -//import org.sonar.home.cache.FileCacheBuilder; -// -//import java.io.File; -//import java.io.IOException; -//import java.util.Arrays; -// -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.when; -// -//public class BatchPluginRepositoryTest { -// -// @Rule -// public TemporaryFolder temp = new TemporaryFolder(); -// -// private BatchPluginRepository repository; -// private DefaultAnalysisMode mode; -// private FileCache cache; -// private File userHome; -// -// @Before -// public void before() throws IOException { -// mode = mock(DefaultAnalysisMode.class); -// when(mode.isPreview()).thenReturn(false); -// userHome = temp.newFolder(); -// cache = new FileCacheBuilder().setUserHome(userHome).build(); -// } -// -// @After -// public void tearDown() { -// if (repository != null) { -// repository.stop(); -// } -// } -// -// @Test -// public void shouldLoadPlugin() throws Exception { -// RemotePlugin checkstyle = new RemotePlugin("checkstyle", true); -// -// DefaultPluginRepository installer = mock(DefaultPluginsRepository.class); -// when(installer.pluginFile(checkstyle)).thenReturn(fileFromCache("sonar-checkstyle-plugin-2.8.jar")); -// -// repository = new BatchPluginRepository(installer, new Settings(), mode, new BatchPluginJarInstaller(cache)); -// -// repository.doStart(Arrays.asList(checkstyle)); -// -// assertThat(repository.getPlugin("checkstyle")).isNotNull(); -// assertThat(repository.getMetadata()).hasSize(1); -// assertThat(repository.getMetadata("checkstyle").getName()).isEqualTo("Checkstyle"); -// assertThat(repository.getMetadata("checkstyle").getDeployedFiles()).hasSize(4); // plugin + 3 dependencies -// } -// -// @Test -// public void shouldLoadPluginExtension() throws Exception { -// RemotePlugin checkstyle = new RemotePlugin("checkstyle", true); -// RemotePlugin checkstyleExt = new RemotePlugin("checkstyleextensions", false); -// -// DefaultPluginsRepository downloader = mock(DefaultPluginsRepository.class); -// when(downloader.pluginFile(checkstyle)).thenReturn(fileFromCache("sonar-checkstyle-plugin-2.8.jar")); -// when(downloader.pluginFile(checkstyleExt)).thenReturn(fileFromCache("sonar-checkstyle-extensions-plugin-0.1-SNAPSHOT.jar")); -// -// repository = new BatchPluginRepository(downloader, new Settings(), mode, new BatchPluginJarInstaller(cache)); -// -// repository.doStart(Arrays.asList(checkstyle, checkstyleExt)); -// -// assertThat(repository.getPlugin("checkstyle")).isNotNull(); -// assertThat(repository.getPlugin("checkstyleextensions")).isNotNull(); -// assertThat(repository.getMetadata()).hasSize(2); -// assertThat(repository.getMetadata("checkstyle").getName()).isEqualTo("Checkstyle"); -// assertThat(repository.getMetadata("checkstyleextensions").getVersion()).isEqualTo("0.1-SNAPSHOT"); -// } -// -// @Test -// public void shouldExcludePluginAndItsExtensions() throws Exception { -// RemotePlugin checkstyle = new RemotePlugin("checkstyle", true); -// RemotePlugin checkstyleExt = new RemotePlugin("checkstyleextensions", false); -// -// DefaultPluginsRepository downloader = mock(DefaultPluginsRepository.class); -// when(downloader.pluginFile(checkstyle)).thenReturn(fileFromCache("sonar-checkstyle-plugin-2.8.jar")); -// when(downloader.pluginFile(checkstyleExt)).thenReturn(fileFromCache("sonar-checkstyle-extensions-plugin-0.1-SNAPSHOT.jar")); -// -// Settings settings = new Settings(); -// settings.setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "checkstyle"); -// repository = new BatchPluginRepository(downloader, settings, mode, new BatchPluginJarInstaller(cache)); -// -// repository.doStart(Arrays.asList(checkstyle, checkstyleExt)); -// -// assertThat(repository.getMetadata()).isEmpty(); -// } -// -// private File fileFromCache(String filename) throws Exception { -// File file = new File(Resources.getResource("org/sonar/batch/bootstrap/BatchPluginRepositoryTest/" + filename).toURI()); -// File destDir = new File(userHome, "cache/foomd5"); -// FileUtils.forceMkdir(destDir); -// FileUtils.copyFileToDirectory(file, destDir); -// return new File(destDir, filename); -// } -// -// @Test -// public void shouldAlwaysAcceptIfNoWhiteListAndBlackList() { -// BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(new Settings(), mode); -// assertThat(filter.accepts("pmd")).isTrue(); -// assertThat(filter.accepts("buildbreaker")).isTrue(); -// } -// -// @Test -// public void shouldBlackListBuildBreakerInPreviewMode() { -// when(mode.isPreview()).thenReturn(true); -// BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(new Settings(), mode); -// assertThat(filter.accepts("buildbreaker")).isFalse(); -// } -// -// @Test -// public void whiteListShouldTakePrecedenceOverBlackList() { -// Settings settings = new Settings() -// .setProperty(CoreProperties.BATCH_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs") -// .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "cobertura,pmd"); -// BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings, mode); -// assertThat(filter.accepts("pmd")).isTrue(); -// } -// -// @Test -// public void corePluginShouldAlwaysBeInWhiteList() { -// Settings settings = new Settings() -// .setProperty(CoreProperties.BATCH_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs"); -// BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings, mode); -// assertThat(filter.accepts("core")).isTrue(); -// } -// -// @Test -// public void corePluginShouldNeverBeInBlackList() { -// Settings settings = new Settings() -// .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "core,findbugs"); -// BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings, mode); -// assertThat(filter.accepts("core")).isTrue(); -// } -// -// @Test -// public void check_white_list_with_black_list() { -// Settings settings = new Settings() -// .setProperty(CoreProperties.BATCH_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs") -// .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "cobertura"); -// BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings, mode); -// assertThat(filter.accepts("checkstyle")).isTrue(); -// assertThat(filter.accepts("pmd")).isTrue(); -// assertThat(filter.accepts("cobertura")).isFalse(); -// } -// -// @Test -// public void check_white_list_when_plugin_is_in_both_list() { -// Settings settings = new Settings() -// .setProperty(CoreProperties.BATCH_INCLUDE_PLUGINS, "cobertura,checkstyle,pmd,findbugs") -// .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "cobertura"); -// BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings, mode); -// assertThat(filter.accepts("checkstyle")).isTrue(); -// assertThat(filter.accepts("pmd")).isTrue(); -// assertThat(filter.accepts("cobertura")).isTrue(); -// } -// -// @Test -// public void check_black_list_if_no_white_list() { -// Settings settings = new Settings() -// .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "checkstyle,pmd,findbugs"); -// BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings, mode); -// assertThat(filter.accepts("checkstyle")).isFalse(); -// assertThat(filter.accepts("pmd")).isFalse(); -// assertThat(filter.accepts("cobertura")).isTrue(); -// } -// -// @Test -// public void should_concatenate_preview_filters() { -// Settings settings = new Settings() -// .setProperty(CoreProperties.PREVIEW_INCLUDE_PLUGINS, "cockpit") -// .setProperty(CoreProperties.PREVIEW_EXCLUDE_PLUGINS, "views") -// .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "checkstyle,pmd"); -// when(mode.isPreview()).thenReturn(true); -// BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings, mode); -// assertThat(filter.whites).containsOnly("cockpit"); -// assertThat(filter.blacks).containsOnly("views", "checkstyle", "pmd"); -// } -// -// @Test -// public void should_concatenate_deprecated_dry_run_filters() { -// Settings settings = new Settings() -// .setProperty(CoreProperties.DRY_RUN_INCLUDE_PLUGINS, "cockpit") -// .setProperty(CoreProperties.DRY_RUN_EXCLUDE_PLUGINS, "views") -// .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "checkstyle,pmd"); -// when(mode.isPreview()).thenReturn(true); -// BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings, mode); -// assertThat(filter.whites).containsOnly("cockpit"); -// assertThat(filter.blacks).containsOnly("views", "checkstyle", "pmd"); -// } -// -// @Test -// public void inclusions_and_exclusions_should_be_trimmed() { -// Settings settings = new Settings() -// .setProperty(CoreProperties.BATCH_INCLUDE_PLUGINS, "checkstyle, pmd, findbugs") -// .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "cobertura, pmd"); -// BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings, mode); -// assertThat(filter.accepts("pmd")).isTrue(); -// } -// -//} +package org.sonar.batch.bootstrap; + +import com.google.common.collect.ImmutableMap; +import org.junit.Test; +import org.sonar.api.Plugin; +import org.sonar.core.platform.PluginInfo; +import org.sonar.core.platform.PluginLoader; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.anyCollectionOf; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class BatchPluginRepositoryTest { + + PluginInstaller installer = mock(PluginInstaller.class); + PluginLoader loader = mock(PluginLoader.class); + BatchPluginRepository underTest = new BatchPluginRepository(installer, loader); + + @Test + public void install_and_load_plugins() throws Exception { + PluginInfo info = new PluginInfo("squid"); + ImmutableMap<String, PluginInfo> infos = ImmutableMap.of("squid", info); + Plugin instance = mock(Plugin.class); + when(loader.load(infos)).thenReturn(ImmutableMap.of("squid", instance)); + when(installer.installRemotes()).thenReturn(infos); + + underTest.start(); + + assertThat(underTest.getPluginInfos()).containsOnly(info); + assertThat(underTest.getPluginInfo("squid")).isSameAs(info); + assertThat(underTest.getPluginInstance("squid")).isSameAs(instance); + + underTest.stop(); + verify(loader).unload(anyCollectionOf(Plugin.class)); + } + + @Test + public void fail_if_requesting_missing_plugin() throws Exception { + underTest.start(); + + try { + underTest.getPluginInfo("unknown"); + fail(); + } catch (IllegalStateException e) { + assertThat(e).hasMessage("Plugin [unknown] does not exist"); + } + try { + underTest.getPluginInstance("unknown"); + fail(); + } catch (IllegalStateException e) { + assertThat(e).hasMessage("Plugin [unknown] does not exist"); + } + } +} |