aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-batch/src/test/java')
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchSettingsTest.java116
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/BootstrapSettingsTest.java (renamed from sonar-batch/src/test/java/org/sonar/batch/config/BootstrapSettingsTest.java)24
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectModuleTest.java9
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectSettingsTest.java (renamed from sonar-batch/src/test/java/org/sonar/batch/config/ProjectSettingsTest.java)3
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/UnsupportedPropertiesTest.java (renamed from sonar-batch/src/test/java/org/sonar/batch/config/UnsupportedPropertiesTest.java)3
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/local/DryRunDatabaseTest.java8
6 files changed, 141 insertions, 22 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchSettingsTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchSettingsTest.java
new file mode 100644
index 00000000000..501a7dfbc8e
--- /dev/null
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchSettingsTest.java
@@ -0,0 +1,116 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 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.BaseConfiguration;
+import org.apache.commons.configuration.Configuration;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.api.config.PropertyDefinitions;
+
+import java.util.Map;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class BatchSettingsTest {
+
+ Configuration deprecatedConf;
+ ServerClient client;
+ ProjectDefinition project;
+ ProjectReactor reactor;
+ BootstrapSettings bootstrapSettings;
+
+ @Before
+ public void before() {
+ project = ProjectDefinition.create();
+ project.setKey("struts");
+ reactor = new ProjectReactor(project);
+ deprecatedConf = new BaseConfiguration();
+ client = mock(ServerClient.class);
+ when(client.request("/batch_bootstrap/properties?project=struts")).thenReturn(
+ "[{\"k\":\"sonar.cpd.cross\",\"v\":\"true\"}," +
+ "{\"k\":\"sonar.java.coveragePlugin\",\"v\":\"jacoco\",\"p\":\"struts\"}," +
+ "{\"k\":\"sonar.java.coveragePlugin\",\"v\":\"cobertura\",\"p\":\"struts-core\"}]"
+ );
+ bootstrapSettings = new BootstrapSettings(new PropertyDefinitions(), reactor, deprecatedConf);
+ }
+
+ @Test
+ public void should_load_system_props() {
+ System.setProperty("BatchSettingsTest.testSystemProp", "system");
+ BatchSettings batchSettings = new BatchSettings(bootstrapSettings, reactor, client, deprecatedConf);
+ assertThat(batchSettings.getString("BatchSettingsTest.testSystemProp")).isEqualTo("system");
+ }
+
+ @Test
+ public void should_load_build_props() {
+ project.setProperty("build.prop", "build");
+ BatchSettings batchSettings = new BatchSettings(bootstrapSettings, reactor, client, deprecatedConf);
+ assertThat(batchSettings.getString("build.prop")).isEqualTo("build");
+ }
+
+ @Test
+ public void should_load_global_settings() {
+ BatchSettings batchSettings = new BatchSettings(bootstrapSettings, reactor, client, deprecatedConf);
+ assertThat(batchSettings.getBoolean("sonar.cpd.cross")).isTrue();
+ }
+
+ @Test
+ public void should_load_project_root_settings() {
+ BatchSettings batchSettings = new BatchSettings(bootstrapSettings, reactor, client, deprecatedConf);
+ assertThat(batchSettings.getString("sonar.java.coveragePlugin")).isEqualTo("jacoco");
+ }
+
+ @Test
+ public void should_keep_module_settings_for_later() {
+ BatchSettings batchSettings = new BatchSettings(bootstrapSettings, reactor, client, deprecatedConf);
+ Map<String, String> moduleSettings = batchSettings.getModuleProperties("struts-core");
+ assertThat(moduleSettings).hasSize(1);
+ assertThat(moduleSettings.get("sonar.java.coveragePlugin")).isEqualTo("cobertura");
+ }
+
+ @Test
+ public void system_props_should_override_build_props() {
+ System.setProperty("BatchSettingsTest.testSystemProp", "system");
+ project.setProperty("BatchSettingsTest.testSystemProp", "build");
+ BatchSettings batchSettings = new BatchSettings(bootstrapSettings, reactor, client, deprecatedConf);
+ assertThat(batchSettings.getString("BatchSettingsTest.testSystemProp")).isEqualTo("system");
+ }
+
+ @Test
+ public void should_forward_to_deprecated_commons_configuration() {
+ BatchSettings batchSettings = new BatchSettings(bootstrapSettings, reactor, client, deprecatedConf);
+
+ assertThat(deprecatedConf.getString("sonar.cpd.cross")).isEqualTo("true");
+ assertThat(deprecatedConf.getString("sonar.java.coveragePlugin")).isEqualTo("jacoco");
+
+ batchSettings.removeProperty("sonar.cpd.cross");
+ assertThat(deprecatedConf.getString("sonar.cpd.cross")).isNull();
+ assertThat(deprecatedConf.getString("sonar.java.coveragePlugin")).isEqualTo("jacoco");
+
+ batchSettings.clear();
+ assertThat(deprecatedConf.getString("sonar.cpd.cross")).isNull();
+ assertThat(deprecatedConf.getString("sonar.java.coveragePlugin")).isNull();
+ }
+}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/config/BootstrapSettingsTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BootstrapSettingsTest.java
index 1d68dfa3cdc..df01592816b 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/config/BootstrapSettingsTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BootstrapSettingsTest.java
@@ -17,7 +17,7 @@
* 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.config;
+package org.sonar.batch.bootstrap;
import org.apache.commons.configuration.BaseConfiguration;
import org.junit.Test;
@@ -25,8 +25,7 @@ import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.config.PropertyDefinitions;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
public class BootstrapSettingsTest {
@@ -39,7 +38,7 @@ public class BootstrapSettingsTest {
ProjectReactor reactor = new ProjectReactor(project);
BootstrapSettings settings = new BootstrapSettings(new PropertyDefinitions(), reactor, new BaseConfiguration());
- assertThat(settings.getString("foo"), is("bar"));
+ assertThat(settings.getString("foo")).isEqualTo("bar");
}
@Test
@@ -51,18 +50,27 @@ public class BootstrapSettingsTest {
ProjectReactor reactor = new ProjectReactor(project);
BootstrapSettings settings = new BootstrapSettings(new PropertyDefinitions(), reactor, new BaseConfiguration());
- assertThat(settings.getString("BootstrapSettingsTest.testEnv"), is("env"));
+ assertThat(settings.getString("BootstrapSettingsTest.testEnv")).isEqualTo("env");
}
@Test
public void shouldForwardToCommonsConfiguration() {
ProjectDefinition project = ProjectDefinition.create();
+ project.setProperty("hello", "world");
project.setProperty("foo", "bar");
-
ProjectReactor reactor = new ProjectReactor(project);
BaseConfiguration deprecatedConfiguration = new BaseConfiguration();
- new BootstrapSettings(new PropertyDefinitions(), reactor, deprecatedConfiguration);
+ BootstrapSettings settings = new BootstrapSettings(new PropertyDefinitions(), reactor, deprecatedConfiguration);
+
+ assertThat(deprecatedConfiguration.getString("hello")).isEqualTo("world");
+ assertThat(deprecatedConfiguration.getString("foo")).isEqualTo("bar");
+
+ settings.removeProperty("foo");
+ assertThat(deprecatedConfiguration.getString("foo")).isNull();
+ assertThat(deprecatedConfiguration.getString("hello")).isEqualTo("world");
- assertThat(deprecatedConfiguration.getString("foo"), is("bar"));
+ settings.clear();
+ assertThat(deprecatedConfiguration.getString("foo")).isNull();
+ assertThat(deprecatedConfiguration.getString("hello")).isNull();
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectModuleTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectModuleTest.java
index adad9113158..df8e0f6a949 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectModuleTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectModuleTest.java
@@ -22,8 +22,6 @@ package org.sonar.batch.bootstrap;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.junit.Test;
import org.mockito.Matchers;
-import org.mockito.MockSettings;
-import org.mockito.Mockito;
import org.sonar.api.batch.InstantiationStrategy;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.database.model.Snapshot;
@@ -31,11 +29,7 @@ import org.sonar.api.platform.ComponentContainer;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.batch.ProjectTree;
-import org.sonar.batch.config.BootstrapSettings;
-import org.sonar.batch.config.ProjectSettings;
import org.sonar.batch.index.ResourcePersister;
-import org.sonar.core.properties.PropertiesDao;
-import org.sonar.wsclient.Sonar;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.any;
@@ -62,8 +56,7 @@ public class ProjectModuleTest {
container.addSingleton(extensionInstaller);
container.addSingleton(projectTree);
container.addSingleton(resourcePersister);
- container.addSingleton(mock(Sonar.class));
- container.addSingleton(mock(BootstrapSettings.class));
+ container.addSingleton(mock(BatchSettings.class));
}
};
diff --git a/sonar-batch/src/test/java/org/sonar/batch/config/ProjectSettingsTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectSettingsTest.java
index 753a09921a8..5798595a885 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/config/ProjectSettingsTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectSettingsTest.java
@@ -17,11 +17,12 @@
* 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.config;
+package org.sonar.batch.bootstrap;
import org.hamcrest.core.Is;
import org.junit.Test;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.batch.bootstrap.ProjectSettings;
import java.util.List;
diff --git a/sonar-batch/src/test/java/org/sonar/batch/config/UnsupportedPropertiesTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/UnsupportedPropertiesTest.java
index 6c042280b48..0b8d35d43f0 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/config/UnsupportedPropertiesTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/UnsupportedPropertiesTest.java
@@ -17,12 +17,13 @@
* 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.config;
+package org.sonar.batch.bootstrap;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.config.Settings;
+import org.sonar.batch.bootstrap.UnsupportedProperties;
public class UnsupportedPropertiesTest {
diff --git a/sonar-batch/src/test/java/org/sonar/batch/local/DryRunDatabaseTest.java b/sonar-batch/src/test/java/org/sonar/batch/local/DryRunDatabaseTest.java
index e2b3d27b816..e3cb4ce7fad 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/local/DryRunDatabaseTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/local/DryRunDatabaseTest.java
@@ -76,7 +76,7 @@ public class DryRunDatabaseTest {
dryRunDatabase.start();
- verify(server).download("/api/synchro?resource=group:project", databaseFile);
+ verify(server).download("/batch_bootstrap/db?project=group:project", databaseFile);
}
@Test
@@ -97,7 +97,7 @@ public class DryRunDatabaseTest {
public void should_fail_on_unknown_project() {
when(dryRun.isEnabled()).thenReturn(true);
when(tempDirectories.getFile("dry_run", "db.h2.db")).thenReturn(new File("/tmp/dry_run/db.h2.db"));
- doThrow(new SonarException(new FileNotFoundException())).when(server).download("/api/synchro?resource=group:project", new File("/tmp/dry_run/db.h2.db"));
+ doThrow(new SonarException(new FileNotFoundException())).when(server).download("/batch_bootstrap/db?project=group:project", new File("/tmp/dry_run/db.h2.db"));
thrown.expect(SonarException.class);
thrown.expectMessage("Project [group:project] doesn't exist on server");
@@ -109,7 +109,7 @@ public class DryRunDatabaseTest {
public void should_fail_on_invalid_role() {
when(dryRun.isEnabled()).thenReturn(true);
when(tempDirectories.getFile("dry_run", "db.h2.db")).thenReturn(new File("/tmp/dry_run/db.h2.db"));
- doThrow(new SonarException(new IOException("HTTP 401"))).when(server).download("/api/synchro?resource=group:project", new File("/tmp/dry_run/db.h2.db"));
+ doThrow(new SonarException(new IOException("HTTP 401"))).when(server).download("/batch_bootstrap/db?project=group:project", new File("/tmp/dry_run/db.h2.db"));
thrown.expect(SonarException.class);
thrown.expectMessage("You don't have access rights to project [group:project]");
@@ -121,7 +121,7 @@ public class DryRunDatabaseTest {
public void should_fail() {
when(dryRun.isEnabled()).thenReturn(true);
when(tempDirectories.getFile("dry_run", "db.h2.db")).thenReturn(new File("/tmp/dry_run/db.h2.db"));
- doThrow(new SonarException("BUG")).when(server).download("/api/synchro?resource=group:project", new File("/tmp/dry_run/db.h2.db"));
+ doThrow(new SonarException("BUG")).when(server).download("/batch_bootstrap/db?project=group:project", new File("/tmp/dry_run/db.h2.db"));
thrown.expect(SonarException.class);
thrown.expectMessage("BUG");