From 19e3a382b9bd06dcb2175604fc6ed5a799726f21 Mon Sep 17 00:00:00 2001 From: OZGCloud <ozgcloud@mgm-tp.com> Date: Mon, 31 Oct 2022 09:28:24 +0100 Subject: [PATCH] OZG-2626 OZG-3065 handle validation inline --- .../user/UserNotificationService.java | 12 ++++--- .../user/UserNotificationServiceTest.java | 31 +++++++++++++++++-- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/notification-manager/src/main/java/de/itvsh/kop/notification/user/UserNotificationService.java b/notification-manager/src/main/java/de/itvsh/kop/notification/user/UserNotificationService.java index 88d2070ce..95cb74ff2 100644 --- a/notification-manager/src/main/java/de/itvsh/kop/notification/user/UserNotificationService.java +++ b/notification-manager/src/main/java/de/itvsh/kop/notification/user/UserNotificationService.java @@ -1,10 +1,10 @@ package de.itvsh.kop.notification.user; import java.util.List; - -import javax.validation.constraints.NotNull; +import java.util.Objects; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -24,8 +24,12 @@ public class UserNotificationService { @Autowired private UserRemoteService userRemoteService; - public void sendNotification(@NotNull String organisationEinheitId) { - var recipients = userRemoteService.getRecipients(organisationEinheitId); + @Async + public void sendNotification(String organisationsEinheitId) { + if (Objects.isNull(organisationsEinheitId)) { + throw new IllegalArgumentException("organisationsEinheitId cannot be null."); + } + var recipients = userRemoteService.getRecipients(organisationsEinheitId); emailRemoteService.sendEmail(buildUserEmail(recipients)); } diff --git a/notification-manager/src/test/java/de/itvsh/kop/notification/user/UserNotificationServiceTest.java b/notification-manager/src/test/java/de/itvsh/kop/notification/user/UserNotificationServiceTest.java index 463469928..37dd2dc08 100644 --- a/notification-manager/src/test/java/de/itvsh/kop/notification/user/UserNotificationServiceTest.java +++ b/notification-manager/src/test/java/de/itvsh/kop/notification/user/UserNotificationServiceTest.java @@ -1,5 +1,6 @@ package de.itvsh.kop.notification.user; +import static org.assertj.core.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; @@ -31,9 +32,9 @@ class UserNotificationServiceTest { @Nested class TestSendNotification { - @DisplayName("with valid orgaIds") + @DisplayName("with valid orgaId") @Nested - class TestWithValidOrgaIds { + class TestWithValidOrgaId { @BeforeEach void init() { @@ -55,5 +56,31 @@ class UserNotificationServiceTest { verify(emailRemoteService).sendEmail(UserEmailTestFactory.create()); } } + + @DisplayName("with valid orgaId") + @Nested + class TestWithInValidOrgaId { + + @Test + void shouldSendEmail() { + assertThatThrownBy(() -> service.sendNotification(null)) + .isInstanceOf(IllegalArgumentException.class) + .withFailMessage("organisationsEinheitId cannot be null."); + } + + @Test + void shouldNotCallUserRemoteService() { + assertThatThrownBy(() -> service.sendNotification(null)); + + verify(userRemoteService, never()).getRecipients(anyString()); + } + + @Test + void shouldNotCallEmailRemoteSErvie() { + assertThatThrownBy(() -> service.sendNotification(null)); + + verify(emailRemoteService, never()).sendEmail(any(UserEmail.class)); + } + } } } \ No newline at end of file -- GitLab