Search in sources :

Example 46 with Configuration

use of org.sonar.api.config.Configuration in project sonarqube by SonarSource.

the class DefaultConfigurationTest method accessingMultiValuedPropertiesShouldBeConsistentWithDeclaration.

@Test
public void accessingMultiValuedPropertiesShouldBeConsistentWithDeclaration() {
    Configuration config = new DefaultConfiguration(new PropertyDefinitions(System2.INSTANCE, Arrays.asList(PropertyDefinition.builder("single").multiValues(false).build(), PropertyDefinition.builder("multiA").multiValues(true).build())), new Encryption(null), ImmutableMap.of("single", "foo", "multiA", "a,b", "notDeclared", "c,d")) {
    };
    assertThat(config.get("multiA")).hasValue("a,b");
    assertThat(logTester.logs(LoggerLevel.WARN)).contains("Access to the multi-values/property set property 'multiA' should be made using 'getStringArray' method. The SonarQube plugin using this property should be updated.");
    logTester.clear();
    assertThat(config.getStringArray("single")).containsExactly("foo");
    assertThat(logTester.logs(LoggerLevel.WARN)).contains("Property 'single' is not declared as multi-values/property set but was read using 'getStringArray' method. The SonarQube plugin declaring this property should be updated.");
    logTester.clear();
    assertThat(config.get("notDeclared")).hasValue("c,d");
    assertThat(config.getStringArray("notDeclared")).containsExactly("c", "d");
    assertThat(logTester.logs(LoggerLevel.WARN)).isEmpty();
}
Also used : Configuration(org.sonar.api.config.Configuration) PropertyDefinitions(org.sonar.api.config.PropertyDefinitions) Encryption(org.sonar.api.config.internal.Encryption) Test(org.junit.Test)

Example 47 with Configuration

use of org.sonar.api.config.Configuration in project sonarqube by SonarSource.

the class ProjectBuilderTest method shouldChangeProject.

@Test
public void shouldChangeProject() {
    // this reactor is created and provided by Sonar
    final ProjectReactor projectReactor = new ProjectReactor(ProjectDefinition.create());
    ProjectBuilder builder = new ProjectBuilderSample();
    final MapSettings settings = new MapSettings();
    settings.setProperty("foo", "bar");
    final Configuration configuration = settings.asConfig();
    builder.build(new ProjectBuilderContext(projectReactor, configuration));
    assertThat(projectReactor.getProjects().size(), is(2));
    ProjectDefinition root = projectReactor.getRoot();
    assertThat(root.getName(), is("Name changed by plugin"));
    assertThat(root.getSubProjects().size(), is(1));
    assertThat(root.getSubProjects().get(0).sources()).contains("src");
}
Also used : ProjectBuilderContext(org.sonar.api.batch.bootstrap.internal.ProjectBuilderContext) MapSettings(org.sonar.api.config.internal.MapSettings) Configuration(org.sonar.api.config.Configuration) Test(org.junit.Test)

Aggregations

Configuration (org.sonar.api.config.Configuration)47 Test (org.junit.Test)40 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)14 ComponentDto (org.sonar.db.component.ComponentDto)12 QGChangeEvent (org.sonar.server.qualitygate.changeevent.QGChangeEvent)7 MapSettings (org.sonar.api.config.internal.MapSettings)5 SnapshotDto (org.sonar.db.component.SnapshotDto)4 PropertyDefinitions (org.sonar.api.config.PropertyDefinitions)3 Encryption (org.sonar.api.config.internal.Encryption)3 Metric (org.sonar.api.measures.Metric)3 DefaultBranchImpl (org.sonar.ce.task.projectanalysis.component.DefaultBranchImpl)3 HashSet (java.util.HashSet)2 DbClient (org.sonar.db.DbClient)2 BranchDto (org.sonar.db.component.BranchDto)2 LiveMeasureDto (org.sonar.db.measure.LiveMeasureDto)2 MetricDto (org.sonar.db.metric.MetricDto)2 ProjectDto (org.sonar.db.project.ProjectDto)2 EvaluatedQualityGate (org.sonar.server.qualitygate.EvaluatedQualityGate)2 QualityGate (org.sonar.server.qualitygate.QualityGate)2 File (java.io.File)1