Search in sources :

Example 1 with AlmSettingDto

use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.

the class BitbucketServerSettingsValidatorTest method validate_failure_on_bitbucket_server_api_error.

@Test
public void validate_failure_on_bitbucket_server_api_error() {
    doThrow(new IllegalArgumentException("error")).when(bitbucketServerRestClient).validateUrl(anyString());
    AlmSettingDto almSettingDto = createNewBitbucketDto("http://abc.com", "abc");
    assertThatThrownBy(() -> underTest.validate(almSettingDto)).isInstanceOf(IllegalArgumentException.class);
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 2 with AlmSettingDto

use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.

the class BitbucketServerSettingsValidatorTest method validate_failure_on_incomplete_configuration.

@Test
public void validate_failure_on_incomplete_configuration() {
    AlmSettingDto almSettingDto = createNewBitbucketDto(null, "abc");
    assertThatThrownBy(() -> underTest.validate(almSettingDto)).isInstanceOf(IllegalArgumentException.class);
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 3 with AlmSettingDto

use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.

the class BitbucketServerSettingsValidatorTest method validate_success_with_encrypted_token.

@Test
public void validate_success_with_encrypted_token() {
    String encryptedToken = "abc";
    String decryptedToken = "decrypted-token";
    AlmSettingDto almSettingDto = createNewBitbucketDto("http://abc.com", encryptedToken);
    when(encryption.isEncrypted(encryptedToken)).thenReturn(true);
    when(encryption.decrypt(encryptedToken)).thenReturn(decryptedToken);
    underTest.validate(almSettingDto);
    verify(bitbucketServerRestClient, times(1)).validateUrl("http://abc.com");
    verify(bitbucketServerRestClient, times(1)).validateToken("http://abc.com", decryptedToken);
    verify(bitbucketServerRestClient, times(1)).validateReadPermission("http://abc.com", decryptedToken);
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 4 with AlmSettingDto

use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.

the class GithubGlobalSettingsValidatorTest method github_validation_checks_invalid_appId.

@Test
public void github_validation_checks_invalid_appId() {
    AlmSettingDto almSettingDto = createNewGithubDto("clientId", "clientSecret", "abc", null);
    assertThatThrownBy(() -> underTest.validate(almSettingDto)).isInstanceOf(IllegalArgumentException.class).hasMessage("Invalid appId; For input string: \"abc\"");
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 5 with AlmSettingDto

use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.

the class GithubGlobalSettingsValidatorTest method github_global_settings_validation.

@Test
public void github_global_settings_validation() {
    AlmSettingDto almSettingDto = createNewGithubDto("clientId", "clientSecret", EXAMPLE_APP_ID, EXAMPLE_PRIVATE_KEY);
    when(encryption.isEncrypted(any())).thenReturn(false);
    GithubAppConfiguration configuration = underTest.validate(almSettingDto);
    ArgumentCaptor<GithubAppConfiguration> configurationArgumentCaptor = ArgumentCaptor.forClass(GithubAppConfiguration.class);
    verify(appClient).checkApiEndpoint(configurationArgumentCaptor.capture());
    verify(appClient).checkAppPermissions(configurationArgumentCaptor.capture());
    assertThat(configuration.getId()).isEqualTo(configurationArgumentCaptor.getAllValues().get(0).getId());
    assertThat(configuration.getId()).isEqualTo(configurationArgumentCaptor.getAllValues().get(1).getId());
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) GithubAppConfiguration(org.sonar.alm.client.github.config.GithubAppConfiguration) Test(org.junit.Test)

Aggregations

AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)217 Test (org.junit.Test)175 UserDto (org.sonar.db.user.UserDto)113 TestRequest (org.sonar.server.ws.TestRequest)48 ProjectDto (org.sonar.db.project.ProjectDto)40 NotFoundException (org.sonar.server.exceptions.NotFoundException)37 DbSession (org.sonar.db.DbSession)36 WebService (org.sonar.api.server.ws.WebService)31 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)28 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)28 Rule (org.junit.Rule)28 Mockito.mock (org.mockito.Mockito.mock)28 DbTester (org.sonar.db.DbTester)28 UserSessionRule (org.sonar.server.tester.UserSessionRule)28 WsActionTester (org.sonar.server.ws.WsActionTester)28 Encryption (org.sonar.api.config.internal.Encryption)27 ForbiddenException (org.sonar.server.exceptions.ForbiddenException)27 ComponentFinder (org.sonar.server.component.ComponentFinder)26 Tuple.tuple (org.assertj.core.groups.Tuple.tuple)25 ProjectAlmSettingDto (org.sonar.db.alm.setting.ProjectAlmSettingDto)25