Search in sources :

Example 1 with OwnerAssignmentService

use of com.sequenceiq.authorization.service.OwnerAssignmentService 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());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) BeforeEach(org.junit.jupiter.api.BeforeEach) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) NotificationSender(com.sequenceiq.notification.NotificationSender) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) Credential(com.sequenceiq.environment.credential.domain.Credential) Client(javax.ws.rs.client.Client) OwnerAssignmentService(com.sequenceiq.authorization.service.OwnerAssignmentService) MockitoAnnotations(org.mockito.MockitoAnnotations) CloudbreakMessagesService(com.sequenceiq.cloudbreak.message.CloudbreakMessagesService) ENVIRONMENT(com.sequenceiq.common.model.CredentialType.ENVIRONMENT) BadRequestException(javax.ws.rs.BadRequestException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Notification(com.sequenceiq.notification.Notification) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) ArgumentMatchers.anyCollection(org.mockito.ArgumentMatchers.anyCollection) List(java.util.List) EnvironmentViewService(com.sequenceiq.environment.environment.service.EnvironmentViewService) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Credential(com.sequenceiq.environment.credential.domain.Credential) Set(java.util.Set) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Aggregations

OwnerAssignmentService (com.sequenceiq.authorization.service.OwnerAssignmentService)1 CloudbreakMessagesService (com.sequenceiq.cloudbreak.message.CloudbreakMessagesService)1 ENVIRONMENT (com.sequenceiq.common.model.CredentialType.ENVIRONMENT)1 Credential (com.sequenceiq.environment.credential.domain.Credential)1 EnvironmentViewService (com.sequenceiq.environment.environment.service.EnvironmentViewService)1 Notification (com.sequenceiq.notification.Notification)1 NotificationSender (com.sequenceiq.notification.NotificationSender)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 BadRequestException (javax.ws.rs.BadRequestException)1 Client (javax.ws.rs.client.Client)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)1 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 ArgumentMatchers.anyCollection (org.mockito.ArgumentMatchers.anyCollection)1 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)1