Search in sources :

Example 31 with Configuration

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

the class WebhookQGChangeEventListenerTest method onIssueChanges_calls_webhook_on_main_branch.

@Test
@UseDataProvider("newQGorNot")
public void onIssueChanges_calls_webhook_on_main_branch(@Nullable EvaluatedQualityGate newQualityGate) {
    ProjectAndBranch mainBranch = insertMainBranch();
    SnapshotDto analysis = insertAnalysisTask(mainBranch);
    Configuration configuration = mock(Configuration.class);
    QGChangeEvent qualityGateEvent = newQGChangeEvent(mainBranch, analysis, configuration, newQualityGate);
    mockWebhookEnabled(qualityGateEvent.getProject());
    underTest.onIssueChanges(qualityGateEvent, CHANGED_ISSUES_ARE_IGNORED);
    verifyWebhookCalled(mainBranch, analysis, qualityGateEvent.getProject());
}
Also used : Configuration(org.sonar.api.config.Configuration) SnapshotDto(org.sonar.db.component.SnapshotDto) QGChangeEvent(org.sonar.server.qualitygate.changeevent.QGChangeEvent) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 32 with Configuration

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

the class IndexDefinitionHashTest method hash_changes_if_number_of_shards_changes.

@Test
public void hash_changes_if_number_of_shards_changes() {
    Index index = Index.simple("foo");
    IndexMainType mainType = IndexMainType.main(index, "bar");
    Configuration emptySettings = new MapSettings().asConfig();
    SettingsConfiguration defaultNbOfShards = SettingsConfiguration.newBuilder(emptySettings).build();
    SettingsConfiguration specifiedDefaultNbOfShards = SettingsConfiguration.newBuilder(emptySettings).setDefaultNbOfShards(5).build();
    SettingsConfiguration specifyDefaultNbOfShards = SettingsConfiguration.newBuilder(new MapSettings().setProperty("sonar.search." + index.getName() + ".shards", 1).asConfig()).setDefaultNbOfShards(1).build();
    SettingsConfiguration specifiedNbOfShards = SettingsConfiguration.newBuilder(new MapSettings().setProperty("sonar.search." + index.getName() + ".shards", 10).asConfig()).setDefaultNbOfShards(5).build();
    assertThat(hashOf(new TestNewIndex(mainType, defaultNbOfShards))).isEqualTo(hashOf(new TestNewIndex(mainType, defaultNbOfShards))).isEqualTo(hashOf(new TestNewIndex(mainType, specifyDefaultNbOfShards))).isNotEqualTo(hashOf(new TestNewIndex(mainType, specifiedDefaultNbOfShards))).isNotEqualTo(hashOf(new TestNewIndex(mainType, specifiedNbOfShards)));
    assertThat(hashOf(new TestNewIndex(mainType, specifiedDefaultNbOfShards))).isEqualTo(hashOf(new TestNewIndex(mainType, specifiedDefaultNbOfShards))).isNotEqualTo(hashOf(new TestNewIndex(mainType, specifyDefaultNbOfShards)));
}
Also used : SettingsConfiguration(org.sonar.server.es.newindex.SettingsConfiguration) Configuration(org.sonar.api.config.Configuration) MapSettings(org.sonar.api.config.internal.MapSettings) SettingsConfiguration(org.sonar.server.es.newindex.SettingsConfiguration) TestNewIndex(org.sonar.server.es.newindex.TestNewIndex) IndexMainType(org.sonar.server.es.IndexType.IndexMainType) TestNewIndex(org.sonar.server.es.newindex.TestNewIndex) Test(org.junit.Test)

Example 33 with Configuration

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

the class ConfigurationProviderTest method getStringArray_on_unknown_or_non_multivalue_properties_ignores_subsequent_commas_differently_from_Settings.

@Test
@UseDataProvider("subsequentCommas2")
public void getStringArray_on_unknown_or_non_multivalue_properties_ignores_subsequent_commas_differently_from_Settings(String subsequentCommas, String[] expected) {
    settings.setProperty(nonDeclaredKey, subsequentCommas);
    settings.setProperty(nonMultivalueKey, subsequentCommas);
    Configuration configuration = underTest.provide(settings);
    getStringArrayBehaviorDiffers(configuration, nonDeclaredKey, expected);
    getStringArrayBehaviorDiffers(configuration, nonMultivalueKey, expected);
}
Also used : Configuration(org.sonar.api.config.Configuration) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 34 with Configuration

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

the class ConfigurationProviderTest method getStringArray_on_unknown_or_non_multivalue_properties_ignores_empty_fields_same_as_settings.

@Test
@UseDataProvider("emptyFields1")
public void getStringArray_on_unknown_or_non_multivalue_properties_ignores_empty_fields_same_as_settings(String emptyFields, String[] expected) {
    settings.setProperty(nonDeclaredKey, emptyFields);
    settings.setProperty(nonMultivalueKey, emptyFields);
    Configuration configuration = underTest.provide(settings);
    getStringArrayBehaviorIsTheSame(configuration, nonDeclaredKey, expected);
    getStringArrayBehaviorIsTheSame(configuration, nonMultivalueKey, expected);
}
Also used : Configuration(org.sonar.api.config.Configuration) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 35 with Configuration

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

the class ConfigurationRepositoryTest method project_settings_are_cached_to_avoid_db_access.

@Test
public void project_settings_are_cached_to_avoid_db_access() {
    ComponentDto project = db.components().insertPrivateProject();
    insertProjectProperty(project, "key", "value");
    analysisMetadataHolder.setProject(Project.from(project));
    Configuration config = underTest.getConfiguration();
    assertThat(config.get("key")).hasValue("value");
    db.executeUpdateSql("delete from properties");
    db.commit();
    assertThat(config.get("key")).hasValue("value");
}
Also used : Configuration(org.sonar.api.config.Configuration) ComponentDto(org.sonar.db.component.ComponentDto) 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