3 * Copyright (C) 2009-2022 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.ce.task.projectanalysis.analysis;
22 import org.junit.Rule;
23 import org.junit.Test;
24 import org.sonar.api.config.Configuration;
25 import org.sonar.api.config.internal.MapSettings;
26 import org.sonar.ce.task.projectanalysis.component.DefaultBranchImpl;
27 import org.sonar.db.DbTester;
28 import org.sonar.db.component.ComponentDto;
30 import static org.assertj.core.api.Assertions.assertThat;
31 import static org.sonar.db.property.PropertyTesting.newComponentPropertyDto;
33 public class ProjectConfigurationFactoryTest {
35 private static final String PROJECT_KEY = "PROJECT_KEY";
38 public DbTester db = DbTester.create();
40 private MapSettings settings = new MapSettings();
42 private ProjectConfigurationFactory underTest = new ProjectConfigurationFactory(settings, db.getDbClient());
45 public void return_global_settings() {
46 settings.setProperty("key", "value");
47 Configuration config = underTest.newProjectConfiguration(PROJECT_KEY, new DefaultBranchImpl());
49 assertThat(config.get("key")).hasValue("value");
53 public void return_project_settings() {
54 ComponentDto project = db.components().insertPrivateProject();
55 db.properties().insertProperties(null, project.getKey(), project.name(), project.qualifier(),
56 newComponentPropertyDto(project).setKey("1").setValue("val1"),
57 newComponentPropertyDto(project).setKey("2").setValue("val2"),
58 newComponentPropertyDto(project).setKey("3").setValue("val3"));
60 Configuration config = underTest.newProjectConfiguration(project.getKey(), new DefaultBranchImpl());
62 assertThat(config.get("1")).hasValue("val1");
63 assertThat(config.get("2")).hasValue("val2");
64 assertThat(config.get("3")).hasValue("val3");
68 public void project_settings_override_global_settings() {
69 settings.setProperty("key", "value");
70 ComponentDto project = db.components().insertPrivateProject();
71 db.properties().insertProperties(null, project.getKey(), project.name(), project.qualifier(),
72 newComponentPropertyDto(project).setKey("key").setValue("value2"));
74 Configuration projectConfig = underTest.newProjectConfiguration(project.getKey(), new DefaultBranchImpl());
76 assertThat(projectConfig.get("key")).hasValue("value2");