Search in sources :

Example 86 with AlmSettingDto

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

the class UpdateBitbucketActionTest method fail_when_new_key_matches_existing_alm_setting.

@Test
public void fail_when_new_key_matches_existing_alm_setting() {
    UserDto user = db.users().insertUser();
    userSession.logIn(user).setSystemAdministrator();
    AlmSettingDto almSetting1 = db.almSettings().insertBitbucketAlmSetting();
    AlmSettingDto almSetting2 = db.almSettings().insertBitbucketAlmSetting();
    assertThatThrownBy(() -> ws.newRequest().setParam("key", almSetting1.getKey()).setParam("newKey", almSetting2.getKey()).setParam("url", "https://bitbucket.enterprise-unicorn.com").setParam("personalAccessToken", "0123456789").execute()).isInstanceOf(IllegalArgumentException.class).hasMessageContaining(format("An ALM setting with key '%s' already exists", almSetting2.getKey()));
}
Also used : UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 87 with AlmSettingDto

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

the class UpdateGithubActionTest method update_with_new_key.

@Test
public void update_with_new_key() {
    UserDto user = db.users().insertUser();
    userSession.logIn(user).setSystemAdministrator();
    AlmSettingDto almSettingDto = db.almSettings().insertGitHubAlmSetting();
    ws.newRequest().setParam("key", almSettingDto.getKey()).setParam("newKey", "GitHub Server - Infra Team").setParam("url", "https://github.enterprise-unicorn.com").setParam("appId", "54321").setParam("privateKey", "10987654321").setParam("clientId", "client_1234").setParam("clientSecret", "client_so_secret").execute();
    assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession())).extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getAppId, s -> s.getDecryptedPrivateKey(encryption), AlmSettingDto::getClientId, s -> s.getDecryptedClientSecret(encryption)).containsOnly(tuple("GitHub Server - Infra Team", "https://github.enterprise-unicorn.com", "54321", "10987654321", "client_1234", "client_so_secret"));
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) ComponentFinder(org.sonar.server.component.ComponentFinder) UserDto(org.sonar.db.user.UserDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MultipleAlmFeatureProvider(org.sonar.server.almsettings.MultipleAlmFeatureProvider) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test) WsActionTester(org.sonar.server.ws.WsActionTester) NotFoundException(org.sonar.server.exceptions.NotFoundException) String.format(java.lang.String.format) Rule(org.junit.Rule) WebService(org.sonar.api.server.ws.WebService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Encryption(org.sonar.api.config.internal.Encryption) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) Mockito.mock(org.mockito.Mockito.mock) UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 88 with AlmSettingDto

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

the class UpdateGithubActionTest method update_url_with_trailing_slash.

@Test
public void update_url_with_trailing_slash() {
    UserDto user = db.users().insertUser();
    userSession.logIn(user).setSystemAdministrator();
    AlmSettingDto almSettingDto = db.almSettings().insertGitHubAlmSetting();
    ws.newRequest().setParam("key", almSettingDto.getKey()).setParam("url", "https://github.enterprise-unicorn.com/").setParam("appId", "54321").setParam("privateKey", "10987654321").setParam("clientId", "client_1234").setParam("clientSecret", "client_so_secret").execute();
    assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession())).extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getAppId, s -> s.getDecryptedPrivateKey(encryption), AlmSettingDto::getClientId, s -> s.getDecryptedClientSecret(encryption)).containsOnly(tuple(almSettingDto.getKey(), "https://github.enterprise-unicorn.com", "54321", "10987654321", "client_1234", "client_so_secret"));
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) ComponentFinder(org.sonar.server.component.ComponentFinder) UserDto(org.sonar.db.user.UserDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MultipleAlmFeatureProvider(org.sonar.server.almsettings.MultipleAlmFeatureProvider) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test) WsActionTester(org.sonar.server.ws.WsActionTester) NotFoundException(org.sonar.server.exceptions.NotFoundException) String.format(java.lang.String.format) Rule(org.junit.Rule) WebService(org.sonar.api.server.ws.WebService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Encryption(org.sonar.api.config.internal.Encryption) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) Mockito.mock(org.mockito.Mockito.mock) UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 89 with AlmSettingDto

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

the class UpdateGithubActionTest method update.

@Test
public void update() {
    UserDto user = db.users().insertUser();
    userSession.logIn(user).setSystemAdministrator();
    AlmSettingDto almSettingDto = db.almSettings().insertGitHubAlmSetting();
    ws.newRequest().setParam("key", almSettingDto.getKey()).setParam("url", "https://github.enterprise-unicorn.com").setParam("appId", "54321").setParam("privateKey", "10987654321").setParam("clientId", "client_1234").setParam("clientSecret", "client_so_secret").execute();
    assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession())).extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, AlmSettingDto::getAppId, s -> s.getDecryptedPrivateKey(encryption), AlmSettingDto::getClientId, s -> s.getDecryptedClientSecret(encryption)).containsOnly(tuple(almSettingDto.getKey(), "https://github.enterprise-unicorn.com", "54321", "10987654321", "client_1234", "client_so_secret"));
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) ComponentFinder(org.sonar.server.component.ComponentFinder) UserDto(org.sonar.db.user.UserDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MultipleAlmFeatureProvider(org.sonar.server.almsettings.MultipleAlmFeatureProvider) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test) WsActionTester(org.sonar.server.ws.WsActionTester) NotFoundException(org.sonar.server.exceptions.NotFoundException) String.format(java.lang.String.format) Rule(org.junit.Rule) WebService(org.sonar.api.server.ws.WebService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Encryption(org.sonar.api.config.internal.Encryption) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) Mockito.mock(org.mockito.Mockito.mock) UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 90 with AlmSettingDto

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

the class SearchBitbucketServerReposActionTest method list_repos.

@Test
public void list_repos() {
    UserDto user = db.users().insertUser();
    userSession.logIn(user).addPermission(PROVISION_PROJECTS);
    AlmSettingDto almSetting = db.almSettings().insertBitbucketAlmSetting();
    db.almPats().insert(dto -> {
        dto.setAlmSettingUuid(almSetting.getUuid());
        dto.setUserUuid(user.getUuid());
    });
    ProjectDto projectDto = db.components().insertPrivateProjectDto();
    db.almSettings().insertBitbucketProjectAlmSetting(almSetting, projectDto, s -> s.setAlmRepo("projectKey2"), s -> s.setAlmSlug("repo-slug-2"));
    AlmIntegrations.SearchBitbucketserverReposWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).executeProtobuf(SearchBitbucketserverReposWsResponse.class);
    assertThat(response.getIsLastPage()).isTrue();
    assertThat(response.getRepositoriesList()).extracting(AlmIntegrations.BBSRepo::getId, AlmIntegrations.BBSRepo::getName, AlmIntegrations.BBSRepo::getSlug, AlmIntegrations.BBSRepo::hasSqProjectKey, AlmIntegrations.BBSRepo::getSqProjectKey, AlmIntegrations.BBSRepo::getProjectKey).containsExactlyInAnyOrder(tuple(1L, "repoName1", "repo-slug-1", false, "", "projectKey1"), tuple(3L, "repoName2", "repo-slug-2", true, projectDto.getKey(), "projectKey2"));
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) UserDto(org.sonar.db.user.UserDto) SearchBitbucketserverReposWsResponse(org.sonarqube.ws.AlmIntegrations.SearchBitbucketserverReposWsResponse) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) AlmIntegrations(org.sonarqube.ws.AlmIntegrations) 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