From 0c1035499d6840b4dede472c3f6915d786f08275 Mon Sep 17 00:00:00 2001 From: LeandroSilva Date: Mon, 6 May 2024 17:10:02 +0200 Subject: [PATCH 1/5] fix: * changed from email sending to logging the errors --- .../DeleteInactiveSessionsAndUserService.java | 8 +- .../service/WorkflowErrorLogService.java | 35 +++++++++ ...eteInactiveSessionsAndUserServiceTest.java | 10 +-- .../service/WorkflowErrorLogServiceTest.java | 76 +++++++++++++++++++ 4 files changed, 120 insertions(+), 9 deletions(-) create mode 100644 src/main/java/de/caritas/cob/userservice/api/workflow/delete/service/WorkflowErrorLogService.java create mode 100644 src/test/java/de/caritas/cob/userservice/api/workflow/delete/service/WorkflowErrorLogServiceTest.java diff --git a/src/main/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserService.java b/src/main/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserService.java index 3b92ef44a..ec7816436 100644 --- a/src/main/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserService.java +++ b/src/main/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserService.java @@ -30,7 +30,7 @@ public class DeleteInactiveSessionsAndUserService { private final @NonNull UserRepository userRepository; private final @NonNull SessionRepository sessionRepository; private final @NonNull DeleteUserAccountService deleteUserAccountService; - private final @NonNull WorkflowErrorMailService workflowErrorMailService; + private final @NonNull WorkflowErrorLogService workflowErrorLogService; private final @NonNull DeleteSessionService deleteSessionService; private final @NonNull InactivePrivateGroupsProvider inactivePrivateGroupsProvider; @@ -49,12 +49,12 @@ public void deleteInactiveSessionsAndUsers() { .flatMap(Collection::stream) .collect(Collectors.toList()); - sendWorkflowErrorsMail(workflowErrors); + logWorkflowErrors(workflowErrors); } - private void sendWorkflowErrorsMail(List workflowErrors) { + private void logWorkflowErrors(List workflowErrors) { if (isNotEmpty(workflowErrors)) { - this.workflowErrorMailService.buildAndSendErrorMail(workflowErrors); + this.workflowErrorLogService.logWorkflowErrors(workflowErrors); } } diff --git a/src/main/java/de/caritas/cob/userservice/api/workflow/delete/service/WorkflowErrorLogService.java b/src/main/java/de/caritas/cob/userservice/api/workflow/delete/service/WorkflowErrorLogService.java new file mode 100644 index 000000000..3960b4525 --- /dev/null +++ b/src/main/java/de/caritas/cob/userservice/api/workflow/delete/service/WorkflowErrorLogService.java @@ -0,0 +1,35 @@ +package de.caritas.cob.userservice.api.workflow.delete.service; + +import static org.apache.commons.collections4.CollectionUtils.isNotEmpty; + +import de.caritas.cob.userservice.api.workflow.delete.model.DeletionWorkflowError; +import java.util.List; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +/** Service class to log all deletion workflow errors. */ +@Slf4j +@Service +@RequiredArgsConstructor +public class WorkflowErrorLogService { + + public void logWorkflowErrors(List workflowErrors) { + if (isNotEmpty(workflowErrors)) { + workflowErrors.forEach( + workflowError -> + log.warn( + "Errors during deletion workflow:" + + " SourceType = {}; " + + "TargetType = {}; " + + "Identifier = {}; " + + "Reason = {}; " + + "Timestamp = {}.", + workflowError.getDeletionSourceType(), + workflowError.getDeletionTargetType(), + workflowError.getIdentifier(), + workflowError.getReason(), + workflowError.getTimestamp())); + } + } +} diff --git a/src/test/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserServiceTest.java b/src/test/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserServiceTest.java index 625cad2c1..b37e5a10c 100644 --- a/src/test/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserServiceTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserServiceTest.java @@ -30,7 +30,7 @@ public class DeleteInactiveSessionsAndUserServiceTest { @InjectMocks private DeleteInactiveSessionsAndUserService deleteInactiveSessionsAndUserService; - @Mock private WorkflowErrorMailService workflowErrorMailService; + @Mock private WorkflowErrorLogService workflowErrorLogService; @Mock private UserRepository userRepository; @Mock private SessionRepository sessionRepository; @Mock private DeleteUserAccountService deleteUserAccountService; @@ -60,7 +60,7 @@ public void deleteInactiveSessionsAndUsers_Should_SendWorkflowErrorsMail() { deleteInactiveSessionsAndUserService.deleteInactiveSessionsAndUsers(); - verify(workflowErrorMailService, Mockito.times(1)).buildAndSendErrorMail(any()); + verify(workflowErrorLogService, Mockito.times(1)).logWorkflowErrors(any()); } @Test @@ -138,7 +138,7 @@ public void deleteInactiveSessionsAndUsers_Should_SendWorkflowErrorsMail() { deleteInactiveSessionsAndUserService.deleteInactiveSessionsAndUsers(); - verify(workflowErrorMailService, Mockito.times(1)).buildAndSendErrorMail(any()); + verify(workflowErrorLogService, Mockito.times(1)).logWorkflowErrors(any()); } @Test @@ -164,7 +164,7 @@ public void deleteInactiveSessionsAndUsers_Should_SendWorkflowErrorsMail() { deleteInactiveSessionsAndUserService.deleteInactiveSessionsAndUsers(); - verify(workflowErrorMailService, Mockito.times(1)).buildAndSendErrorMail(any()); + verify(workflowErrorLogService, Mockito.times(1)).logWorkflowErrors(any()); } @Test @@ -187,6 +187,6 @@ public void deleteInactiveSessionsAndUsers_Should_SendWorkflowErrorsMail() { deleteInactiveSessionsAndUserService.deleteInactiveSessionsAndUsers(); - verify(workflowErrorMailService, Mockito.times(1)).buildAndSendErrorMail(any()); + verify(workflowErrorLogService, Mockito.times(1)).logWorkflowErrors(any()); } } diff --git a/src/test/java/de/caritas/cob/userservice/api/workflow/delete/service/WorkflowErrorLogServiceTest.java b/src/test/java/de/caritas/cob/userservice/api/workflow/delete/service/WorkflowErrorLogServiceTest.java new file mode 100644 index 000000000..43274c0e5 --- /dev/null +++ b/src/test/java/de/caritas/cob/userservice/api/workflow/delete/service/WorkflowErrorLogServiceTest.java @@ -0,0 +1,76 @@ +package de.caritas.cob.userservice.api.workflow.delete.service; + +import static de.caritas.cob.userservice.api.helper.CustomLocalDateTime.nowInUtc; +import static de.caritas.cob.userservice.api.workflow.delete.model.DeletionSourceType.ASKER; +import static de.caritas.cob.userservice.api.workflow.delete.model.DeletionTargetType.ROCKET_CHAT; +import static java.util.Collections.emptyList; + +import ch.qos.logback.classic.Logger; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.read.ListAppender; +import de.caritas.cob.userservice.api.workflow.delete.model.DeletionWorkflowError; +import java.util.ArrayList; +import java.util.List; +import org.assertj.core.api.Assertions; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.junit.MockitoJUnitRunner; +import org.slf4j.LoggerFactory; + +@RunWith(MockitoJUnitRunner.class) +public class WorkflowErrorLogServiceTest { + + @InjectMocks private WorkflowErrorLogService workflowErrorLogService; + + private ListAppender listAppender; + + @Before + public void setUp() { + Logger logger = (Logger) LoggerFactory.getLogger(WorkflowErrorLogService.class); + listAppender = new ListAppender<>(); + listAppender.start(); + logger.addAppender(listAppender); + } + + @Test + public void logWorkflowErrors_Should_logNoErrors_When_workflowErrorsAreNull() { + + // when + this.workflowErrorLogService.logWorkflowErrors(null); + + // then + Assertions.assertThat(listAppender.list).isEmpty(); + } + + @Test + public void logWorkflowErrors_Should_logNoErrors_When_workflowErrorsAreEmpty() { + + // when + this.workflowErrorLogService.logWorkflowErrors(emptyList()); + + // then + Assertions.assertThat(listAppender.list).isEmpty(); + } + + @Test + public void logWorkflowErrors_Should_logErrors_When_workflowErrorsExists() { + // given + List workflowErrors = new ArrayList<>(); + workflowErrors.add( + DeletionWorkflowError.builder() + .deletionSourceType(ASKER) + .deletionTargetType(ROCKET_CHAT) + .timestamp(nowInUtc()) + .reason("reason") + .identifier("id") + .build()); + + // when + this.workflowErrorLogService.logWorkflowErrors(workflowErrors); + + // then + Assertions.assertThat(listAppender.list).hasSize(1); + } +} From 6d470f6fc4379ae276c34a8ab9dc848fdd48515e Mon Sep 17 00:00:00 2001 From: LeandroSilva Date: Tue, 7 May 2024 14:38:45 +0200 Subject: [PATCH 2/5] fix: * Adpat log and error message emailing code and tests --- .../DeleteInactiveSessionsAndUserService.java | 27 +++++++++++++++---- ...eteInactiveSessionsAndUserServiceTest.java | 16 ++++++++--- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserService.java b/src/main/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserService.java index ec7816436..c099aa042 100644 --- a/src/main/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserService.java +++ b/src/main/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserService.java @@ -30,10 +30,15 @@ public class DeleteInactiveSessionsAndUserService { private final @NonNull UserRepository userRepository; private final @NonNull SessionRepository sessionRepository; private final @NonNull DeleteUserAccountService deleteUserAccountService; + private final @NonNull WorkflowErrorMailService workflowErrorMailService; private final @NonNull WorkflowErrorLogService workflowErrorLogService; private final @NonNull DeleteSessionService deleteSessionService; private final @NonNull InactivePrivateGroupsProvider inactivePrivateGroupsProvider; + private static final String USER_NOT_FOUND_REASON = "User could not be found."; + private static final String RC_SESSION_GROUP_NOT_FOUND_REASON = + "Session with rc group id could not be found."; + /** * Deletes all inactive sessions and even the asker accounts, if there are no more active * sessions. @@ -49,15 +54,27 @@ public void deleteInactiveSessionsAndUsers() { .flatMap(Collection::stream) .collect(Collectors.toList()); - logWorkflowErrors(workflowErrors); + processWorkflowErrors(workflowErrors); } - private void logWorkflowErrors(List workflowErrors) { + private void processWorkflowErrors(List workflowErrors) { if (isNotEmpty(workflowErrors)) { - this.workflowErrorLogService.logWorkflowErrors(workflowErrors); + List userNotFoundWorkflowErrors = + getSameReasonWorkflowErrors(workflowErrors, USER_NOT_FOUND_REASON); + List rcSessionGroupNotFoundWorkflowErrors = + getSameReasonWorkflowErrors(workflowErrors, RC_SESSION_GROUP_NOT_FOUND_REASON); + this.workflowErrorLogService.logWorkflowErrors(rcSessionGroupNotFoundWorkflowErrors); + this.workflowErrorMailService.buildAndSendErrorMail(userNotFoundWorkflowErrors); } } + private static List getSameReasonWorkflowErrors( + List workflowErrors, String reason) { + return workflowErrors.stream() + .filter(error -> reason.equals(error.getReason())) + .collect(Collectors.toList()); + } + private List performDeletionWorkflow( Entry> userInactiveGroupEntry) { @@ -73,7 +90,7 @@ private List performDeletionWorkflow( .deletionSourceType(ASKER) .deletionTargetType(ALL) .identifier(userInactiveGroupEntry.getKey()) - .reason("User could not be found.") + .reason(USER_NOT_FOUND_REASON) .timestamp(nowInUtc()) .build())); @@ -115,7 +132,7 @@ private List performSessionDeletion( .deletionSourceType(ASKER) .deletionTargetType(ALL) .identifier(rcGroupId) - .reason("Session with rc group id could not be found.") + .reason(RC_SESSION_GROUP_NOT_FOUND_REASON) .timestamp(nowInUtc()) .build())); diff --git a/src/test/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserServiceTest.java b/src/test/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserServiceTest.java index b37e5a10c..32ef31d2f 100644 --- a/src/test/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserServiceTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserServiceTest.java @@ -30,6 +30,7 @@ public class DeleteInactiveSessionsAndUserServiceTest { @InjectMocks private DeleteInactiveSessionsAndUserService deleteInactiveSessionsAndUserService; + @Mock private WorkflowErrorMailService workflowErrorMailService; @Mock private WorkflowErrorLogService workflowErrorLogService; @Mock private UserRepository userRepository; @Mock private SessionRepository sessionRepository; @@ -38,7 +39,8 @@ public class DeleteInactiveSessionsAndUserServiceTest { @Mock private InactivePrivateGroupsProvider inactivePrivateGroupsProvider; @Test - public void deleteInactiveSessionsAndUsers_Should_SendWorkflowErrorsMail() { + public void + deleteInactiveSessionsAndUsers_Should_SendWorkflowErrorsMail_When_userNotFoundReason() { EasyRandom easyRandom = new EasyRandom(); User user = easyRandom.nextObject(User.class); @@ -60,7 +62,8 @@ public void deleteInactiveSessionsAndUsers_Should_SendWorkflowErrorsMail() { deleteInactiveSessionsAndUserService.deleteInactiveSessionsAndUsers(); - verify(workflowErrorLogService, Mockito.times(1)).logWorkflowErrors(any()); + verify(workflowErrorLogService, Mockito.times(1)).logWorkflowErrors(Collections.emptyList()); + verify(workflowErrorMailService, Mockito.times(1)).buildAndSendErrorMail(any()); } @Test @@ -115,7 +118,7 @@ public void deleteInactiveSessionsAndUsers_Should_SendWorkflowErrorsMail() { @Test public void - deleteInactiveSessionsAndUsers_Should_SendWorkflowErrorMail_WhenUserHasActiveAndInactiveSessionsAndHasErrors() { + deleteInactiveSessionsAndUsers_Should_logWorkflowErrorMail_WhenUserHasActiveAndInactiveSessionsAndHasErrors() { EasyRandom easyRandom = new EasyRandom(); User user = easyRandom.nextObject(User.class); @@ -139,6 +142,8 @@ public void deleteInactiveSessionsAndUsers_Should_SendWorkflowErrorsMail() { deleteInactiveSessionsAndUserService.deleteInactiveSessionsAndUsers(); verify(workflowErrorLogService, Mockito.times(1)).logWorkflowErrors(any()); + verify(workflowErrorMailService, Mockito.times(1)) + .buildAndSendErrorMail(Collections.emptyList()); } @Test @@ -165,6 +170,8 @@ public void deleteInactiveSessionsAndUsers_Should_SendWorkflowErrorsMail() { deleteInactiveSessionsAndUserService.deleteInactiveSessionsAndUsers(); verify(workflowErrorLogService, Mockito.times(1)).logWorkflowErrors(any()); + verify(workflowErrorMailService, Mockito.times(1)) + .buildAndSendErrorMail(Collections.emptyList()); } @Test @@ -187,6 +194,7 @@ public void deleteInactiveSessionsAndUsers_Should_SendWorkflowErrorsMail() { deleteInactiveSessionsAndUserService.deleteInactiveSessionsAndUsers(); - verify(workflowErrorLogService, Mockito.times(1)).logWorkflowErrors(any()); + verify(workflowErrorLogService, Mockito.times(1)).logWorkflowErrors(Collections.emptyList()); + verify(workflowErrorMailService, Mockito.times(1)).buildAndSendErrorMail(any()); } } From 51cd46299495d94a0cf6a3272d010d56b63ffa6d Mon Sep 17 00:00:00 2001 From: LeandroSilva Date: Wed, 8 May 2024 16:03:15 +0200 Subject: [PATCH 3/5] fix: * Rename method as per PR comment --- .../delete/service/DeleteInactiveSessionsAndUserService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserService.java b/src/main/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserService.java index c099aa042..6a1654453 100644 --- a/src/main/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserService.java +++ b/src/main/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserService.java @@ -54,10 +54,10 @@ public void deleteInactiveSessionsAndUsers() { .flatMap(Collection::stream) .collect(Collectors.toList()); - processWorkflowErrors(workflowErrors); + findWorkflowErrorByReason(workflowErrors); } - private void processWorkflowErrors(List workflowErrors) { + private void findWorkflowErrorByReason(List workflowErrors) { if (isNotEmpty(workflowErrors)) { List userNotFoundWorkflowErrors = getSameReasonWorkflowErrors(workflowErrors, USER_NOT_FOUND_REASON); From 32c861dc606e3703be607a3badc43ac3aed30e6a Mon Sep 17 00:00:00 2001 From: LeandroSilva Date: Wed, 8 May 2024 16:43:47 +0200 Subject: [PATCH 4/5] fix: * Updated code due to PR comments --- .../service/DeleteInactiveSessionsAndUserService.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserService.java b/src/main/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserService.java index 6a1654453..bebbadd2e 100644 --- a/src/main/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserService.java +++ b/src/main/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserService.java @@ -59,10 +59,12 @@ public void deleteInactiveSessionsAndUsers() { private void findWorkflowErrorByReason(List workflowErrors) { if (isNotEmpty(workflowErrors)) { - List userNotFoundWorkflowErrors = - getSameReasonWorkflowErrors(workflowErrors, USER_NOT_FOUND_REASON); List rcSessionGroupNotFoundWorkflowErrors = getSameReasonWorkflowErrors(workflowErrors, RC_SESSION_GROUP_NOT_FOUND_REASON); + List userNotFoundWorkflowErrors = + workflowErrors.stream() + .filter(rcSessionGroupError -> !workflowErrors.contains(rcSessionGroupError)) + .collect(Collectors.toList()); this.workflowErrorLogService.logWorkflowErrors(rcSessionGroupNotFoundWorkflowErrors); this.workflowErrorMailService.buildAndSendErrorMail(userNotFoundWorkflowErrors); } From 1f7162397e2a188254cdb42c85151a66d0c8098e Mon Sep 17 00:00:00 2001 From: LeandroSilva Date: Thu, 9 May 2024 09:48:07 +0200 Subject: [PATCH 5/5] fix: * Updated code and tests due to PR comments --- .../DeleteInactiveSessionsAndUserService.java | 9 +++--- ...eteInactiveSessionsAndUserServiceTest.java | 28 ++++++++++++++----- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserService.java b/src/main/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserService.java index bebbadd2e..83d49f609 100644 --- a/src/main/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserService.java +++ b/src/main/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserService.java @@ -61,12 +61,11 @@ private void findWorkflowErrorByReason(List workflowError if (isNotEmpty(workflowErrors)) { List rcSessionGroupNotFoundWorkflowErrors = getSameReasonWorkflowErrors(workflowErrors, RC_SESSION_GROUP_NOT_FOUND_REASON); - List userNotFoundWorkflowErrors = - workflowErrors.stream() - .filter(rcSessionGroupError -> !workflowErrors.contains(rcSessionGroupError)) - .collect(Collectors.toList()); + List workflowErrorsExceptSessionGroupNotFound = + new ArrayList<>(workflowErrors); + workflowErrorsExceptSessionGroupNotFound.removeAll(rcSessionGroupNotFoundWorkflowErrors); this.workflowErrorLogService.logWorkflowErrors(rcSessionGroupNotFoundWorkflowErrors); - this.workflowErrorMailService.buildAndSendErrorMail(userNotFoundWorkflowErrors); + this.workflowErrorMailService.buildAndSendErrorMail(workflowErrorsExceptSessionGroupNotFound); } } diff --git a/src/test/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserServiceTest.java b/src/test/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserServiceTest.java index 32ef31d2f..92b1a151e 100644 --- a/src/test/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserServiceTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/workflow/delete/service/DeleteInactiveSessionsAndUserServiceTest.java @@ -1,7 +1,10 @@ package de.caritas.cob.userservice.api.workflow.delete.service; -import static org.mockito.ArgumentMatchers.any; +import static de.caritas.cob.userservice.api.helper.CustomLocalDateTime.nowInUtc; +import static de.caritas.cob.userservice.api.workflow.delete.model.DeletionSourceType.ASKER; +import static de.caritas.cob.userservice.api.workflow.delete.model.DeletionTargetType.ALL; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -63,7 +66,8 @@ public class DeleteInactiveSessionsAndUserServiceTest { deleteInactiveSessionsAndUserService.deleteInactiveSessionsAndUsers(); verify(workflowErrorLogService, Mockito.times(1)).logWorkflowErrors(Collections.emptyList()); - verify(workflowErrorMailService, Mockito.times(1)).buildAndSendErrorMail(any()); + verify(workflowErrorMailService, Mockito.times(1)) + .buildAndSendErrorMail(argThat(list -> !list.isEmpty())); } @Test @@ -135,20 +139,28 @@ public class DeleteInactiveSessionsAndUserServiceTest { when(userRepository.findByRcUserIdAndDeleteDateIsNull(anyString())) .thenReturn(Optional.of(user)); when(sessionRepository.findByUser(user)).thenReturn(Arrays.asList(session1, session2)); - DeletionWorkflowError deletionWorkflowError = Mockito.mock(DeletionWorkflowError.class); + DeletionWorkflowError deletionWorkflowError = + DeletionWorkflowError.builder() + .deletionSourceType(ASKER) + .deletionTargetType(ALL) + .identifier(null) + .reason("Session with rc group id could not be found.") + .timestamp(nowInUtc()) + .build(); when(deleteSessionService.performSessionDeletion(session1)) .thenReturn(Collections.singletonList(deletionWorkflowError)); deleteInactiveSessionsAndUserService.deleteInactiveSessionsAndUsers(); - verify(workflowErrorLogService, Mockito.times(1)).logWorkflowErrors(any()); + verify(workflowErrorLogService, Mockito.times(1)) + .logWorkflowErrors(argThat(list -> !list.isEmpty())); verify(workflowErrorMailService, Mockito.times(1)) .buildAndSendErrorMail(Collections.emptyList()); } @Test public void - deleteInactiveSessionsAndUsers_Should_SendWorkflowErrorMail_WhenSessionCouldNotBeFound() { + deleteInactiveSessionsAndUsers_Should_logWorkflowErrorMail_WhenSessionCouldNotBeFound() { EasyRandom easyRandom = new EasyRandom(); User user = easyRandom.nextObject(User.class); @@ -169,7 +181,8 @@ public class DeleteInactiveSessionsAndUserServiceTest { deleteInactiveSessionsAndUserService.deleteInactiveSessionsAndUsers(); - verify(workflowErrorLogService, Mockito.times(1)).logWorkflowErrors(any()); + verify(workflowErrorLogService, Mockito.times(1)) + .logWorkflowErrors(argThat(list -> !list.isEmpty())); verify(workflowErrorMailService, Mockito.times(1)) .buildAndSendErrorMail(Collections.emptyList()); } @@ -195,6 +208,7 @@ public class DeleteInactiveSessionsAndUserServiceTest { deleteInactiveSessionsAndUserService.deleteInactiveSessionsAndUsers(); verify(workflowErrorLogService, Mockito.times(1)).logWorkflowErrors(Collections.emptyList()); - verify(workflowErrorMailService, Mockito.times(1)).buildAndSendErrorMail(any()); + verify(workflowErrorMailService, Mockito.times(1)) + .buildAndSendErrorMail(argThat(list -> !list.isEmpty())); } }