3 * Copyright (C) 2009-2021 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.scanner.repository.settings;
22 import org.junit.Test;
23 import org.sonarqube.ws.Settings.FieldValues;
24 import org.sonarqube.ws.Settings.FieldValues.Value;
25 import org.sonarqube.ws.Settings.FieldValues.Value.Builder;
26 import org.sonarqube.ws.Settings.Setting;
27 import org.sonarqube.ws.Settings.Values;
29 import static java.util.Collections.singletonList;
30 import static org.assertj.core.api.Assertions.assertThat;
31 import static org.assertj.core.api.Assertions.entry;
33 public class AbstractSettingsLoaderTest {
36 public void should_load_global_multivalue_settings() {
37 assertThat(AbstractSettingsLoader.toMap(singletonList(Setting.newBuilder()
38 .setKey("sonar.preview.supportedPlugins")
39 .setValues(Values.newBuilder().addValues("java").addValues("php")).build())))
40 .containsExactly(entry("sonar.preview.supportedPlugins", "java,php"));
44 public void should_escape_global_multivalue_settings() {
45 assertThat(AbstractSettingsLoader.toMap(singletonList(Setting.newBuilder()
46 .setKey("sonar.preview.supportedPlugins")
47 .setValues(Values.newBuilder().addValues("ja,va").addValues("p\"hp")).build())))
48 .containsExactly(entry("sonar.preview.supportedPlugins", "\"ja,va\",\"p\"\"hp\""));
52 public void should_load_global_propertyset_settings() {
53 Builder valuesBuilder = Value.newBuilder();
54 valuesBuilder.putValue("filepattern", "**/*.xml");
55 valuesBuilder.putValue("rulepattern", "*:S12345");
56 Value value1 = valuesBuilder.build();
57 valuesBuilder.clear();
58 valuesBuilder.putValue("filepattern", "**/*.java");
59 valuesBuilder.putValue("rulepattern", "*:S456");
60 Value value2 = valuesBuilder.build();
62 assertThat(AbstractSettingsLoader.toMap(singletonList(Setting.newBuilder()
63 .setKey("sonar.issue.exclusions.multicriteria")
64 .setFieldValues(FieldValues.newBuilder().addFieldValues(value1).addFieldValues(value2)).build())))
65 .containsOnly(entry("sonar.issue.exclusions.multicriteria", "1,2"),
66 entry("sonar.issue.exclusions.multicriteria.1.filepattern", "**/*.xml"),
67 entry("sonar.issue.exclusions.multicriteria.1.rulepattern", "*:S12345"),
68 entry("sonar.issue.exclusions.multicriteria.2.filepattern", "**/*.java"),
69 entry("sonar.issue.exclusions.multicriteria.2.rulepattern", "*:S456"));