Search in sources :

Example 41 with Configuration

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

the class ProjectConfigurationLoaderImplTest method return_configuration_with_global_settings_and_component_settings.

@Test
public void return_configuration_with_global_settings_and_component_settings() {
    String globalKey = randomAlphanumeric(3);
    String globalValue = randomAlphanumeric(4);
    String componentDbKey = randomAlphanumeric(5);
    String componentUuid = randomAlphanumeric(6);
    String projectPropKey1 = randomAlphanumeric(7);
    String projectPropValue1 = randomAlphanumeric(8);
    String projectPropKey2 = randomAlphanumeric(9);
    String projectPropValue2 = randomAlphanumeric(10);
    globalSettings.setProperty(globalKey, globalValue);
    when(propertiesDao.selectProjectProperties(dbSession, componentDbKey)).thenReturn(ImmutableList.of(newPropertyDto(projectPropKey1, projectPropValue1), newPropertyDto(projectPropKey2, projectPropValue2)));
    ComponentDto component = newComponentDto(componentDbKey, componentUuid);
    Map<String, Configuration> configurations = underTest.loadProjectConfigurations(dbSession, singleton(component));
    assertThat(configurations).containsOnlyKeys(componentUuid);
    assertThat(configurations.get(componentUuid).get(globalKey)).contains(globalValue);
    assertThat(configurations.get(componentUuid).get(projectPropKey1)).contains(projectPropValue1);
    assertThat(configurations.get(componentUuid).get(projectPropKey2)).contains(projectPropValue2);
}
Also used : Configuration(org.sonar.api.config.Configuration) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 42 with Configuration

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

the class ProjectConfigurationLoaderImplTest method return_configuration_with_global_settings_main_branch_settings_and_branch_settings.

@Test
public void return_configuration_with_global_settings_main_branch_settings_and_branch_settings() {
    String globalKey = randomAlphanumeric(3);
    String globalValue = randomAlphanumeric(4);
    String mainBranchDbKey = randomAlphanumeric(5);
    String branchDbKey = mainBranchDbKey + ComponentDto.BRANCH_KEY_SEPARATOR + randomAlphabetic(5);
    String branchUuid = randomAlphanumeric(6);
    String mainBranchPropKey = randomAlphanumeric(7);
    String mainBranchPropValue = randomAlphanumeric(8);
    String branchPropKey = randomAlphanumeric(9);
    String branchPropValue = randomAlphanumeric(10);
    globalSettings.setProperty(globalKey, globalValue);
    when(propertiesDao.selectProjectProperties(dbSession, mainBranchDbKey)).thenReturn(ImmutableList.of(newPropertyDto(mainBranchPropKey, mainBranchPropValue)));
    when(propertiesDao.selectProjectProperties(dbSession, branchDbKey)).thenReturn(ImmutableList.of(newPropertyDto(branchPropKey, branchPropValue)));
    ComponentDto component = newComponentDto(branchDbKey, branchUuid);
    Map<String, Configuration> configurations = underTest.loadProjectConfigurations(dbSession, singleton(component));
    assertThat(configurations).containsOnlyKeys(branchUuid);
    assertThat(configurations.get(branchUuid).get(globalKey)).contains(globalValue);
    assertThat(configurations.get(branchUuid).get(mainBranchPropKey)).contains(mainBranchPropValue);
    assertThat(configurations.get(branchUuid).get(branchPropKey)).contains(branchPropValue);
}
Also used : Configuration(org.sonar.api.config.Configuration) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 43 with Configuration

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

the class ComponentIssuesLoaderTest method loadClosedIssues_returns_only_closed_with_close_date_is_from_30_days_ago_if_property_is_not_an_integer.

@Test
@UseDataProvider("notAnIntegerPropertyValues")
public void loadClosedIssues_returns_only_closed_with_close_date_is_from_30_days_ago_if_property_is_not_an_integer(String notAnInteger) {
    Configuration configuration = newConfiguration(notAnInteger);
    ComponentIssuesLoader underTest = newComponentIssuesLoader(configuration);
    loadClosedIssues_returns_only_closed_issues_with_close_date_is_from_30_days_ago(underTest);
}
Also used : Configuration(org.sonar.api.config.Configuration) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 44 with Configuration

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

the class ComponentIssuesLoaderTest method loadClosedIssues_returns_only_closed_with_close_date_is_from_30_days_ago_if_property_is_less_than_0.

@Test
public void loadClosedIssues_returns_only_closed_with_close_date_is_from_30_days_ago_if_property_is_less_than_0() {
    Configuration configuration = newConfiguration(String.valueOf(-(1 + new Random().nextInt(10))));
    ComponentIssuesLoader underTest = newComponentIssuesLoader(configuration);
    loadClosedIssues_returns_only_closed_issues_with_close_date_is_from_30_days_ago(underTest);
}
Also used : Configuration(org.sonar.api.config.Configuration) Random(java.util.Random) Test(org.junit.Test)

Example 45 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)

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