use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.
the class CredentialValidatorTest method testValidateCredentialUpdate.
@Test
void testValidateCredentialUpdate() {
Credential original = new Credential();
original.setCloudPlatform(CloudPlatform.AWS.name());
Credential newCred = new Credential();
newCred.setCloudPlatform(CloudPlatform.AWS.name());
ValidationResult result = underTest.validateCredentialUpdate(original, newCred, ENVIRONMENT);
assertFalse(result.hasError());
}
use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.
the class CredentialDeleteServiceTest method testMultipleIfAllTheCredentialsAreExistsAndAbleToArchiveThenExpectedCredentialsAreComingBack.
@Test
void testMultipleIfAllTheCredentialsAreExistsAndAbleToArchiveThenExpectedCredentialsAreComingBack() {
String firstCredentialName = "first";
String secondCredentialName = "second";
Credential firstCred = createCredentialWithName(firstCredentialName);
Credential secondCred = createCredentialWithName(secondCredentialName);
Set<String> names = Set.of(firstCredentialName, secondCredentialName);
when(credentialService.findByNameAndAccountId(eq(firstCredentialName), eq(ACCOUNT_ID), any(Set.class), any())).thenReturn(Optional.of(firstCred));
when(credentialService.findByNameAndAccountId(eq(secondCredentialName), eq(ACCOUNT_ID), any(Set.class), any())).thenReturn(Optional.of(secondCred));
when(credentialService.save(firstCred)).thenReturn(firstCred);
when(credentialService.save(secondCred)).thenReturn(secondCred);
doNothing().when(ownerAssignmentService).notifyResourceDeleted(any(), any());
Set<Credential> result = underTest.deleteMultiple(names, ACCOUNT_ID, ENVIRONMENT);
assertNotNull(result);
assertEquals(2L, result.size());
assertTrue(result.stream().anyMatch(credential -> credential.getName().startsWith(firstCredentialName)));
assertTrue(result.stream().anyMatch(credential -> credential.getName().startsWith(secondCredentialName)));
assertTrue(result.stream().allMatch(Credential::isArchived));
verify(credentialService, times(2)).findByNameAndAccountId(anyString(), anyString(), anyCollection(), any());
verify(environmentViewService, times(2)).findAllByCredentialId(any());
verify(credentialService, times(2)).save(any());
verify(credentialService, times(1)).save(firstCred);
verify(credentialService, times(1)).save(secondCred);
verify(ownerAssignmentService, times(2)).notifyResourceDeleted(any(), any());
}
use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.
the class CredentialDeleteServiceTest method testWhenCredentialDeleteIsSuccessfulThenNotificationShouldBeSent.
@Test
void testWhenCredentialDeleteIsSuccessfulThenNotificationShouldBeSent() {
Credential cred = createCredentialWithName("first");
when(credentialService.findByNameAndAccountId(eq(cred.getName()), eq(ACCOUNT_ID), any(Set.class), any())).thenReturn(Optional.of(cred));
when(credentialService.save(cred)).thenReturn(cred);
doNothing().when(ownerAssignmentService).notifyResourceDeleted(any(), any());
underTest.deleteMultiple(Set.of(cred.getName()), ACCOUNT_ID, ENVIRONMENT);
notificationSender.send(any(Notification.class), any(List.class), any(Client.class));
verify(ownerAssignmentService, times(1)).notifyResourceDeleted(any(), any());
}
use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.
the class CredentialServiceTest method testUpdateByAccountIdModifyPlatformIsForbiddenAndEnvironmentCredential.
@Test
void testUpdateByAccountIdModifyPlatformIsForbiddenAndEnvironmentCredential() {
Credential result = new Credential();
result.setCloudPlatform("anotherplatform");
when(repository.findByNameAndAccountId(eq(CREDENTIAL_NAME), eq(ACCOUNT_ID), anyCollection(), any())).thenReturn(Optional.of(result));
when(credentialValidator.validateCredentialUpdate(any(), any(), any())).thenThrow(BadRequestException.class);
assertThrows(BadRequestException.class, () -> credentialServiceUnderTest.updateByAccountId(CREDENTIAL, ACCOUNT_ID, ENVIRONMENT));
}
use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.
the class CredentialServiceTest method testUpdateByAccountIdAndAuditCredential.
@Test
void testUpdateByAccountIdAndAuditCredential() {
Credential result = new Credential();
result.setId(2L);
result.setResourceCrn("this");
result.setCloudPlatform(PLATFORM);
CREDENTIAL.setId(1L);
CREDENTIAL.setResourceCrn("that");
CREDENTIAL.setCloudPlatform(PLATFORM);
when(repository.findByNameAndAccountId(eq(CREDENTIAL_NAME), eq(ACCOUNT_ID), anyCollection(), any())).thenReturn(Optional.of(result));
when(credentialAdapter.verify(any(), anyString())).thenAnswer(i -> new CredentialVerification(i.getArgument(0), true));
when(repository.save(any())).thenAnswer(i -> i.getArgument(0));
when(credentialValidator.validateCredentialUpdate(any(Credential.class), any(Credential.class), any(CredentialType.class))).thenReturn(ValidationResult.builder().build());
Credential testResult = credentialServiceUnderTest.updateByAccountId(CREDENTIAL, ACCOUNT_ID, AUDIT);
verify(repository).save(CREDENTIAL);
assertEquals(2L, testResult.getId());
}
Aggregations