Skip to content
Snippets Groups Projects
Commit 4965422e authored by OZGCloud's avatar OZGCloud
Browse files

OZG-2626 OZG-3065 add NotNull Validation to organisationsEinheitId

parent 0560261f
No related branches found
No related tags found
No related merge requests found
...@@ -61,6 +61,10 @@ ...@@ -61,6 +61,10 @@
</dependency> </dependency>
<!-- tools --> <!-- tools -->
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.mapstruct</groupId> <groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId> <artifactId>mapstruct</artifactId>
......
...@@ -2,12 +2,17 @@ package de.itvsh.kop.notification.user; ...@@ -2,12 +2,17 @@ package de.itvsh.kop.notification.user;
import java.util.List; import java.util.List;
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 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;
@Validated
@Service @Service
public class UserNotificationService { public class UserNotificationService {
...@@ -20,8 +25,9 @@ public class UserNotificationService { ...@@ -20,8 +25,9 @@ public class UserNotificationService {
@Autowired @Autowired
private UserRemoteService userRemoteService; private UserRemoteService userRemoteService;
public void sendNotification(String organisationeinheitId) { @Async
var recipients = userRemoteService.getRecipients(organisationeinheitId); public void sendNotification(@NotNull String organisationEinheitId) {
var recipients = userRemoteService.getRecipients(organisationEinheitId);
emailRemoteService.sendEmail(buildUserEmail(recipients)); emailRemoteService.sendEmail(buildUserEmail(recipients));
} }
......
package de.itvsh.kop.notification.user; package de.itvsh.kop.notification.user;
import de.itvsh.kop.notification.email.EmailRemoteService; import static org.mockito.ArgumentMatchers.*;
import de.itvsh.kop.notification.email.UserEmail; import static org.mockito.Mockito.*;
import de.itvsh.kop.notification.email.UserEmailTestFactory;
import de.itvsh.kop.notification.vorgang.VorgangTestFactory; import java.util.List;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
...@@ -11,45 +12,48 @@ import org.junit.jupiter.api.Test; ...@@ -11,45 +12,48 @@ import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import java.util.List; import de.itvsh.kop.notification.email.EmailRemoteService;
import de.itvsh.kop.notification.email.UserEmail;
import static org.mockito.Mockito.*; import de.itvsh.kop.notification.email.UserEmailTestFactory;
import de.itvsh.kop.notification.vorgang.VorgangTestFactory;
class UserNotificationServiceTest { class UserNotificationServiceTest {
@InjectMocks @InjectMocks
private UserNotificationService userNotificationService; private UserNotificationService service;
@Mock @Mock
private EmailRemoteService emailRemoteService; private EmailRemoteService emailRemoteService;
@Mock @Mock
private UserRemoteService userRemoteService; private UserRemoteService userRemoteService;
@DisplayName("Notify") @DisplayName("Send notification")
@Nested @Nested
class TestOnNotify { class TestSendNotification {
private static final List<Recipient> RECIPIENTS = List.of(RecipientTestFactory.create()); @DisplayName("with valid orgaIds")
private static final String ORGANISATIONEINCHEIT_ID = VorgangTestFactory.ORGANISATIONEINCHEIT_ID; @Nested
private static final UserEmail USER_EMAIL = UserEmailTestFactory.create(); class TestWithValidOrgaIds {
@BeforeEach @BeforeEach
void init() { void init() {
when(userRemoteService.getRecipients(ORGANISATIONEINCHEIT_ID)).thenReturn(RECIPIENTS); when(userRemoteService.getRecipients(VorgangTestFactory.ORGANISATIONEINCHEIT_ID)).thenReturn(List.of(RecipientTestFactory.create()));
doNothing().when(emailRemoteService).sendEmail(any(UserEmail.class));
} }
@Test @Test
void shouldGetRecipients() { void shouldGetRecipients() {
userNotificationService.sendNotification(ORGANISATIONEINCHEIT_ID); service.sendNotification(VorgangTestFactory.ORGANISATIONEINCHEIT_ID);
verify(userRemoteService).getRecipients(ORGANISATIONEINCHEIT_ID); verify(userRemoteService).getRecipients(VorgangTestFactory.ORGANISATIONEINCHEIT_ID);
} }
@Test @Test
void shouldSendEmail() { void shouldSendEmail() {
userNotificationService.sendNotification(ORGANISATIONEINCHEIT_ID); service.sendNotification(VorgangTestFactory.ORGANISATIONEINCHEIT_ID);
verify(emailRemoteService).sendEmail(USER_EMAIL); verify(emailRemoteService).sendEmail(UserEmailTestFactory.create());
}
} }
} }
} }
\ No newline at end of file
package de.itvsh.ozg.pluto.vorgang;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import javax.validation.ConstraintViolationException;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.security.test.context.support.WithMockUser;
import de.itvsh.kop.common.test.DataITCase;
import de.itvsh.kop.notification.user.UserNotificationEventListener;
import de.itvsh.kop.notification.vorgang.Vorgang;
import de.itvsh.kop.notification.vorgang.VorgangId;
import de.itvsh.kop.notification.vorgang.VorgangService;
import de.itvsh.ozg.pluto.command.VorgangCreatedEvent;
@DataITCase
@WithMockUser
public class UserNotificationITCase {
@Autowired
private UserNotificationEventListener notificationListener;
@MockBean
private VorgangService vorgangService;
@DisplayName("Send notification")
@Nested
class TestSendNotification {
@Test
void shouldThrowConstraintViolationExceptionOnMissingOrgaIds() {
when(vorgangService.getVorgang(any(VorgangId.class))).thenReturn(Vorgang.builder().organisationseinheitenId(null).build());
var vorgangCreatedEvent = new VorgangCreatedEvent(VorgangTestFactory.ID.toString());
assertThatThrownBy(() -> notificationListener.onVorgangCreated(vorgangCreatedEvent)).isInstanceOf(ConstraintViolationException.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