Skip to content
Snippets Groups Projects
Commit 19e3a382 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-2626 OZG-3065 handle validation inline

parent 73dca533
No related branches found
No related tags found
No related merge requests found
package de.itvsh.kop.notification.user; package de.itvsh.kop.notification.user;
import java.util.List; import java.util.List;
import java.util.Objects;
import javax.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
...@@ -24,8 +24,12 @@ public class UserNotificationService { ...@@ -24,8 +24,12 @@ public class UserNotificationService {
@Autowired @Autowired
private UserRemoteService userRemoteService; private UserRemoteService userRemoteService;
public void sendNotification(@NotNull String organisationEinheitId) { @Async
var recipients = userRemoteService.getRecipients(organisationEinheitId); 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)); emailRemoteService.sendEmail(buildUserEmail(recipients));
} }
......
package de.itvsh.kop.notification.user; package de.itvsh.kop.notification.user;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*; import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
...@@ -31,9 +32,9 @@ class UserNotificationServiceTest { ...@@ -31,9 +32,9 @@ class UserNotificationServiceTest {
@Nested @Nested
class TestSendNotification { class TestSendNotification {
@DisplayName("with valid orgaIds") @DisplayName("with valid orgaId")
@Nested @Nested
class TestWithValidOrgaIds { class TestWithValidOrgaId {
@BeforeEach @BeforeEach
void init() { void init() {
...@@ -55,5 +56,31 @@ class UserNotificationServiceTest { ...@@ -55,5 +56,31 @@ class UserNotificationServiceTest {
verify(emailRemoteService).sendEmail(UserEmailTestFactory.create()); 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment