Search in sources :

Example 11 with AlmSettingDto

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

the class BitbucketCloudValidatorTest method validate_forwardsExceptionFromRestClient.

@Test
public void validate_forwardsExceptionFromRestClient() {
    AlmSettingDto dto = mock(AlmSettingDto.class);
    when(dto.getAppId()).thenReturn(EXAMPLE_APP_ID);
    when(dto.getClientId()).thenReturn("clientId");
    when(dto.getDecryptedClientSecret(any())).thenReturn("secret");
    doThrow(new IllegalArgumentException("Exception from bitbucket cloud rest client")).when(bitbucketCloudRestClient).validate(any(), any(), any());
    assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> underTest.validate(dto)).withMessage("Exception from bitbucket cloud rest client");
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 12 with AlmSettingDto

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

the class AlmPatDaoWithPersisterTest method deleteByAlmSettingWithoutAffectedRowsIsNotPersisted.

@Test
public void deleteByAlmSettingWithoutAffectedRowsIsNotPersisted() {
    AlmSettingDto almSettingDto = db.almSettings().insertBitbucketAlmSetting();
    clearInvocations(auditPersister);
    underTest.deleteByAlmSetting(dbSession, almSettingDto);
    verifyNoInteractions(auditPersister);
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 13 with AlmSettingDto

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

the class AlmPatDaoWithPersisterTest method deleteByAlmSettingIsPersisted.

@Test
public void deleteByAlmSettingIsPersisted() {
    when(uuidFactory.create()).thenReturn(A_UUID);
    AlmSettingDto almSettingDto = db.almSettings().insertBitbucketAlmSetting();
    AlmPatDto almPat = newAlmPatDto();
    almPat.setAlmSettingUuid(almSettingDto.getUuid());
    underTest.insert(dbSession, almPat, null, almSettingDto.getKey());
    verify(auditPersister).addPersonalAccessToken(eq(dbSession), newValueCaptor.capture());
    underTest.deleteByAlmSetting(dbSession, almSettingDto);
    verify(auditPersister).deletePersonalAccessToken(eq(dbSession), newValueCaptor.capture());
    PersonalAccessTokenNewValue newValue = newValueCaptor.getValue();
    assertThat(newValue).extracting(PersonalAccessTokenNewValue::getPatUuid, PersonalAccessTokenNewValue::getAlmSettingUuid, PersonalAccessTokenNewValue::getAlmSettingKey).containsExactly(null, almPat.getAlmSettingUuid(), almSettingDto.getKey());
    assertThat(newValue.toString()).doesNotContain("userUuid");
}
Also used : PersonalAccessTokenNewValue(org.sonar.db.audit.model.PersonalAccessTokenNewValue) AlmPatsTesting.newAlmPatDto(org.sonar.db.alm.integration.pat.AlmPatsTesting.newAlmPatDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 14 with AlmSettingDto

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

the class AlmPatDaoTest method deleteByAlmSetting.

@Test
public void deleteByAlmSetting() {
    when(uuidFactory.create()).thenReturn(A_UUID);
    AlmSettingDto almSettingDto = db.almSettings().insertBitbucketAlmSetting();
    AlmPatDto almPat = newAlmPatDto();
    almPat.setAlmSettingUuid(almSettingDto.getUuid());
    underTest.insert(dbSession, almPat, null, null);
    underTest.deleteByAlmSetting(dbSession, almSettingDto);
    assertThat(underTest.selectByUuid(dbSession, almPat.getUuid())).isNotPresent();
}
Also used : AlmPatsTesting.newAlmPatDto(org.sonar.db.alm.integration.pat.AlmPatsTesting.newAlmPatDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) AlmSettingsTesting.newGithubAlmSettingDto(org.sonar.db.almsettings.AlmSettingsTesting.newGithubAlmSettingDto) Test(org.junit.Test)

Example 15 with AlmSettingDto

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

the class AlmPatDaoTest method selectByAlmSetting.

@Test
public void selectByAlmSetting() {
    when(uuidFactory.create()).thenReturn(A_UUID);
    AlmSettingDto almSetting = newGithubAlmSettingDto();
    almSettingDao.insert(dbSession, almSetting);
    AlmPatDto almPatDto = newAlmPatDto();
    almPatDto.setAlmSettingUuid(almSetting.getUuid());
    String userUuid = randomAlphanumeric(40);
    almPatDto.setUserUuid(userUuid);
    underTest.insert(dbSession, almPatDto, null, null);
    assertThat(underTest.selectByUserAndAlmSetting(dbSession, userUuid, almSetting).get()).extracting(AlmPatDto::getUuid, AlmPatDto::getPersonalAccessToken, AlmPatDto::getUserUuid, AlmPatDto::getAlmSettingUuid, AlmPatDto::getCreatedAt, AlmPatDto::getUpdatedAt).containsExactly(A_UUID, almPatDto.getPersonalAccessToken(), userUuid, almSetting.getUuid(), NOW, NOW);
    assertThat(underTest.selectByUserAndAlmSetting(dbSession, randomAlphanumeric(40), newGithubAlmSettingDto())).isNotPresent();
}
Also used : AlmPatsTesting.newAlmPatDto(org.sonar.db.alm.integration.pat.AlmPatsTesting.newAlmPatDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) AlmSettingsTesting.newGithubAlmSettingDto(org.sonar.db.almsettings.AlmSettingsTesting.newGithubAlmSettingDto) 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