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.assertThatThrownBy;
32 import static org.assertj.core.api.Assertions.entry;
34 public class AbstractSettingsLoaderTest {
37 public void should_load_global_multivalue_settings() {
38 assertThat(AbstractSettingsLoader.toMap(singletonList(Setting.newBuilder()
39 .setKey("sonar.preview.supportedPlugins")
40 .setValues(Values.newBuilder().addValues("java").addValues("php")).build())))
41 .containsExactly(entry("sonar.preview.supportedPlugins", "java,php"));
45 public void should_escape_global_multivalue_settings() {
46 assertThat(AbstractSettingsLoader.toMap(singletonList(Setting.newBuilder()
47 .setKey("sonar.preview.supportedPlugins")
48 .setValues(Values.newBuilder().addValues("ja,va").addValues("p\"hp")).build())))
49 .containsExactly(entry("sonar.preview.supportedPlugins", "\"ja,va\",\"p\"\"hp\""));
53 public void should_throw_exception_when_no_value_of_non_secured_settings() {
54 assertThatThrownBy(() -> AbstractSettingsLoader.toMap(singletonList(Setting.newBuilder()
55 .setKey("sonar.open.setting").build())))
56 .isInstanceOf(IllegalStateException.class)
57 .hasMessage("Unknown property value for sonar.open.setting");
61 public void should_filter_secured_settings_without_value() {
62 assertThat(AbstractSettingsLoader.toMap(singletonList(Setting.newBuilder()
63 .setKey("sonar.setting.secured").build())))
68 public void should_load_global_propertyset_settings() {
69 Builder valuesBuilder = Value.newBuilder();
70 valuesBuilder.putValue("filepattern", "**/*.xml");
71 valuesBuilder.putValue("rulepattern", "*:S12345");
72 Value value1 = valuesBuilder.build();
73 valuesBuilder.clear();
74 valuesBuilder.putValue("filepattern", "**/*.java");
75 valuesBuilder.putValue("rulepattern", "*:S456");
76 Value value2 = valuesBuilder.build();
78 assertThat(AbstractSettingsLoader.toMap(singletonList(Setting.newBuilder()
79 .setKey("sonar.issue.exclusions.multicriteria")
80 .setFieldValues(FieldValues.newBuilder().addFieldValues(value1).addFieldValues(value2)).build())))
81 .containsOnly(entry("sonar.issue.exclusions.multicriteria", "1,2"),
82 entry("sonar.issue.exclusions.multicriteria.1.filepattern", "**/*.xml"),
83 entry("sonar.issue.exclusions.multicriteria.1.rulepattern", "*:S12345"),
84 entry("sonar.issue.exclusions.multicriteria.2.filepattern", "**/*.java"),
85 entry("sonar.issue.exclusions.multicriteria.2.rulepattern", "*:S456"));