Search in sources :

Example 1 with AlmSettingsTesting.newGithubAlmSettingDto

use of org.sonar.db.almsettings.AlmSettingsTesting.newGithubAlmSettingDto in project sonarqube by SonarSource.

the class AlmSettingDaoTest method selectByKey.

@Test
public void selectByKey() {
    when(uuidFactory.create()).thenReturn(A_UUID);
    String decrypted = "decrypted";
    when(encryption.isEncrypted(any())).thenReturn(true);
    when(encryption.decrypt(any())).thenReturn(decrypted);
    AlmSettingDto almSettingDto = AlmSettingsTesting.newGithubAlmSettingDto();
    underTest.insert(dbSession, almSettingDto);
    assertThat(underTest.selectByKey(dbSession, almSettingDto.getKey()).get()).extracting(AlmSettingDto::getUuid, AlmSettingDto::getKey, AlmSettingDto::getRawAlm, AlmSettingDto::getUrl, AlmSettingDto::getAppId, AlmSettingDto::getCreatedAt, AlmSettingDto::getUpdatedAt, s -> almSettingDto.getDecryptedPrivateKey(encryption), s -> almSettingDto.getDecryptedPersonalAccessToken(encryption), s -> almSettingDto.getDecryptedClientSecret(encryption)).containsExactly(A_UUID, almSettingDto.getKey(), ALM.GITHUB.getId(), almSettingDto.getUrl(), almSettingDto.getAppId(), NOW, NOW, almSettingDto.getDecryptedPrivateKey(encryption), null, almSettingDto.getDecryptedClientSecret(encryption));
    assertThat(underTest.selectByKey(dbSession, "foo")).isNotPresent();
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DbTester(org.sonar.db.DbTester) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UuidFactory(org.sonar.core.util.UuidFactory) Test(org.junit.Test) NoOpAuditPersister(org.sonar.db.audit.NoOpAuditPersister) Mockito.when(org.mockito.Mockito.when) DbSession(org.sonar.db.DbSession) TestSystem2(org.sonar.api.impl.utils.TestSystem2) List(java.util.List) Rule(org.junit.Rule) AlmSettingsTesting(org.sonar.db.almsettings.AlmSettingsTesting) Encryption(org.sonar.api.config.internal.Encryption) AlmSettingsTesting.newGithubAlmSettingDto(org.sonar.db.almsettings.AlmSettingsTesting.newGithubAlmSettingDto) Mockito.mock(org.mockito.Mockito.mock) AlmSettingsTesting.newGithubAlmSettingDto(org.sonar.db.almsettings.AlmSettingsTesting.newGithubAlmSettingDto) Test(org.junit.Test)

Aggregations

List (java.util.List)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Rule (org.junit.Rule)1 Test (org.junit.Test)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.when (org.mockito.Mockito.when)1 Encryption (org.sonar.api.config.internal.Encryption)1 TestSystem2 (org.sonar.api.impl.utils.TestSystem2)1 UuidFactory (org.sonar.core.util.UuidFactory)1 DbSession (org.sonar.db.DbSession)1 DbTester (org.sonar.db.DbTester)1 AlmSettingsTesting (org.sonar.db.almsettings.AlmSettingsTesting)1 AlmSettingsTesting.newGithubAlmSettingDto (org.sonar.db.almsettings.AlmSettingsTesting.newGithubAlmSettingDto)1 NoOpAuditPersister (org.sonar.db.audit.NoOpAuditPersister)1