Search in sources :

Example 1 with Settings

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

the class CreateDb method main.

public static void main(String[] args) {
    createDb(configuration -> {
        Settings settings = new MapSettings();
        configuration.asMap().forEach(settings::setProperty);
        logJdbcSettings(settings);
        SQDatabase.newDatabase(settings, true).start();
    });
}
Also used : MapSettings(org.sonar.api.config.internal.MapSettings) Settings(org.sonar.api.config.internal.Settings) MapSettings(org.sonar.api.config.internal.MapSettings)

Example 2 with Settings

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

the class ValidateActionTest method github_validation_checks.

@Test
public void github_validation_checks() {
    AlmSettingDto almSetting = insertAlmSetting(db.almSettings().insertGitHubAlmSetting(settings -> settings.setClientId("clientId").setClientSecret("clientSecret")));
    when(encryption.isEncrypted(any())).thenReturn(false);
    ws.newRequest().setParam("key", almSetting.getKey()).execute();
    ArgumentCaptor<AlmSettingDto> almSettingDtoArgumentCaptor = ArgumentCaptor.forClass(AlmSettingDto.class);
    verify(githubGlobalSettingsValidator).validate(almSettingDtoArgumentCaptor.capture());
    assertThat(almSettingDtoArgumentCaptor.getAllValues()).hasSize(1);
    assertThat(almSettingDtoArgumentCaptor.getValue().getClientId()).isEqualTo(almSetting.getClientId());
    assertThat(almSettingDtoArgumentCaptor.getValue().getDecryptedClientSecret(encryption)).isEqualTo(almSetting.getDecryptedClientSecret(encryption));
    assertThat(almSettingDtoArgumentCaptor.getValue().getAlm()).isEqualTo(almSetting.getAlm());
    assertThat(almSettingDtoArgumentCaptor.getValue().getAppId()).isEqualTo(almSetting.getAppId());
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ComponentFinder(org.sonar.server.component.ComponentFinder) Settings(org.sonar.api.config.internal.Settings) BeforeClass(org.junit.BeforeClass) UserDto(org.sonar.db.user.UserDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) GitlabGlobalSettingsValidator(org.sonar.alm.client.gitlab.GitlabGlobalSettingsValidator) MultipleAlmFeatureProvider(org.sonar.server.almsettings.MultipleAlmFeatureProvider) BitbucketServerSettingsValidator(org.sonar.alm.client.bitbucketserver.BitbucketServerSettingsValidator) ALM(org.sonar.db.alm.setting.ALM) GithubGlobalSettingsValidator(org.sonar.alm.client.github.GithubGlobalSettingsValidator) Mockito.doThrow(org.mockito.Mockito.doThrow) ArgumentCaptor(org.mockito.ArgumentCaptor) WebService(org.sonar.api.server.ws.WebService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Encryption(org.sonar.api.config.internal.Encryption) ResourceTypes(org.sonar.api.resources.ResourceTypes) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) BitbucketCloudRestClient(org.sonar.alm.client.bitbucket.bitbucketcloud.BitbucketCloudRestClient) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test) BitbucketCloudValidator(org.sonar.alm.client.bitbucket.bitbucketcloud.BitbucketCloudValidator) Mockito.when(org.mockito.Mockito.when) WsActionTester(org.sonar.server.ws.WsActionTester) NotFoundException(org.sonar.server.exceptions.NotFoundException) Mockito.verify(org.mockito.Mockito.verify) Rule(org.junit.Rule) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) AzureDevOpsValidator(org.sonar.alm.client.azure.AzureDevOpsValidator) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) AzureDevOpsHttpClient(org.sonar.alm.client.azure.AzureDevOpsHttpClient) Mockito.mock(org.mockito.Mockito.mock) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 3 with Settings

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

the class ValidateActionTest method github_validation_checks_with_encrypted_secret.

@Test
public void github_validation_checks_with_encrypted_secret() {
    String secret = "encrypted-secret";
    String decryptedSecret = "decrypted-secret";
    AlmSettingDto almSetting = insertAlmSetting(db.almSettings().insertGitHubAlmSetting(settings -> settings.setClientId("clientId").setClientSecret(secret)));
    when(encryption.isEncrypted(secret)).thenReturn(true);
    when(encryption.decrypt(secret)).thenReturn(decryptedSecret);
    ws.newRequest().setParam("key", almSetting.getKey()).execute();
    ArgumentCaptor<AlmSettingDto> almSettingDtoArgumentCaptor = ArgumentCaptor.forClass(AlmSettingDto.class);
    verify(githubGlobalSettingsValidator).validate(almSettingDtoArgumentCaptor.capture());
    assertThat(almSettingDtoArgumentCaptor.getAllValues()).hasSize(1);
    assertThat(almSettingDtoArgumentCaptor.getValue().getClientId()).isEqualTo(almSetting.getClientId());
    assertThat(almSettingDtoArgumentCaptor.getValue().getDecryptedClientSecret(encryption)).isEqualTo(decryptedSecret);
    assertThat(almSettingDtoArgumentCaptor.getValue().getAlm()).isEqualTo(almSetting.getAlm());
    assertThat(almSettingDtoArgumentCaptor.getValue().getAppId()).isEqualTo(almSetting.getAppId());
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ComponentFinder(org.sonar.server.component.ComponentFinder) Settings(org.sonar.api.config.internal.Settings) BeforeClass(org.junit.BeforeClass) UserDto(org.sonar.db.user.UserDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) GitlabGlobalSettingsValidator(org.sonar.alm.client.gitlab.GitlabGlobalSettingsValidator) MultipleAlmFeatureProvider(org.sonar.server.almsettings.MultipleAlmFeatureProvider) BitbucketServerSettingsValidator(org.sonar.alm.client.bitbucketserver.BitbucketServerSettingsValidator) ALM(org.sonar.db.alm.setting.ALM) GithubGlobalSettingsValidator(org.sonar.alm.client.github.GithubGlobalSettingsValidator) Mockito.doThrow(org.mockito.Mockito.doThrow) ArgumentCaptor(org.mockito.ArgumentCaptor) WebService(org.sonar.api.server.ws.WebService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Encryption(org.sonar.api.config.internal.Encryption) ResourceTypes(org.sonar.api.resources.ResourceTypes) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) BitbucketCloudRestClient(org.sonar.alm.client.bitbucket.bitbucketcloud.BitbucketCloudRestClient) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test) BitbucketCloudValidator(org.sonar.alm.client.bitbucket.bitbucketcloud.BitbucketCloudValidator) Mockito.when(org.mockito.Mockito.when) WsActionTester(org.sonar.server.ws.WsActionTester) NotFoundException(org.sonar.server.exceptions.NotFoundException) Mockito.verify(org.mockito.Mockito.verify) Rule(org.junit.Rule) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) AzureDevOpsValidator(org.sonar.alm.client.azure.AzureDevOpsValidator) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) AzureDevOpsHttpClient(org.sonar.alm.client.azure.AzureDevOpsHttpClient) Mockito.mock(org.mockito.Mockito.mock) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 4 with Settings

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

the class NotificationMediumTest method getDispatchers_empty.

@Test
public void getDispatchers_empty() {
    Settings settings = new MapSettings().setProperty("sonar.notifications.delay", 1L);
    service = new NotificationService(dbClient);
    assertThat(service.getDispatchers()).isEmpty();
}
Also used : MapSettings(org.sonar.api.config.internal.MapSettings) Settings(org.sonar.api.config.internal.Settings) MapSettings(org.sonar.api.config.internal.MapSettings) Test(org.junit.Test)

Example 5 with Settings

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

the class ProjectConfigurationFactory method newProjectConfiguration.

public Configuration newProjectConfiguration(String projectKey, Branch branch) {
    Settings projectSettings = new ChildSettings(globalSettings);
    addSettings(projectSettings, projectKey);
    if (branch.getType() == BranchType.PULL_REQUEST) {
        addSettings(projectSettings, generatePullRequestKey(projectKey, branch.getPullRequestKey()));
    } else {
        addSettings(projectSettings, generateBranchKey(projectKey, branch.getName()));
    }
    return new ConfigurationBridge(projectSettings);
}
Also used : ChildSettings(org.sonar.server.setting.ChildSettings) ConfigurationBridge(org.sonar.api.config.internal.ConfigurationBridge) Settings(org.sonar.api.config.internal.Settings) ChildSettings(org.sonar.server.setting.ChildSettings)

Aggregations

Settings (org.sonar.api.config.internal.Settings)8 MapSettings (org.sonar.api.config.internal.MapSettings)4 Test (org.junit.Test)3 BiConsumer (java.util.function.BiConsumer)2 Consumer (java.util.function.Consumer)2 Function (java.util.function.Function)2 Nullable (javax.annotation.Nullable)2 DigestUtils (org.apache.commons.codec.digest.DigestUtils)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)2 Tuple.tuple (org.assertj.core.groups.Tuple.tuple)2 AssumptionViolatedException (org.junit.AssumptionViolatedException)2 BeforeClass (org.junit.BeforeClass)2 Rule (org.junit.Rule)2 ArgumentCaptor (org.mockito.ArgumentCaptor)2 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)2 Mockito.doThrow (org.mockito.Mockito.doThrow)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.verify (org.mockito.Mockito.verify)2 Mockito.when (org.mockito.Mockito.when)2