From 1063d63ad0fef20b898376d4465e4c88cc061c1b Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 15 Jun 2011 10:55:55 +0200 Subject: SONAR-2505 core components which write to database are disabled on dry runs --- .../bootstrap/BatchExtensionInstallerTest.java | 6 +-- .../java/org/sonar/batch/bootstrap/DryRunTest.java | 45 ++++++++++++++++++++++ .../sonar/batch/bootstrap/ExtensionUtilsTest.java | 18 +++++++++ .../bootstrap/ProjectExtensionInstallerTest.java | 4 +- .../java/org/sonar/batch/phases/PhasesTest.java | 7 +++- 5 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 sonar-batch/src/test/java/org/sonar/batch/bootstrap/DryRunTest.java (limited to 'sonar-batch/src/test') 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())); } } -- cgit v1.2.3