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
Branches
Tags
No related merge requests found
......@@ -61,6 +61,10 @@
</dependency>
<!-- tools -->
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
......
......@@ -2,12 +2,17 @@ package de.itvsh.kop.notification.user;
import java.util.List;
import javax.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import de.itvsh.kop.notification.email.EmailRemoteService;
import de.itvsh.kop.notification.email.UserEmail;
@Validated
@Service
public class UserNotificationService {
......@@ -20,8 +25,9 @@ public class UserNotificationService {
@Autowired
private UserRemoteService userRemoteService;
public void sendNotification(String organisationeinheitId) {
var recipients = userRemoteService.getRecipients(organisationeinheitId);
@Async
public void sendNotification(@NotNull String organisationEinheitId) {
var recipients = userRemoteService.getRecipients(organisationEinheitId);
emailRemoteService.sendEmail(buildUserEmail(recipients));
}
......
package de.itvsh.kop.notification.user;
import de.itvsh.kop.notification.email.EmailRemoteService;
import de.itvsh.kop.notification.email.UserEmail;
import de.itvsh.kop.notification.email.UserEmailTestFactory;
import de.itvsh.kop.notification.vorgang.VorgangTestFactory;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
......@@ -11,45 +12,48 @@ import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import java.util.List;
import static org.mockito.Mockito.*;
import de.itvsh.kop.notification.email.EmailRemoteService;
import de.itvsh.kop.notification.email.UserEmail;
import de.itvsh.kop.notification.email.UserEmailTestFactory;
import de.itvsh.kop.notification.vorgang.VorgangTestFactory;
class UserNotificationServiceTest {
@InjectMocks
private UserNotificationService userNotificationService;
private UserNotificationService service;
@Mock
private EmailRemoteService emailRemoteService;
@Mock
private UserRemoteService userRemoteService;
@DisplayName("Notify")
@DisplayName("Send notification")
@Nested
class TestOnNotify {
class TestSendNotification {
private static final List<Recipient> RECIPIENTS = List.of(RecipientTestFactory.create());
private static final String ORGANISATIONEINCHEIT_ID = VorgangTestFactory.ORGANISATIONEINCHEIT_ID;
private static final UserEmail USER_EMAIL = UserEmailTestFactory.create();
@DisplayName("with valid orgaIds")
@Nested
class TestWithValidOrgaIds {
@BeforeEach
void init() {
when(userRemoteService.getRecipients(ORGANISATIONEINCHEIT_ID)).thenReturn(RECIPIENTS);
}
@BeforeEach
void init() {
when(userRemoteService.getRecipients(VorgangTestFactory.ORGANISATIONEINCHEIT_ID)).thenReturn(List.of(RecipientTestFactory.create()));
doNothing().when(emailRemoteService).sendEmail(any(UserEmail.class));
}
@Test
void shouldGetRecipients() {
userNotificationService.sendNotification(ORGANISATIONEINCHEIT_ID);
@Test
void shouldGetRecipients() {
service.sendNotification(VorgangTestFactory.ORGANISATIONEINCHEIT_ID);
verify(userRemoteService).getRecipients(ORGANISATIONEINCHEIT_ID);
}
verify(userRemoteService).getRecipients(VorgangTestFactory.ORGANISATIONEINCHEIT_ID);
}
@Test
void shouldSendEmail() {
userNotificationService.sendNotification(ORGANISATIONEINCHEIT_ID);
@Test
void shouldSendEmail() {
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