use of com.sequenceiq.environment.environment.service.EnvironmentViewService 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());
}
Aggregations