Skip to content
Snippets Groups Projects
Commit 9b26f300 authored by OZGCloud's avatar OZGCloud
Browse files

Merge pull request 'OZG-3841: Vorgangsname in E-Mail' (#191) from...

Merge pull request 'OZG-3841: Vorgangsname in E-Mail' (#191) from OZG-3841-Vorgangsname-in-EMail into master

Reviewed-on: https://git.ozg-sh.de/mgm/pluto/pulls/191


Reviewed-by: default avatarOZGCloud <ozgcloud@mgm-tp.com>
parents 109c0875 a16b5fac
No related branches found
No related tags found
No related merge requests found
...@@ -23,8 +23,6 @@ ...@@ -23,8 +23,6 @@
*/ */
package de.itvsh.kop.notification.user; package de.itvsh.kop.notification.user;
import java.util.Objects;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener; import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -44,10 +42,6 @@ public class UserNotificationEventListener { ...@@ -44,10 +42,6 @@ public class UserNotificationEventListener {
@EventListener @EventListener
public void onVorgangCreated(VorgangCreatedEvent event) { public void onVorgangCreated(VorgangCreatedEvent event) {
var organisationsEinheitId = vorgangService.getVorgang(VorgangId.from(event.getSource())).getOrganisationseinheitenId(); userNotificationService.sendNotification(vorgangService.getVorgang(VorgangId.from(event.getSource())));
if (Objects.nonNull(organisationsEinheitId)) {
userNotificationService.sendNotification(organisationsEinheitId);
}
} }
} }
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
*/ */
package de.itvsh.kop.notification.user; package de.itvsh.kop.notification.user;
import static java.util.Objects.*;
import java.util.List; import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -31,12 +33,13 @@ import org.springframework.stereotype.Service; ...@@ -31,12 +33,13 @@ import org.springframework.stereotype.Service;
import de.itvsh.kop.notification.email.EmailRemoteService; import de.itvsh.kop.notification.email.EmailRemoteService;
import de.itvsh.kop.notification.email.UserEmail; import de.itvsh.kop.notification.email.UserEmail;
import de.itvsh.kop.notification.vorgang.Vorgang;
import lombok.NonNull; import lombok.NonNull;
@Service @Service
public class UserNotificationService { public class UserNotificationService {
public static final String MAIL_SUBJECT = "Neuer Vorgang"; public static final String MAIL_SUBJECT_TEMPLATE = "Neuer Vorgang: %s";
public static final String MAIL_BODY = "Es ist ein neuer Vorgang im Allgemeinen Fachverfahren eingegangen."; public static final String MAIL_BODY = "Es ist ein neuer Vorgang im Allgemeinen Fachverfahren eingegangen.";
@Autowired @Autowired
...@@ -46,12 +49,14 @@ public class UserNotificationService { ...@@ -46,12 +49,14 @@ public class UserNotificationService {
private UserRemoteService userRemoteService; private UserRemoteService userRemoteService;
@Async @Async
public void sendNotification(@NonNull String organisationsEinheitId) { public void sendNotification(@NonNull Vorgang vorgang) {
var recipients = userRemoteService.getRecipients(organisationsEinheitId); if (nonNull(vorgang.getOrganisationseinheitenId())) {
emailRemoteService.sendEmail(buildUserEmail(recipients)); var recipients = userRemoteService.getRecipients(vorgang.getOrganisationseinheitenId());
emailRemoteService.sendEmail(buildUserEmail(recipients, MAIL_SUBJECT_TEMPLATE.formatted(vorgang.getVorgangName())));
}
} }
private UserEmail buildUserEmail(List<Recipient> recipients) { UserEmail buildUserEmail(List<Recipient> recipients, String subject) {
return UserEmail.builder().recipients(recipients).subject(MAIL_SUBJECT).body(MAIL_BODY).build(); return UserEmail.builder().recipients(recipients).subject(subject).body(MAIL_BODY).build();
} }
} }
\ No newline at end of file
...@@ -23,12 +23,13 @@ ...@@ -23,12 +23,13 @@
*/ */
package de.itvsh.kop.notification.email; package de.itvsh.kop.notification.email;
import java.util.List;
import de.itvsh.kop.notification.email.UserEmail.UserEmailBuilder; import de.itvsh.kop.notification.email.UserEmail.UserEmailBuilder;
import de.itvsh.kop.notification.user.Recipient; import de.itvsh.kop.notification.user.Recipient;
import de.itvsh.kop.notification.user.UserNotificationService;
import de.itvsh.kop.notification.user.RecipientTestFactory; import de.itvsh.kop.notification.user.RecipientTestFactory;
import de.itvsh.kop.notification.user.UserNotificationService;
import java.util.List; import de.itvsh.kop.notification.vorgang.VorgangTestFactory;
public class UserEmailTestFactory { public class UserEmailTestFactory {
...@@ -41,7 +42,7 @@ public class UserEmailTestFactory { ...@@ -41,7 +42,7 @@ public class UserEmailTestFactory {
public static UserEmailBuilder createBuilder() { public static UserEmailBuilder createBuilder() {
return UserEmail.builder() return UserEmail.builder()
.recipients(RECIPIENTS) .recipients(RECIPIENTS)
.subject(UserNotificationService.MAIL_SUBJECT) .subject(UserNotificationService.MAIL_SUBJECT_TEMPLATE.formatted(VorgangTestFactory.VORGANG_NAME))
.body(UserNotificationService.MAIL_BODY); .body(UserNotificationService.MAIL_BODY);
} }
} }
...@@ -72,27 +72,14 @@ class UserNotificationEventListenerTest { ...@@ -72,27 +72,14 @@ class UserNotificationEventListenerTest {
@Test @Test
void shouldNotifyWithOrganisationeinheitIds() { void shouldNotifyWithOrganisationeinheitIds() {
userNotificationEventListener.onVorgangCreated(EVENT); var vorgang = VorgangTestFactory.create();
when(vorgangService.getVorgang(any())).thenReturn(vorgang);
verify(userNotificationService).sendNotification(VorgangTestFactory.ORGANISATIONS_EINHEIT_ID);
}
}
@DisplayName("with missing orgaId")
@Nested
class TestWithoutOrgaId {
@BeforeEach
void initMock() {
when(vorgangService.getVorgang(any())).thenReturn(VorgangTestFactory.createBuilder().organisationseinheitenId(null).build());
}
@Test
void shouldNotCallNotificationService() {
userNotificationEventListener.onVorgangCreated(EVENT); userNotificationEventListener.onVorgangCreated(EVENT);
verifyNoInteractions(userNotificationService); verify(userNotificationService).sendNotification(vorgang);
} }
} }
} }
} }
\ No newline at end of file
...@@ -35,14 +35,17 @@ import org.junit.jupiter.api.Nested; ...@@ -35,14 +35,17 @@ import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Spy;
import de.itvsh.kop.notification.email.EmailRemoteService; import de.itvsh.kop.notification.email.EmailRemoteService;
import de.itvsh.kop.notification.email.UserEmail; import de.itvsh.kop.notification.email.UserEmail;
import de.itvsh.kop.notification.email.UserEmailTestFactory; import de.itvsh.kop.notification.email.UserEmailTestFactory;
import de.itvsh.kop.notification.vorgang.Vorgang;
import de.itvsh.kop.notification.vorgang.VorgangTestFactory; import de.itvsh.kop.notification.vorgang.VorgangTestFactory;
class UserNotificationServiceTest { class UserNotificationServiceTest {
@Spy
@InjectMocks @InjectMocks
private UserNotificationService service; private UserNotificationService service;
...@@ -67,16 +70,27 @@ class UserNotificationServiceTest { ...@@ -67,16 +70,27 @@ class UserNotificationServiceTest {
@Test @Test
void shouldGetRecipients() { void shouldGetRecipients() {
service.sendNotification(VorgangTestFactory.ORGANISATIONS_EINHEIT_ID); service.sendNotification(VorgangTestFactory.create());
verify(userRemoteService).getRecipients(VorgangTestFactory.ORGANISATIONS_EINHEIT_ID); verify(userRemoteService).getRecipients(VorgangTestFactory.ORGANISATIONS_EINHEIT_ID);
} }
@Test @Test
void shouldSendEmail() { void shouldSendEmail() {
service.sendNotification(VorgangTestFactory.ORGANISATIONS_EINHEIT_ID); var email = UserEmailTestFactory.create();
doReturn(email).when(service).buildUserEmail(anyList(), anyString());
service.sendNotification(VorgangTestFactory.create());
verify(emailRemoteService).sendEmail(email);
}
@Test
void shouldSetSubject() {
service.sendNotification(VorgangTestFactory.create());
verify(service).buildUserEmail(anyList(), eq("Neuer Vorgang: " + VorgangTestFactory.VORGANG_NAME));
verify(emailRemoteService).sendEmail(UserEmailTestFactory.create());
} }
} }
...@@ -84,26 +98,28 @@ class UserNotificationServiceTest { ...@@ -84,26 +98,28 @@ class UserNotificationServiceTest {
@Nested @Nested
class TestWithInvalidOrgaId { class TestWithInvalidOrgaId {
@Test private Vorgang vorgang = VorgangTestFactory.createBuilder().organisationseinheitenId(null).build();
void shouldThrowIllegalArgumentException() {
assertThatThrownBy(() -> service.sendNotification(null))
.isInstanceOf(IllegalArgumentException.class)
.withFailMessage("organisationsEinheitId cannot be null.");
}
@Test @Test
void shouldNotCallUserRemoteService() { void shouldNotCallUserRemoteService() {
assertThatThrownBy(() -> service.sendNotification(null)); service.sendNotification(vorgang);
verify(userRemoteService, never()).getRecipients(anyString()); verify(userRemoteService, never()).getRecipients(anyString());
} }
@Test @Test
void shouldNotCallEmailRemoteSErvie() { void shouldNotCallEmailRemoteServie() {
assertThatThrownBy(() -> service.sendNotification(null)); service.sendNotification(vorgang);
verify(emailRemoteService, never()).sendEmail(any(UserEmail.class)); verify(emailRemoteService, never()).sendEmail(any(UserEmail.class));
} }
} }
@Test
void shouldThrowExceptionWhenVorgangNull() {
assertThatThrownBy(() -> service.sendNotification(null))
.withFailMessage("organisationsEinheitId cannot be null.")
.isInstanceOf(IllegalArgumentException.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