diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2011-06-15 10:55:55 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2011-06-15 10:56:24 +0200 |
commit | 1063d63ad0fef20b898376d4465e4c88cc061c1b (patch) | |
tree | e02735640b26715c8aae7396e3cf3e0cba3e93e4 /sonar-batch/src/test | |
parent | eb3c0dc7dec66ad446e41a8291836af352bbc819 (diff) | |
download | sonarqube-1063d63ad0fef20b898376d4465e4c88cc061c1b.tar.gz sonarqube-1063d63ad0fef20b898376d4465e4c88cc061c1b.zip |
SONAR-2505 core components which write to database are disabled on dry runs
Diffstat (limited to 'sonar-batch/src/test')
5 files changed, 74 insertions, 6 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java index 4f81bd34294..10c19e6d415 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java @@ -45,7 +45,7 @@ public class BatchExtensionInstallerTest { } })); Module module = new FakeModule().init(); - BatchExtensionInstaller installer = new BatchExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7")); + BatchExtensionInstaller installer = new BatchExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new DryRun(false)); installer.install(module); @@ -63,7 +63,7 @@ public class BatchExtensionInstallerTest { } })); Module module = new FakeModule().init(); - BatchExtensionInstaller installer = new BatchExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7")); + BatchExtensionInstaller installer = new BatchExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new DryRun(false)); installer.install(module); @@ -82,7 +82,7 @@ public class BatchExtensionInstallerTest { } })); Module module = new FakeModule().init(); - BatchExtensionInstaller installer = new BatchExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7")); + BatchExtensionInstaller installer = new BatchExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new DryRun(false)); installer.install(module); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DryRunTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DryRunTest.java new file mode 100644 index 00000000000..5b278b0285d --- /dev/null +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DryRunTest.java @@ -0,0 +1,45 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar 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. + * + * Sonar 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 Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.batch.bootstrap; + +import org.apache.commons.configuration.PropertiesConfiguration; +import org.hamcrest.core.Is; +import org.junit.Test; + +import static org.junit.Assert.assertThat; + +public class DryRunTest { + + @Test + public void shouldReadConfiguration() { + PropertiesConfiguration conf = new PropertiesConfiguration(); + conf.setProperty("sonar.dryRun", "true"); + assertThat(new DryRun(conf).isEnabled(), Is.is(true)); + + conf.setProperty("sonar.dryRun", "false"); + assertThat(new DryRun(conf).isEnabled(), Is.is(false)); + } + + @Test + public void shouldNotEnableDryRunByDefault() { + PropertiesConfiguration conf = new PropertiesConfiguration(); + assertThat(new DryRun(conf).isEnabled(), Is.is(false)); + } +} diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java index 2e6abe8621c..23cc30d560a 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java @@ -25,6 +25,7 @@ import org.sonar.api.ServerExtension; import org.sonar.api.batch.InstantiationStrategy; import org.sonar.api.batch.SupportedEnvironment; import org.sonar.batch.bootstrapper.EnvironmentInformation; +import org.sonar.core.NotDryRun; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; @@ -75,6 +76,18 @@ public class ExtensionUtilsTest { assertThat(ExtensionUtils.isMavenExtensionOnly(BuildToolService.class), is(false)); } + @Test + public void shouldCheckDryRun() { + assertThat(ExtensionUtils.checkDryRun(BatchService.class, true), is(true)); + assertThat(ExtensionUtils.checkDryRun(PersistentService.class, true), is(false)); + } + + @Test + public void shouldNotCheckDryRun() { + assertThat(ExtensionUtils.checkDryRun(BatchService.class, false), is(true)); + assertThat(ExtensionUtils.checkDryRun(PersistentService.class, false), is(true)); + } + @InstantiationStrategy(InstantiationStrategy.PER_BATCH) public static class BatchService implements BatchExtension { @@ -102,4 +115,9 @@ public class ExtensionUtilsTest { public static class BuildToolService implements BatchExtension { } + + @NotDryRun + public static class PersistentService implements BatchExtension { + + } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java index b8020422a15..9e9fcd60fa6 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java @@ -66,7 +66,7 @@ public class ProjectExtensionInstallerTest { }); when(pluginRepository.getPluginsByKey()).thenReturn(pluginsMap); Module module = new FakeModule().init(); - ProjectExtensionInstaller installer = new ProjectExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7")); + ProjectExtensionInstaller installer = new ProjectExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new DryRun(false)); installer.install(module, new Project("foo")); @@ -86,7 +86,7 @@ public class ProjectExtensionInstallerTest { }); when(pluginRepository.getPluginsByKey()).thenReturn(pluginsMap); Module module = new FakeModule().init(); - ProjectExtensionInstaller installer = new ProjectExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7")); + ProjectExtensionInstaller installer = new ProjectExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new DryRun(false)); installer.install(module, new Project("foo")); diff --git a/sonar-batch/src/test/java/org/sonar/batch/phases/PhasesTest.java b/sonar-batch/src/test/java/org/sonar/batch/phases/PhasesTest.java index d14d30d7ae4..ae8a6d0b962 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/phases/PhasesTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/phases/PhasesTest.java @@ -28,6 +28,11 @@ public class PhasesTest { @Test public void shouldDefinePhaseClasses() { - assertThat(Phases.getPhaseClasses().size(), greaterThan(4)); + assertThat(Phases.getPhaseClasses(false).size(), greaterThan(4)); + } + + @Test + public void someComponentsShouldBeDisabledOnDryRun() { + assertThat(Phases.getPhaseClasses(false).size(), greaterThan(Phases.getPhaseClasses(true).size())); } } |