aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/test/java/org/sonar
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-scanner-engine/src/test/java/org/sonar')
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalSettingsTest.java27
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java13
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/log/ExceptionHandlingMediumTest.java29
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/settings/DefaultSettingsLoaderTest.java63
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleSettingsTest.java4
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectSettingsTest.java4
6 files changed, 105 insertions, 35 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalSettingsTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalSettingsTest.java
index b4613a837b3..a3b68bacf73 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalSettingsTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalSettingsTest.java
@@ -19,8 +19,8 @@
*/
package org.sonar.scanner.bootstrap;
+import com.google.common.collect.ImmutableMap;
import java.util.Collections;
-
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -28,13 +28,11 @@ import org.junit.rules.ExpectedException;
import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
-import org.sonar.scanner.bootstrap.GlobalMode;
-import org.sonar.scanner.bootstrap.GlobalProperties;
-import org.sonar.scanner.bootstrap.GlobalSettings;
-import org.sonar.scanner.protocol.input.GlobalRepositories;
+import org.sonar.scanner.repository.settings.SettingsLoader;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class GlobalSettingsTest {
@@ -44,39 +42,38 @@ public class GlobalSettingsTest {
@Rule
public LogTester logTester = new LogTester();
- GlobalRepositories globalRef;
+ SettingsLoader settingsLoader;
GlobalProperties bootstrapProps;
private GlobalMode mode;
@Before
public void prepare() {
- globalRef = new GlobalRepositories();
+ settingsLoader = mock(SettingsLoader.class);
bootstrapProps = new GlobalProperties(Collections.<String, String>emptyMap());
mode = mock(GlobalMode.class);
}
@Test
public void should_load_global_settings() {
- globalRef.globalSettings().put("sonar.cpd.cross", "true");
+ when(settingsLoader.load(null)).thenReturn(ImmutableMap.of("sonar.cpd.cross", "true"));
- GlobalSettings batchSettings = new GlobalSettings(bootstrapProps, new PropertyDefinitions(), globalRef, mode);
+ GlobalSettings batchSettings = new GlobalSettings(bootstrapProps, new PropertyDefinitions(), settingsLoader, mode);
assertThat(batchSettings.getBoolean("sonar.cpd.cross")).isTrue();
}
@Test
public void should_log_warn_msg_for_each_jdbc_property_if_present() {
- globalRef.globalSettings().put("sonar.jdbc.url", SOME_VALUE);
- globalRef.globalSettings().put("sonar.jdbc.username", SOME_VALUE);
- globalRef.globalSettings().put("sonar.jdbc.password", SOME_VALUE);
+ when(settingsLoader.load(null)).thenReturn(ImmutableMap.of("sonar.jdbc.url", SOME_VALUE,
+ "sonar.jdbc.username", SOME_VALUE,
+ "sonar.jdbc.password", SOME_VALUE));
- new GlobalSettings(bootstrapProps, new PropertyDefinitions(), globalRef, mode);
+ new GlobalSettings(bootstrapProps, new PropertyDefinitions(), settingsLoader, mode);
assertThat(logTester.logs(LoggerLevel.WARN)).containsOnly(
"Property 'sonar.jdbc.url' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database.",
"Property 'sonar.jdbc.username' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database.",
- "Property 'sonar.jdbc.password' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database."
- );
+ "Property 'sonar.jdbc.password' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database.");
}
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java
index c64259117c0..e6b475f7515 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java
@@ -30,6 +30,7 @@ import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
@@ -62,6 +63,7 @@ import org.sonar.scanner.repository.ProjectRepositories;
import org.sonar.scanner.repository.ProjectRepositoriesLoader;
import org.sonar.scanner.repository.QualityProfileLoader;
import org.sonar.scanner.repository.ServerIssuesLoader;
+import org.sonar.scanner.repository.settings.SettingsLoader;
import org.sonar.scanner.rule.ActiveRulesLoader;
import org.sonar.scanner.rule.LoadedActiveRule;
import org.sonar.scanner.rule.RulesLoader;
@@ -283,7 +285,8 @@ public class ScannerMediumTester {
builder.rulesLoader,
builder.projectRefProvider,
builder.activeRules,
- new DefaultDebtModel())
+ new DefaultDebtModel(),
+ new FakeSettingsLoader())
.setBootstrapProperties(builder.bootstrapProperties)
.setLogOutput(builder.logOutput);
@@ -474,6 +477,14 @@ public class ScannerMediumTester {
}
}
+ private static class FakeSettingsLoader implements SettingsLoader {
+
+ @Override
+ public Map<String, String> load(String componentKey) {
+ return Collections.emptyMap();
+ }
+ }
+
private static class FakeServerLineHashesLoader implements ServerLineHashesLoader {
private Map<String, String[]> byKey = new HashMap<>();
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/log/ExceptionHandlingMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/log/ExceptionHandlingMediumTest.java
index f552f33f421..918ac2c1dd6 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/log/ExceptionHandlingMediumTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/log/ExceptionHandlingMediumTest.java
@@ -20,30 +20,29 @@
package org.sonar.scanner.mediumtest.log;
import java.util.Collections;
-
-import org.hamcrest.Matchers;
+import java.util.Map;
import org.hamcrest.Description;
+import org.hamcrest.Matchers;
import org.hamcrest.TypeSafeMatcher;
import org.junit.BeforeClass;
-import org.sonar.api.utils.MessageException;
-import org.sonar.batch.bootstrapper.Batch;
-import org.sonar.batch.bootstrapper.EnvironmentInformation;
-import org.sonar.scanner.protocol.input.GlobalRepositories;
-import org.sonar.scanner.repository.GlobalRepositoriesLoader;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.sonar.api.utils.MessageException;
+import org.sonar.batch.bootstrapper.Batch;
+import org.sonar.batch.bootstrapper.EnvironmentInformation;
+import org.sonar.scanner.repository.settings.SettingsLoader;
public class ExceptionHandlingMediumTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
private Batch batch;
- private static ErrorGlobalRepositoriesLoader loader;
+ private static ErrorSettingsLoader loader;
@BeforeClass
public static void beforeClass() {
- loader = new ErrorGlobalRepositoriesLoader();
+ loader = new ErrorSettingsLoader();
}
public void setUp(boolean verbose) {
@@ -64,7 +63,7 @@ public class ExceptionHandlingMediumTest {
setUp(false);
loader.withCause = false;
thrown.expect(MessageException.class);
- thrown.expectMessage("Error loading repository");
+ thrown.expectMessage("Error loading settings");
thrown.expectCause(Matchers.nullValue(Throwable.class));
batch.start();
@@ -76,7 +75,7 @@ public class ExceptionHandlingMediumTest {
loader.withCause = true;
thrown.expect(MessageException.class);
- thrown.expectMessage("Error loading repository");
+ thrown.expectMessage("Error loading settings");
thrown.expectCause(new TypeSafeMatcher<Throwable>() {
@Override
public void describeTo(Description description) {
@@ -99,16 +98,16 @@ public class ExceptionHandlingMediumTest {
batch.start();
}
- private static class ErrorGlobalRepositoriesLoader implements GlobalRepositoriesLoader {
+ private static class ErrorSettingsLoader implements SettingsLoader {
boolean withCause = false;
@Override
- public GlobalRepositories load() {
+ public Map<String, String> load(String componentKey) {
if (withCause) {
IllegalStateException cause = new IllegalStateException("Code 401");
- throw MessageException.of("Error loading repository", cause);
+ throw MessageException.of("Error loading settings", cause);
} else {
- throw MessageException.of("Error loading repository");
+ throw MessageException.of("Error loading settings");
}
}
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/settings/DefaultSettingsLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/settings/DefaultSettingsLoaderTest.java
new file mode 100644
index 00000000000..8f9be5cf33d
--- /dev/null
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/settings/DefaultSettingsLoaderTest.java
@@ -0,0 +1,63 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.scanner.repository.settings;
+
+import org.junit.Test;
+import org.sonarqube.ws.Settings.FieldValues;
+import org.sonarqube.ws.Settings.FieldValues.Value;
+import org.sonarqube.ws.Settings.FieldValues.Value.Builder;
+import org.sonarqube.ws.Settings.Setting;
+import org.sonarqube.ws.Settings.Values;
+
+import static java.util.Arrays.asList;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.entry;
+
+public class DefaultSettingsLoaderTest {
+
+ @Test
+ public void should_load_global_multivalue_settings() {
+ assertThat(DefaultSettingsLoader.toMap(asList(Setting.newBuilder()
+ .setKey("sonar.preview.supportedPlugins")
+ .setValues(Values.newBuilder().addValues("java").addValues("php")).build())))
+ .containsExactly(entry("sonar.preview.supportedPlugins", "java,php"));
+ }
+
+ @Test
+ public void should_load_global_propertyset_settings() {
+ Builder valuesBuilder = Value.newBuilder();
+ valuesBuilder.getMutableValue().put("filepattern", "**/*.xml");
+ valuesBuilder.getMutableValue().put("rulepattern", "*:S12345");
+ Value value1 = valuesBuilder.build();
+ valuesBuilder.clear();
+ valuesBuilder.getMutableValue().put("filepattern", "**/*.java");
+ valuesBuilder.getMutableValue().put("rulepattern", "*:S456");
+ Value value2 = valuesBuilder.build();
+
+ assertThat(DefaultSettingsLoader.toMap(asList(Setting.newBuilder()
+ .setKey("sonar.issue.exclusions.multicriteria")
+ .setFieldValues(FieldValues.newBuilder().addFieldValues(value1).addFieldValues(value2)).build())))
+ .containsOnly(entry("sonar.issue.exclusions.multicriteria", "1,2"),
+ entry("sonar.issue.exclusions.multicriteria.1.filepattern", "**/*.xml"),
+ entry("sonar.issue.exclusions.multicriteria.1.rulepattern", "*:S12345"),
+ entry("sonar.issue.exclusions.multicriteria.2.filepattern", "**/*.java"),
+ entry("sonar.issue.exclusions.multicriteria.2.rulepattern", "*:S456"));
+ }
+}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleSettingsTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleSettingsTest.java
index f779b0d80f4..034bf4304a7 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleSettingsTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ModuleSettingsTest.java
@@ -36,10 +36,10 @@ import org.sonar.scanner.analysis.DefaultAnalysisMode;
import org.sonar.scanner.bootstrap.GlobalMode;
import org.sonar.scanner.bootstrap.GlobalProperties;
import org.sonar.scanner.bootstrap.GlobalSettings;
-import org.sonar.scanner.protocol.input.GlobalRepositories;
import org.sonar.scanner.report.AnalysisContextReportPublisher;
import org.sonar.scanner.repository.FileData;
import org.sonar.scanner.repository.ProjectRepositories;
+import org.sonar.scanner.repository.settings.SettingsLoader;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@@ -157,6 +157,6 @@ public class ModuleSettingsTest {
private GlobalSettings newGlobalSettings(Map<String, String> props) {
GlobalProperties globalProps = new GlobalProperties(props);
return new GlobalSettings(globalProps, new PropertyDefinitions(),
- new GlobalRepositories(), new GlobalMode(globalProps));
+ mock(SettingsLoader.class), new GlobalMode(globalProps));
}
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectSettingsTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectSettingsTest.java
index 5b889fb1340..6ec64aab7ed 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectSettingsTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectSettingsTest.java
@@ -37,9 +37,9 @@ import org.sonar.scanner.analysis.DefaultAnalysisMode;
import org.sonar.scanner.bootstrap.GlobalMode;
import org.sonar.scanner.bootstrap.GlobalProperties;
import org.sonar.scanner.bootstrap.GlobalSettings;
-import org.sonar.scanner.protocol.input.GlobalRepositories;
import org.sonar.scanner.repository.FileData;
import org.sonar.scanner.repository.ProjectRepositories;
+import org.sonar.scanner.repository.settings.SettingsLoader;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@@ -68,7 +68,7 @@ public class ProjectSettingsTest {
project = ProjectDefinition.create().setKey("struts");
globalMode = mock(GlobalMode.class);
mode = mock(DefaultAnalysisMode.class);
- bootstrapProps = new GlobalSettings(new GlobalProperties(Collections.<String, String>emptyMap()), new PropertyDefinitions(), new GlobalRepositories(), globalMode);
+ bootstrapProps = new GlobalSettings(new GlobalProperties(Collections.<String, String>emptyMap()), new PropertyDefinitions(), mock(SettingsLoader.class), globalMode);
}
@Test