From 8834868a4a366e5dea1f0eb647769993f62755ea Mon Sep 17 00:00:00 2001 From: Hassan Matout Date: Mon, 25 Nov 2024 01:19:16 +0100 Subject: [PATCH 1/5] Development: Add an abstract testing class for the purpose of testing mail content generated from thymeleaf templates --- .../service/mail/AbstractMailContentTest.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/AbstractMailContentTest.java diff --git a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/AbstractMailContentTest.java b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/AbstractMailContentTest.java new file mode 100644 index 000000000000..44f58bb8af1b --- /dev/null +++ b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/AbstractMailContentTest.java @@ -0,0 +1,61 @@ +package de.tum.cit.aet.artemis.communication.notifications.service.mail; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.Mockito.verify; + +import org.junit.jupiter.api.BeforeEach; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.MessageSource; +import org.thymeleaf.spring6.SpringTemplateEngine; + +import de.tum.cit.aet.artemis.communication.service.notifications.MailSendingService; +import de.tum.cit.aet.artemis.communication.service.notifications.MailService; +import de.tum.cit.aet.artemis.core.domain.User; +import de.tum.cit.aet.artemis.core.service.TimeService; +import de.tum.cit.aet.artemis.shared.base.AbstractSpringIntegrationIndependentTest; + +/** + * Abstract class for testing mail content and the correct usage of DTO attributes in the mail content. + */ +class AbstractMailContentTest extends AbstractSpringIntegrationIndependentTest { + + protected MailService mailService; + + @Mock + protected MailSendingService mailSendingService; + + @Mock + private TimeService timeService; + + @Autowired + private SpringTemplateEngine templateEngine; + + @Autowired + private MessageSource messageSource; + + @BeforeEach + void setup() { + mailService = new MailService(messageSource, templateEngine, timeService, mailSendingService); + } + + /** + * All users attempted to receive a mail should have at least a language key set. + */ + protected User createMinimalMailRecipientUser() { + User recipient = new User(); + recipient.setLangKey("de"); + return recipient; + } + + /** + * Retrieve the content of the interpreted thymeleaf template, which represents the mail content. + */ + protected String getGeneratedEmailTemplateText() { + ArgumentCaptor contentCaptor = ArgumentCaptor.forClass(String.class); + verify(mailSendingService).sendEmail(any(), any(String.class), contentCaptor.capture(), anyBoolean(), anyBoolean()); + return contentCaptor.getValue(); + } +} From 197abad80f505043c7b95dbbbc8423f3d25741f8 Mon Sep 17 00:00:00 2001 From: Hassan Matout Date: Mon, 25 Nov 2024 16:42:27 +0100 Subject: [PATCH 2/5] Development: Make non-notification mails use DTOs instead of models, adjust thymeleaf templates and add tests --- .../notifications/MailSendingService.java | 6 +- .../service/notifications/MailService.java | 105 ++++++++++-------- .../mails/dto/IMailRecipientUserDTO.java | 15 +++ .../ActivationMailRecipientDTO.java | 11 ++ .../DataExportFailedContentDTO.java | 10 ++ ...DataExportFailedMailAdminRecipientDTO.java | 11 ++ .../DataExportSuccessfulContentDTO.java | 10 ++ .../DataExportSuccessfulContentsDTO.java | 14 +++ ...ExportSuccessfulMailAdminRecipientDTO.java | 11 ++ .../NotificationMailRecipientDTO.java | 11 ++ .../PasswordResetRecipientDTO.java | 11 ++ .../SAML2SetPasswordMailRecipientDTO.java | 11 ++ .../WeeklyExerciseSummaryDTO.java | 21 ++++ .../WeeklySummaryMailContentDTO.java | 16 +++ .../WeeklySummaryMailRecipientDTO.java | 11 ++ .../mail/dataExportFailedAdminEmail.html | 4 +- .../mail/notification/fragments.html | 2 +- .../mail/successfulDataExportsAdminEmail.html | 7 +- .../templates/mail/weeklySummary.html | 28 ++--- .../service/MailServiceTest.java | 5 +- .../service/mail/AbstractMailContentTest.java | 4 +- .../service/mail/ActivationMailTest.java | 26 +++++ .../mail/DataExportFailedMailTest.java | 35 ++++++ .../mail/DataExportSuccessfulMailTest.java | 50 +++++++++ .../service/mail/PasswordResetMailTest.java | 26 +++++ .../mail/SAML2SetPasswordMailTest.java | 26 +++++ .../service/mail/WeeklySummaryMailTest.java | 72 ++++++++++++ .../DataExportScheduleServiceTest.java | 3 +- 28 files changed, 485 insertions(+), 77 deletions(-) create mode 100644 src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/IMailRecipientUserDTO.java create mode 100644 src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/activation_mail/ActivationMailRecipientDTO.java create mode 100644 src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_failed_mail/DataExportFailedContentDTO.java create mode 100644 src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_failed_mail/DataExportFailedMailAdminRecipientDTO.java create mode 100644 src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_successful_mail/DataExportSuccessfulContentDTO.java create mode 100644 src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_successful_mail/DataExportSuccessfulContentsDTO.java create mode 100644 src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_successful_mail/DataExportSuccessfulMailAdminRecipientDTO.java create mode 100644 src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/notifications/NotificationMailRecipientDTO.java create mode 100644 src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/password_reset_mail/PasswordResetRecipientDTO.java create mode 100644 src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/saml2_set_password_mail/SAML2SetPasswordMailRecipientDTO.java create mode 100644 src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklyExerciseSummaryDTO.java create mode 100644 src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklySummaryMailContentDTO.java create mode 100644 src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklySummaryMailRecipientDTO.java create mode 100644 src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/ActivationMailTest.java create mode 100644 src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/DataExportFailedMailTest.java create mode 100644 src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/DataExportSuccessfulMailTest.java create mode 100644 src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/PasswordResetMailTest.java create mode 100644 src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/SAML2SetPasswordMailTest.java create mode 100644 src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/WeeklySummaryMailTest.java diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/MailSendingService.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/MailSendingService.java index 173aa77d7b3d..ceb009f1463b 100644 --- a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/MailSendingService.java +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/MailSendingService.java @@ -16,7 +16,7 @@ import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; -import de.tum.cit.aet.artemis.core.domain.User; +import de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.IMailRecipientUserDTO; import tech.jhipster.config.JHipsterProperties; /** @@ -47,14 +47,14 @@ public MailSendingService(JHipsterProperties jHipsterProperties, JavaMailSender * @param isHtml Whether the mail should support HTML tags */ @Async - public void sendEmail(User recipient, String subject, String content, boolean isMultipart, boolean isHtml) { + public void sendEmail(IMailRecipientUserDTO recipient, String subject, String content, boolean isMultipart, boolean isHtml) { log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}'", isMultipart, isHtml, recipient, subject); // Prepare message using a Spring helper MimeMessage mimeMessage = javaMailSender.createMimeMessage(); try { MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, StandardCharsets.UTF_8.name()); - message.setTo(recipient.getEmail()); + message.setTo(recipient.email()); message.setFrom(jHipsterProperties.getMail().getFrom()); message.setSubject(subject); message.setText(content, isHtml); diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/MailService.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/MailService.java index fc6f7e9e1256..51f7460d84aa 100644 --- a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/MailService.java +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/MailService.java @@ -24,6 +24,17 @@ import de.tum.cit.aet.artemis.communication.domain.Post; import de.tum.cit.aet.artemis.communication.domain.notification.Notification; import de.tum.cit.aet.artemis.communication.domain.notification.NotificationConstants; +import de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.IMailRecipientUserDTO; +import de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.activation_mail.ActivationMailRecipientDTO; +import de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.data_export_failed_mail.DataExportFailedContentDTO; +import de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.data_export_failed_mail.DataExportFailedMailAdminRecipientDTO; +import de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.data_export_successful_mail.DataExportSuccessfulContentsDTO; +import de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.data_export_successful_mail.DataExportSuccessfulMailAdminRecipientDTO; +import de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.notifications.NotificationMailRecipientDTO; +import de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.password_reset_mail.PasswordResetRecipientDTO; +import de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.saml2_set_password_mail.SAML2SetPasswordMailRecipientDTO; +import de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.weekly_summary_mail.WeeklySummaryMailContentDTO; +import de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.weekly_summary_mail.WeeklySummaryMailRecipientDTO; import de.tum.cit.aet.artemis.core.domain.Course; import de.tum.cit.aet.artemis.core.domain.DataExport; import de.tum.cit.aet.artemis.core.domain.User; @@ -47,11 +58,9 @@ public class MailService implements InstantNotificationService { private static final String BASE_URL = "baseUrl"; - private static final String DATA_EXPORT = "dataExport"; + private static final String DATA_EXPORT_CONTENTS = "dataExportContents"; - private static final String DATA_EXPORTS = "dataExports"; - - private static final String REASON = "reason"; + private static final String DATA_EXPORT_FAILED_CONTENT = "dataExportFailedContent"; @Value("${server.url}") private URL artemisServerUrl; @@ -86,8 +95,7 @@ public class MailService implements InstantNotificationService { private static final String TIME_SERVICE = "timeService"; // weekly summary related variables - - private static final String WEEKLY_SUMMARY_NEW_EXERCISES = "weeklySummaryNewExercises"; + private static final String WEEKLY_SUMMARY_CONTENT = "weeklySummaryContent"; public MailService(MessageSource messageSource, SpringTemplateEngine templateEngine, TimeService timeService, MailSendingService mailSendingService) { this.messageSource = messageSource; @@ -99,82 +107,89 @@ public MailService(MessageSource messageSource, SpringTemplateEngine templateEng /** * Sends a predefined mail based on a template * - * @param user The receiver of the mail + * @param recipient The receiver of the mail * @param templateName The name of the template * @param titleKey The key mapping the title for the subject of the mail */ - public void sendEmailFromTemplate(User user, String templateName, String titleKey) { - Locale locale = Locale.forLanguageTag(user.getLangKey()); - Context context = createBaseContext(user, locale); - prepareTemplateAndSendEmail(user, templateName, titleKey, context); + private void sendEmailFromTemplate(IMailRecipientUserDTO recipient, String templateName, String titleKey) { + Locale locale = Locale.forLanguageTag(recipient.langKey()); + Context context = createBaseContext(recipient, locale); + prepareTemplateAndSendEmail(recipient, templateName, titleKey, context); } /** * Sends an email to a user (the internal admin user) about a failed data export creation. * - * @param admin the admin user - * @param templateName the name of the email template - * @param titleKey the subject of the email - * @param dataExport the data export that failed - * @param reason the exception that caused the data export to fail + * @param recipientAdmin the admin user + * @param templateName the name of the email template + * @param titleKey the subject of the email + * @param exportFailCaseContent the relevant information of the failed data export */ - public void sendDataExportFailedEmailForAdmin(User admin, String templateName, String titleKey, DataExport dataExport, Exception reason) { - Locale locale = Locale.forLanguageTag(admin.getLangKey()); - Context context = createBaseContext(admin, locale); - context.setVariable(DATA_EXPORT, dataExport); - context.setVariable(REASON, reason); - prepareTemplateAndSendEmailWithArgumentInSubject(admin, templateName, titleKey, dataExport.getUser().getLogin(), context); + private void sendDataExportFailedEmailForAdmin(IMailRecipientUserDTO recipientAdmin, String templateName, String titleKey, DataExportFailedContentDTO exportFailCaseContent) { + Locale locale = Locale.forLanguageTag(recipientAdmin.langKey()); + Context context = createBaseContext(recipientAdmin, locale); + context.setVariable(DATA_EXPORT_FAILED_CONTENT, exportFailCaseContent); + prepareTemplateAndSendEmailWithArgumentInSubject(recipientAdmin, templateName, titleKey, exportFailCaseContent.exportUsername(), context); } - public void sendSuccessfulDataExportsEmailToAdmin(User admin, String templateName, String titleKey, Set dataExports) { - Locale locale = Locale.forLanguageTag(admin.getLangKey()); - Context context = createBaseContext(admin, locale); - context.setVariable(DATA_EXPORTS, dataExports); - prepareTemplateAndSendEmail(admin, templateName, titleKey, context); + private void sendSuccessfulDataExportsEmailToAdmin(IMailRecipientUserDTO recipientAdmin, String templateName, String titleKey, + DataExportSuccessfulContentsDTO dataExportContents) { + Locale locale = Locale.forLanguageTag(recipientAdmin.langKey()); + Context context = createBaseContext(recipientAdmin, locale); + context.setVariable(DATA_EXPORT_CONTENTS, dataExportContents); + prepareTemplateAndSendEmail(recipientAdmin, templateName, titleKey, context); } - private void prepareTemplateAndSendEmail(User admin, String templateName, String titleKey, Context context) { + private void prepareTemplateAndSendEmail(IMailRecipientUserDTO recipient, String templateName, String titleKey, Context context) { String content = templateEngine.process(templateName, context); String subject = messageSource.getMessage(titleKey, null, context.getLocale()); - mailSendingService.sendEmail(admin, subject, content, false, true); + mailSendingService.sendEmail(recipient, subject, content, false, true); } - private void prepareTemplateAndSendEmailWithArgumentInSubject(User admin, String templateName, String titleKey, String argument, Context context) { + private void prepareTemplateAndSendEmailWithArgumentInSubject(IMailRecipientUserDTO recipient, String templateName, String titleKey, String argument, Context context) { String content = templateEngine.process(templateName, context); String subject = messageSource.getMessage(titleKey, new Object[] { argument }, context.getLocale()); - mailSendingService.sendEmail(admin, subject, content, false, true); + mailSendingService.sendEmail(recipient, subject, content, false, true); } - private Context createBaseContext(User admin, Locale locale) { + /** + * Creates a base context for the email + * + * @param recipient DTO representing the user in a given use-case + * @param locale language preference of the user + */ + private Context createBaseContext(IMailRecipientUserDTO recipient, Locale locale) { Context context = new Context(locale); - context.setVariable(USER, admin); + context.setVariable(USER, recipient); context.setVariable(BASE_URL, artemisServerUrl); return context; } public void sendActivationEmail(User user) { log.debug("Sending activation email to '{}'", user.getEmail()); - sendEmailFromTemplate(user, "mail/activationEmail", "email.activation.title"); + sendEmailFromTemplate(ActivationMailRecipientDTO.of(user), "mail/activationEmail", "email.activation.title"); } public void sendPasswordResetMail(User user) { log.debug("Sending password reset email to '{}'", user.getEmail()); - sendEmailFromTemplate(user, "mail/passwordResetEmail", "email.reset.title"); + sendEmailFromTemplate(PasswordResetRecipientDTO.of(user), "mail/passwordResetEmail", "email.reset.title"); } public void sendSAML2SetPasswordMail(User user) { log.debug("Sending SAML2 set password email to '{}'", user.getEmail()); - sendEmailFromTemplate(user, "mail/samlSetPasswordEmail", "email.saml.title"); + sendEmailFromTemplate(SAML2SetPasswordMailRecipientDTO.of(user), "mail/samlSetPasswordEmail", "email.saml.title"); } public void sendDataExportFailedEmailToAdmin(User admin, DataExport dataExport, Exception reason) { log.debug("Sending data export failed email to admin email address '{}'", admin.getEmail()); - sendDataExportFailedEmailForAdmin(admin, "mail/dataExportFailedAdminEmail", "email.dataExportFailedAdmin.title", dataExport, reason); + sendDataExportFailedEmailForAdmin(DataExportFailedMailAdminRecipientDTO.of(admin), "mail/dataExportFailedAdminEmail", "email.dataExportFailedAdmin.title", + DataExportFailedContentDTO.of(reason, dataExport)); } public void sendSuccessfulDataExportsEmailToAdmin(User admin, Set dataExports) { log.debug("Sending successful creation of data exports email to admin email address '{}'", admin.getEmail()); - sendSuccessfulDataExportsEmailToAdmin(admin, "mail/successfulDataExportsAdminEmail", "email.successfulDataExportCreationsAdmin.title", dataExports); + sendSuccessfulDataExportsEmailToAdmin(DataExportSuccessfulMailAdminRecipientDTO.of(admin), "mail/successfulDataExportsAdminEmail", + "email.successfulDataExportCreationsAdmin.title", DataExportSuccessfulContentsDTO.of(dataExports)); } // notification related @@ -224,6 +239,7 @@ public void sendNotification(Notification notification, Set users, Object * @param user who should be contacted * @param notificationSubject that is used to provide further information (e.g. exercise, attachment, post, etc.) */ + @Override public void sendNotification(Notification notification, User user, Object notificationSubject) { NotificationType notificationType = NotificationConstants.findCorrespondingNotificationType(notification.getTitle()); @@ -282,7 +298,7 @@ public void sendNotification(Notification notification, User user, Object notifi context.setVariable(BASE_URL, artemisServerUrl); String content = createContentForNotificationEmailByType(notificationType, context); - mailSendingService.sendEmail(user, subject, content, false, true); + mailSendingService.sendEmail(NotificationMailRecipientDTO.of(user), subject, content, false, true); } /** @@ -402,15 +418,12 @@ public void sendWeeklySummaryEmail(User user, Set exercises) { Locale locale = Locale.forLanguageTag(user.getLangKey()); Context context = new Context(locale); - context.setVariable(USER, user); - context.setVariable(WEEKLY_SUMMARY_NEW_EXERCISES, exercises); - - context.setVariable(TIME_SERVICE, this.timeService); - String subject = "Weekly Summary"; - context.setVariable(BASE_URL, artemisServerUrl); + context.setVariable(USER, WeeklySummaryMailRecipientDTO.of(user)); + context.setVariable(WEEKLY_SUMMARY_CONTENT, WeeklySummaryMailContentDTO.of(exercises, timeService)); + String subject = "Weekly Summary"; String content = templateEngine.process("mail/weeklySummary", context); - mailSendingService.sendEmail(user, subject, content, false, true); + mailSendingService.sendEmail(WeeklySummaryMailRecipientDTO.of(user), subject, content, false, true); } } diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/IMailRecipientUserDTO.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/IMailRecipientUserDTO.java new file mode 100644 index 000000000000..931c3c09b1e6 --- /dev/null +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/IMailRecipientUserDTO.java @@ -0,0 +1,15 @@ +package de.tum.cit.aet.artemis.communication.service.notifications.mails.dto; + +/** + * Minimal information a recipient of an email needs to provide. + */ +public interface IMailRecipientUserDTO { + + String langKey = ""; + + String email = ""; + + String langKey(); + + String email(); +} diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/activation_mail/ActivationMailRecipientDTO.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/activation_mail/ActivationMailRecipientDTO.java new file mode 100644 index 000000000000..179ff1a95804 --- /dev/null +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/activation_mail/ActivationMailRecipientDTO.java @@ -0,0 +1,11 @@ +package de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.activation_mail; + +import de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.IMailRecipientUserDTO; +import de.tum.cit.aet.artemis.core.domain.User; + +public record ActivationMailRecipientDTO(String langKey, String email, String login, String activationKey) implements IMailRecipientUserDTO { + + public static ActivationMailRecipientDTO of(User user) { + return new ActivationMailRecipientDTO(user.getLangKey(), user.getEmail(), user.getLogin(), user.getActivationKey()); + } +} diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_failed_mail/DataExportFailedContentDTO.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_failed_mail/DataExportFailedContentDTO.java new file mode 100644 index 000000000000..e67b1d297c22 --- /dev/null +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_failed_mail/DataExportFailedContentDTO.java @@ -0,0 +1,10 @@ +package de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.data_export_failed_mail; + +import de.tum.cit.aet.artemis.core.domain.DataExport; + +public record DataExportFailedContentDTO(String reason, String exportUsername) { + + public static DataExportFailedContentDTO of(Exception exception, DataExport dataExport) { + return new DataExportFailedContentDTO(exception.getMessage(), dataExport.getUser().getLogin()); + } +} diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_failed_mail/DataExportFailedMailAdminRecipientDTO.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_failed_mail/DataExportFailedMailAdminRecipientDTO.java new file mode 100644 index 000000000000..2ee29a7cafcb --- /dev/null +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_failed_mail/DataExportFailedMailAdminRecipientDTO.java @@ -0,0 +1,11 @@ +package de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.data_export_failed_mail; + +import de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.IMailRecipientUserDTO; +import de.tum.cit.aet.artemis.core.domain.User; + +public record DataExportFailedMailAdminRecipientDTO(String langKey, String email, String login) implements IMailRecipientUserDTO { + + public static DataExportFailedMailAdminRecipientDTO of(User user) { + return new DataExportFailedMailAdminRecipientDTO(user.getLangKey(), user.getEmail(), user.getLogin()); + } +} diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_successful_mail/DataExportSuccessfulContentDTO.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_successful_mail/DataExportSuccessfulContentDTO.java new file mode 100644 index 000000000000..9bec98af2b47 --- /dev/null +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_successful_mail/DataExportSuccessfulContentDTO.java @@ -0,0 +1,10 @@ +package de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.data_export_successful_mail; + +import de.tum.cit.aet.artemis.core.domain.DataExport; + +public record DataExportSuccessfulContentDTO(String userLogin) { + + public static DataExportSuccessfulContentDTO of(DataExport dataExport) { + return new DataExportSuccessfulContentDTO(dataExport.getUser().getLogin()); + } +} diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_successful_mail/DataExportSuccessfulContentsDTO.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_successful_mail/DataExportSuccessfulContentsDTO.java new file mode 100644 index 000000000000..a771831650a8 --- /dev/null +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_successful_mail/DataExportSuccessfulContentsDTO.java @@ -0,0 +1,14 @@ +package de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.data_export_successful_mail; + +import java.util.Set; +import java.util.stream.Collectors; + +import de.tum.cit.aet.artemis.core.domain.DataExport; + +public record DataExportSuccessfulContentsDTO(Set contents) { + + public static DataExportSuccessfulContentsDTO of(Set exportSet) { + Set contents = exportSet.stream().map(DataExportSuccessfulContentDTO::of).collect(Collectors.toSet()); + return new DataExportSuccessfulContentsDTO(contents); + } +} diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_successful_mail/DataExportSuccessfulMailAdminRecipientDTO.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_successful_mail/DataExportSuccessfulMailAdminRecipientDTO.java new file mode 100644 index 000000000000..7bbaf48458c9 --- /dev/null +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_successful_mail/DataExportSuccessfulMailAdminRecipientDTO.java @@ -0,0 +1,11 @@ +package de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.data_export_successful_mail; + +import de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.IMailRecipientUserDTO; +import de.tum.cit.aet.artemis.core.domain.User; + +public record DataExportSuccessfulMailAdminRecipientDTO(String langKey, String email) implements IMailRecipientUserDTO { + + public static DataExportSuccessfulMailAdminRecipientDTO of(User user) { + return new DataExportSuccessfulMailAdminRecipientDTO(user.getLangKey(), user.getEmail()); + } +} diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/notifications/NotificationMailRecipientDTO.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/notifications/NotificationMailRecipientDTO.java new file mode 100644 index 000000000000..156ad8a357d2 --- /dev/null +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/notifications/NotificationMailRecipientDTO.java @@ -0,0 +1,11 @@ +package de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.notifications; + +import de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.IMailRecipientUserDTO; +import de.tum.cit.aet.artemis.core.domain.User; + +public record NotificationMailRecipientDTO(String langKey, String email, String name, String login) implements IMailRecipientUserDTO { + + public static NotificationMailRecipientDTO of(User user) { + return new NotificationMailRecipientDTO(user.getLangKey(), user.getEmail(), user.getName(), user.getLogin()); + } +} diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/password_reset_mail/PasswordResetRecipientDTO.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/password_reset_mail/PasswordResetRecipientDTO.java new file mode 100644 index 000000000000..47199a4a546c --- /dev/null +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/password_reset_mail/PasswordResetRecipientDTO.java @@ -0,0 +1,11 @@ +package de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.password_reset_mail; + +import de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.IMailRecipientUserDTO; +import de.tum.cit.aet.artemis.core.domain.User; + +public record PasswordResetRecipientDTO(String langKey, String email, String login, String resetKey) implements IMailRecipientUserDTO { + + public static PasswordResetRecipientDTO of(User user) { + return new PasswordResetRecipientDTO(user.getLangKey(), user.getEmail(), user.getLogin(), user.getResetKey()); + } +} diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/saml2_set_password_mail/SAML2SetPasswordMailRecipientDTO.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/saml2_set_password_mail/SAML2SetPasswordMailRecipientDTO.java new file mode 100644 index 000000000000..1ce422464bf8 --- /dev/null +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/saml2_set_password_mail/SAML2SetPasswordMailRecipientDTO.java @@ -0,0 +1,11 @@ +package de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.saml2_set_password_mail; + +import de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.IMailRecipientUserDTO; +import de.tum.cit.aet.artemis.core.domain.User; + +public record SAML2SetPasswordMailRecipientDTO(String langKey, String email, String login, String resetKey) implements IMailRecipientUserDTO { + + public static SAML2SetPasswordMailRecipientDTO of(User user) { + return new SAML2SetPasswordMailRecipientDTO(user.getLangKey(), user.getEmail(), user.getLogin(), user.getResetKey()); + } +} diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklyExerciseSummaryDTO.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklyExerciseSummaryDTO.java new file mode 100644 index 000000000000..90bdf4627fdc --- /dev/null +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklyExerciseSummaryDTO.java @@ -0,0 +1,21 @@ +package de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.weekly_summary_mail; + +import de.tum.cit.aet.artemis.core.service.TimeService; +import de.tum.cit.aet.artemis.exercise.domain.Exercise; + +public record WeeklyExerciseSummaryDTO(String title, String type, String difficulty, String releaseDate, String dueDate, double maxPoints, double bonusPoints) { + + public static WeeklyExerciseSummaryDTO of(Exercise exercise, TimeService timeService) { + String releaseDate = null, dueDate = null; + if (exercise.getReleaseDate() != null) { + releaseDate = timeService.convertToHumanReadableDate(exercise.getReleaseDate()); + } + if (exercise.getDueDate() != null) { + dueDate = timeService.convertToHumanReadableDate(exercise.getDueDate()); + } + + String difficulty = exercise.getDifficulty() != null ? exercise.getDifficulty().toString() : null; + + return new WeeklyExerciseSummaryDTO(exercise.getTitle(), exercise.getType(), difficulty, releaseDate, dueDate, exercise.getMaxPoints(), exercise.getBonusPoints()); + } +} diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklySummaryMailContentDTO.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklySummaryMailContentDTO.java new file mode 100644 index 000000000000..5f4365d16aee --- /dev/null +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklySummaryMailContentDTO.java @@ -0,0 +1,16 @@ +package de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.weekly_summary_mail; + +import java.util.Set; +import java.util.stream.Collectors; + +import de.tum.cit.aet.artemis.core.service.TimeService; +import de.tum.cit.aet.artemis.exercise.domain.Exercise; + +public record WeeklySummaryMailContentDTO(boolean hasNewExercises, Set exerciseSummaries) { + + public static WeeklySummaryMailContentDTO of(Set exercises, TimeService timeService) { + boolean hasNewExercises = !exercises.isEmpty(); + Set exerciseSummaries = exercises.stream().map(exercise -> WeeklyExerciseSummaryDTO.of(exercise, timeService)).collect(Collectors.toSet()); + return new WeeklySummaryMailContentDTO(hasNewExercises, exerciseSummaries); + } +} diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklySummaryMailRecipientDTO.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklySummaryMailRecipientDTO.java new file mode 100644 index 000000000000..5bc6c2a18550 --- /dev/null +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklySummaryMailRecipientDTO.java @@ -0,0 +1,11 @@ +package de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.weekly_summary_mail; + +import de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.IMailRecipientUserDTO; +import de.tum.cit.aet.artemis.core.domain.User; + +public record WeeklySummaryMailRecipientDTO(String langKey, String email, String name) implements IMailRecipientUserDTO { + + public static WeeklySummaryMailRecipientDTO of(User user) { + return new WeeklySummaryMailRecipientDTO(user.getLangKey(), user.getEmail(), user.getName()); + } +} diff --git a/src/main/resources/templates/mail/dataExportFailedAdminEmail.html b/src/main/resources/templates/mail/dataExportFailedAdminEmail.html index 14d68464eac7..e5f134dbee7d 100644 --- a/src/main/resources/templates/mail/dataExportFailedAdminEmail.html +++ b/src/main/resources/templates/mail/dataExportFailedAdminEmail.html @@ -10,10 +10,10 @@
A data export creation failed. - Username + Username failed -

The error message

+

The error message

diff --git a/src/main/resources/templates/mail/notification/fragments.html b/src/main/resources/templates/mail/notification/fragments.html index 266a4291c74b..10f9ea55601b 100644 --- a/src/main/resources/templates/mail/notification/fragments.html +++ b/src/main/resources/templates/mail/notification/fragments.html @@ -190,7 +190,7 @@ --> Dear - fullName + fullName
diff --git a/src/main/resources/templates/mail/successfulDataExportsAdminEmail.html b/src/main/resources/templates/mail/successfulDataExportsAdminEmail.html index 7903a1e51573..db7c78a60a75 100644 --- a/src/main/resources/templates/mail/successfulDataExportsAdminEmail.html +++ b/src/main/resources/templates/mail/successfulDataExportsAdminEmail.html @@ -10,12 +10,9 @@

Successful data exports

-
- -

+
+

- -
diff --git a/src/main/resources/templates/mail/weeklySummary.html b/src/main/resources/templates/mail/weeklySummary.html index a531ce2d5c58..bbe46cde71e7 100644 --- a/src/main/resources/templates/mail/weeklySummary.html +++ b/src/main/resources/templates/mail/weeklySummary.html @@ -13,21 +13,21 @@
This is your Artemis summary of the last seven days.
- +

There are no new exercises that are still open:

- +

All newly released exercises that are still open:

    - +
  • -

    +

      -
    • - +
    • +
    • - + @@ -40,15 +40,15 @@
    • - -
    • Release Date
    • + +
    • Release Date
    • - -
    • Due Date
    • + +
    • Due Date
    • -
    • Max Points
    • - -
    • Bonus Points
    • +
    • Max Points
    • + +
    • Bonus Points
  • diff --git a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/MailServiceTest.java b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/MailServiceTest.java index b29c998d6ee7..a245aa54de7b 100644 --- a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/MailServiceTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/MailServiceTest.java @@ -31,6 +31,7 @@ import de.tum.cit.aet.artemis.communication.domain.notification.NotificationConstants; import de.tum.cit.aet.artemis.communication.service.notifications.MailSendingService; import de.tum.cit.aet.artemis.communication.service.notifications.MailService; +import de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.activation_mail.ActivationMailRecipientDTO; import de.tum.cit.aet.artemis.core.domain.Course; import de.tum.cit.aet.artemis.core.domain.User; import de.tum.cit.aet.artemis.core.service.TimeService; @@ -124,7 +125,7 @@ void setUp() throws MalformedURLException, URISyntaxException { */ @Test void testSendEmail() { - mailSendingService.sendEmail(student1, subject, content, false, true); + mailSendingService.sendEmail(ActivationMailRecipientDTO.of(student1), subject, content, false, true); verify(javaMailSender).send(any(MimeMessage.class)); } @@ -134,7 +135,7 @@ void testSendEmail() { @Test void testNoMailSendExceptionThrown() { doThrow(new MailSendException("Some error occurred during mail send")).when(javaMailSender).send(any(MimeMessage.class)); - assertThatNoException().isThrownBy(() -> mailSendingService.sendEmail(student1, subject, content, false, true)); + assertThatNoException().isThrownBy(() -> mailSendingService.sendEmail(ActivationMailRecipientDTO.of(student1), subject, content, false, true)); } /** diff --git a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/AbstractMailContentTest.java b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/AbstractMailContentTest.java index 44f58bb8af1b..6965aab4c304 100644 --- a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/AbstractMailContentTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/AbstractMailContentTest.java @@ -27,8 +27,8 @@ class AbstractMailContentTest extends AbstractSpringIntegrationIndependentTest { @Mock protected MailSendingService mailSendingService; - @Mock - private TimeService timeService; + @Autowired + protected TimeService timeService; @Autowired private SpringTemplateEngine templateEngine; diff --git a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/ActivationMailTest.java b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/ActivationMailTest.java new file mode 100644 index 000000000000..16ed44b4c2b6 --- /dev/null +++ b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/ActivationMailTest.java @@ -0,0 +1,26 @@ +package de.tum.cit.aet.artemis.communication.notifications.service.mail; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +import de.tum.cit.aet.artemis.core.domain.User; + +public class ActivationMailTest extends AbstractMailContentTest { + + @Test + void testThatVariablesAreInjectedIntoTheTemplate() { + // Arrange: + User recipient = createMinimalMailRecipientUser(); + recipient.setLogin("test_student"); + recipient.setActivationKey("test_key"); + + // Act: + mailService.sendActivationEmail(recipient); + + // Assert: + String capturedContent = getGeneratedEmailTemplateText(); + assertThat(capturedContent).contains("test_student"); + assertThat(capturedContent).contains("test_key"); + } +} diff --git a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/DataExportFailedMailTest.java b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/DataExportFailedMailTest.java new file mode 100644 index 000000000000..02a23cc03df8 --- /dev/null +++ b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/DataExportFailedMailTest.java @@ -0,0 +1,35 @@ +package de.tum.cit.aet.artemis.communication.notifications.service.mail; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +import de.tum.cit.aet.artemis.core.domain.DataExport; +import de.tum.cit.aet.artemis.core.domain.User; + +public class DataExportFailedMailTest extends AbstractMailContentTest { + + @Test + void testThatVariablesAreInjectedIntoTheTemplate() { + // Arrange: + User recipient = createMinimalMailRecipientUser(); + recipient.setLogin("test_login"); + + User dataExporSubjecttUser = new User(); + dataExporSubjecttUser.setLogin("test_subject"); + + DataExport dataExport = new DataExport(); + dataExport.setUser(dataExporSubjecttUser); + + Exception reason = new Exception("test_reason"); + + // Act: + mailService.sendDataExportFailedEmailToAdmin(recipient, dataExport, reason); + + // Assert: + String capturedContent = getGeneratedEmailTemplateText(); + assertThat(capturedContent).contains("test_login"); + assertThat(capturedContent).contains("test_subject"); + assertThat(capturedContent).contains("test_reason"); + } +} diff --git a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/DataExportSuccessfulMailTest.java b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/DataExportSuccessfulMailTest.java new file mode 100644 index 000000000000..a71fd1978fd8 --- /dev/null +++ b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/DataExportSuccessfulMailTest.java @@ -0,0 +1,50 @@ +package de.tum.cit.aet.artemis.communication.notifications.service.mail; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Set; + +import org.jetbrains.annotations.NotNull; +import org.junit.jupiter.api.Test; + +import de.tum.cit.aet.artemis.core.domain.DataExport; +import de.tum.cit.aet.artemis.core.domain.User; + +public class DataExportSuccessfulMailTest extends AbstractMailContentTest { + + @Test + void testThatVariablesAreInjectedIntoTheTemplate() { + // Arrange: + User recipient = createMinimalMailRecipientUser(); + recipient.setLogin("test_login"); + recipient.setResetKey("test_reset_key"); + Set dataExports = createThreeDataExportsWithThreeDifferentUsers(); + + // Act: + mailService.sendSuccessfulDataExportsEmailToAdmin(recipient, dataExports); + + // Assert: + String capturedContent = getGeneratedEmailTemplateText(); + assertThat(capturedContent).contains("test_subject_1"); + assertThat(capturedContent).contains("test_subject_2"); + assertThat(capturedContent).contains("test_subject_3"); + } + + @NotNull + private static Set createThreeDataExportsWithThreeDifferentUsers() { + User dataExportSubjectUser1 = new User(); + User dataExportSubjectUser2 = new User(); + User dataExportSubjectUser3 = new User(); + dataExportSubjectUser1.setLogin("test_subject_1"); + dataExportSubjectUser2.setLogin("test_subject_2"); + dataExportSubjectUser3.setLogin("test_subject_3"); + DataExport dataExport1 = new DataExport(); + DataExport dataExport2 = new DataExport(); + DataExport dataExport3 = new DataExport(); + dataExport1.setUser(dataExportSubjectUser1); + dataExport2.setUser(dataExportSubjectUser2); + dataExport3.setUser(dataExportSubjectUser3); + + return Set.of(dataExport1, dataExport2, dataExport3); + } +} diff --git a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/PasswordResetMailTest.java b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/PasswordResetMailTest.java new file mode 100644 index 000000000000..eac7abb673e1 --- /dev/null +++ b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/PasswordResetMailTest.java @@ -0,0 +1,26 @@ +package de.tum.cit.aet.artemis.communication.notifications.service.mail; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +import de.tum.cit.aet.artemis.core.domain.User; + +public class PasswordResetMailTest extends AbstractMailContentTest { + + @Test + void testThatVariablesAreInjectedIntoTheTemplate() { + // Arrange: + User recipient = createMinimalMailRecipientUser(); + recipient.setLogin("test_login"); + recipient.setResetKey("test_reset_key"); + + // Act: + mailService.sendPasswordResetMail(recipient); + + // Assert: + String capturedContent = getGeneratedEmailTemplateText(); + assertThat(capturedContent).contains("test_login"); + assertThat(capturedContent).contains("test_reset_key"); + } +} diff --git a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/SAML2SetPasswordMailTest.java b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/SAML2SetPasswordMailTest.java new file mode 100644 index 000000000000..398773409d99 --- /dev/null +++ b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/SAML2SetPasswordMailTest.java @@ -0,0 +1,26 @@ +package de.tum.cit.aet.artemis.communication.notifications.service.mail; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +import de.tum.cit.aet.artemis.core.domain.User; + +public class SAML2SetPasswordMailTest extends AbstractMailContentTest { + + @Test + void testThatVariablesAreInjectedIntoTheTemplate() { + // Arrange: + User recipient = createMinimalMailRecipientUser(); + recipient.setLogin("test_login"); + recipient.setResetKey("test_reset_key"); + + // Act: + mailService.sendSAML2SetPasswordMail(recipient); + + // Assert: + String capturedContent = getGeneratedEmailTemplateText(); + assertThat(capturedContent).contains("test_login"); + assertThat(capturedContent).contains("test_reset_key"); + } +} diff --git a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/WeeklySummaryMailTest.java b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/WeeklySummaryMailTest.java new file mode 100644 index 000000000000..3169d71cae71 --- /dev/null +++ b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/WeeklySummaryMailTest.java @@ -0,0 +1,72 @@ +package de.tum.cit.aet.artemis.communication.notifications.service.mail; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.time.ZonedDateTime; +import java.util.Set; + +import org.junit.jupiter.api.Test; + +import de.tum.cit.aet.artemis.core.domain.User; +import de.tum.cit.aet.artemis.exercise.domain.DifficultyLevel; +import de.tum.cit.aet.artemis.exercise.domain.Exercise; +import de.tum.cit.aet.artemis.quiz.domain.QuizExercise; +import de.tum.cit.aet.artemis.text.domain.TextExercise; + +public class WeeklySummaryMailTest extends AbstractMailContentTest { + + @Test + void testThatVariablesAreInjectedIntoTheTemplate() { + // Arrange: + User recipient = createMinimalMailRecipientUser(); + recipient.setLogin("test_login"); + recipient.setResetKey("test_reset_key"); + + ZonedDateTime dueDateTime = ZonedDateTime.now().plusDays(1); + ZonedDateTime releaseDateTime = ZonedDateTime.now().minusDays(1); + + Exercise easyExercise = new TextExercise(); + easyExercise.setTitle("easy_exercise"); + easyExercise.setDifficulty(DifficultyLevel.EASY); + easyExercise.setReleaseDate(releaseDateTime); + easyExercise.setDueDate(dueDateTime); + easyExercise.setBonusPoints(0.0); + easyExercise.setMaxPoints(101.0); + + Exercise mediumExercise = new QuizExercise(); + mediumExercise.setTitle("medium_exercise"); + mediumExercise.setDifficulty(DifficultyLevel.MEDIUM); + mediumExercise.setReleaseDate(releaseDateTime); + mediumExercise.setDueDate(dueDateTime); + mediumExercise.setBonusPoints(12.0); + mediumExercise.setMaxPoints(201.0); + + Exercise hardExercise = new QuizExercise(); + hardExercise.setTitle("hard_exercise"); + hardExercise.setDifficulty(DifficultyLevel.HARD); + hardExercise.setReleaseDate(releaseDateTime); + hardExercise.setDueDate(dueDateTime); + hardExercise.setBonusPoints(13.0); + hardExercise.setMaxPoints(301.0); + + Set exercises = Set.of(easyExercise, mediumExercise, hardExercise); + + // Act: + mailService.sendWeeklySummaryEmail(recipient, exercises); + + // Assert: + String capturedContent = getGeneratedEmailTemplateText(); + for (Exercise e : exercises) { + String dueDateFormat = timeService.convertToHumanReadableDate(e.getDueDate()); + String releaseDateFormat = timeService.convertToHumanReadableDate(e.getReleaseDate()); + + assertThat(capturedContent).contains(e.getTitle()); + assertThat(capturedContent).contains(e.getType()); + assertThat(capturedContent).containsAnyOf("Schwer", "Mittel", "Leicht"); + assertThat(capturedContent).contains(String.format("%.0f", e.getBonusPoints())); + assertThat(capturedContent).contains(String.format("%.0f", e.getMaxPoints())); + assertThat(capturedContent).contains(dueDateFormat); + assertThat(capturedContent).contains(releaseDateFormat); + } + } +} diff --git a/src/test/java/de/tum/cit/aet/artemis/core/service/DataExportScheduleServiceTest.java b/src/test/java/de/tum/cit/aet/artemis/core/service/DataExportScheduleServiceTest.java index aac8fe17f6ec..38873bbd0bbe 100644 --- a/src/test/java/de/tum/cit/aet/artemis/core/service/DataExportScheduleServiceTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/core/service/DataExportScheduleServiceTest.java @@ -3,7 +3,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyLong; -import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.eq; @@ -84,7 +83,7 @@ void testScheduledCronTaskSendsEmailToAdminAboutSuccessfulDataExports() throws I doThrow(new RuntimeException("error")).doNothing().doNothing().when(fileService).scheduleDirectoryPathForRecursiveDeletion(any(Path.class), anyLong()); dataExportScheduleService.createDataExportsAndDeleteOldOnes(); var dataExportsAfterCreation = dataExportRepository.findAllSuccessfullyCreatedDataExports(); - verify(mailService).sendSuccessfulDataExportsEmailToAdmin(any(User.class), anyString(), anyString(), eq(Set.copyOf(dataExportsAfterCreation))); + verify(mailService).sendSuccessfulDataExportsEmailToAdmin(any(User.class), eq(Set.copyOf(dataExportsAfterCreation))); } From e58d9fe4e1dbea3556f40aee827c403a57fa3366 Mon Sep 17 00:00:00 2001 From: Hassan Matout Date: Mon, 25 Nov 2024 20:41:25 +0100 Subject: [PATCH 3/5] Development: Fix failing server tests due to public testing classes and illegal annotation --- .../notifications/service/mail/ActivationMailTest.java | 2 +- .../notifications/service/mail/DataExportFailedMailTest.java | 2 +- .../service/mail/DataExportSuccessfulMailTest.java | 4 +--- .../notifications/service/mail/PasswordResetMailTest.java | 2 +- .../notifications/service/mail/SAML2SetPasswordMailTest.java | 2 +- .../notifications/service/mail/WeeklySummaryMailTest.java | 2 +- 6 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/ActivationMailTest.java b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/ActivationMailTest.java index 16ed44b4c2b6..b4dfe2c65e5b 100644 --- a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/ActivationMailTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/ActivationMailTest.java @@ -6,7 +6,7 @@ import de.tum.cit.aet.artemis.core.domain.User; -public class ActivationMailTest extends AbstractMailContentTest { +class ActivationMailTest extends AbstractMailContentTest { @Test void testThatVariablesAreInjectedIntoTheTemplate() { diff --git a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/DataExportFailedMailTest.java b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/DataExportFailedMailTest.java index 02a23cc03df8..c5826bec402a 100644 --- a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/DataExportFailedMailTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/DataExportFailedMailTest.java @@ -7,7 +7,7 @@ import de.tum.cit.aet.artemis.core.domain.DataExport; import de.tum.cit.aet.artemis.core.domain.User; -public class DataExportFailedMailTest extends AbstractMailContentTest { +class DataExportFailedMailTest extends AbstractMailContentTest { @Test void testThatVariablesAreInjectedIntoTheTemplate() { diff --git a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/DataExportSuccessfulMailTest.java b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/DataExportSuccessfulMailTest.java index a71fd1978fd8..3776addca809 100644 --- a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/DataExportSuccessfulMailTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/DataExportSuccessfulMailTest.java @@ -4,13 +4,12 @@ import java.util.Set; -import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Test; import de.tum.cit.aet.artemis.core.domain.DataExport; import de.tum.cit.aet.artemis.core.domain.User; -public class DataExportSuccessfulMailTest extends AbstractMailContentTest { +class DataExportSuccessfulMailTest extends AbstractMailContentTest { @Test void testThatVariablesAreInjectedIntoTheTemplate() { @@ -30,7 +29,6 @@ void testThatVariablesAreInjectedIntoTheTemplate() { assertThat(capturedContent).contains("test_subject_3"); } - @NotNull private static Set createThreeDataExportsWithThreeDifferentUsers() { User dataExportSubjectUser1 = new User(); User dataExportSubjectUser2 = new User(); diff --git a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/PasswordResetMailTest.java b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/PasswordResetMailTest.java index eac7abb673e1..b441153b1adf 100644 --- a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/PasswordResetMailTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/PasswordResetMailTest.java @@ -6,7 +6,7 @@ import de.tum.cit.aet.artemis.core.domain.User; -public class PasswordResetMailTest extends AbstractMailContentTest { +class PasswordResetMailTest extends AbstractMailContentTest { @Test void testThatVariablesAreInjectedIntoTheTemplate() { diff --git a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/SAML2SetPasswordMailTest.java b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/SAML2SetPasswordMailTest.java index 398773409d99..cdb6eaacd6af 100644 --- a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/SAML2SetPasswordMailTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/SAML2SetPasswordMailTest.java @@ -6,7 +6,7 @@ import de.tum.cit.aet.artemis.core.domain.User; -public class SAML2SetPasswordMailTest extends AbstractMailContentTest { +class SAML2SetPasswordMailTest extends AbstractMailContentTest { @Test void testThatVariablesAreInjectedIntoTheTemplate() { diff --git a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/WeeklySummaryMailTest.java b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/WeeklySummaryMailTest.java index 3169d71cae71..60fb5b75d66d 100644 --- a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/WeeklySummaryMailTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/WeeklySummaryMailTest.java @@ -13,7 +13,7 @@ import de.tum.cit.aet.artemis.quiz.domain.QuizExercise; import de.tum.cit.aet.artemis.text.domain.TextExercise; -public class WeeklySummaryMailTest extends AbstractMailContentTest { +class WeeklySummaryMailTest extends AbstractMailContentTest { @Test void testThatVariablesAreInjectedIntoTheTemplate() { From bdad5c382e7c07ca371fb42e0a6c0d03905692a6 Mon Sep 17 00:00:00 2001 From: Hassan Matout Date: Tue, 26 Nov 2024 01:44:59 +0100 Subject: [PATCH 4/5] Development: Add missing javadocs to dto classes --- .../service/notifications/MailService.java | 1 - .../activation_mail/ActivationMailRecipientDTO.java | 3 +++ .../DataExportFailedContentDTO.java | 6 ++++++ .../DataExportFailedMailAdminRecipientDTO.java | 3 +++ .../DataExportSuccessfulContentDTO.java | 5 +++++ .../DataExportSuccessfulContentsDTO.java | 3 +++ .../DataExportSuccessfulMailAdminRecipientDTO.java | 3 +++ .../notifications/NotificationMailRecipientDTO.java | 3 +++ .../PasswordResetRecipientDTO.java | 3 +++ .../SAML2SetPasswordMailRecipientDTO.java | 3 +++ .../WeeklyExerciseSummaryDTO.java | 11 +++++++++++ .../WeeklySummaryMailContentDTO.java | 13 +++++++++++++ .../WeeklySummaryMailRecipientDTO.java | 3 +++ .../service/mail/ActivationMailTest.java | 3 +++ .../service/mail/DataExportFailedMailTest.java | 3 +++ .../service/mail/DataExportSuccessfulMailTest.java | 3 +++ .../service/mail/PasswordResetMailTest.java | 3 +++ .../service/mail/SAML2SetPasswordMailTest.java | 3 +++ .../service/mail/WeeklySummaryMailTest.java | 3 +++ 19 files changed, 77 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/MailService.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/MailService.java index 51f7460d84aa..5c2ea605d731 100644 --- a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/MailService.java +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/MailService.java @@ -239,7 +239,6 @@ public void sendNotification(Notification notification, Set users, Object * @param user who should be contacted * @param notificationSubject that is used to provide further information (e.g. exercise, attachment, post, etc.) */ - @Override public void sendNotification(Notification notification, User user, Object notificationSubject) { NotificationType notificationType = NotificationConstants.findCorrespondingNotificationType(notification.getTitle()); diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/activation_mail/ActivationMailRecipientDTO.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/activation_mail/ActivationMailRecipientDTO.java index 179ff1a95804..682c6e333d12 100644 --- a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/activation_mail/ActivationMailRecipientDTO.java +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/activation_mail/ActivationMailRecipientDTO.java @@ -3,6 +3,9 @@ import de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.IMailRecipientUserDTO; import de.tum.cit.aet.artemis.core.domain.User; +/** + * DTO for the recipient of the activation mail + */ public record ActivationMailRecipientDTO(String langKey, String email, String login, String activationKey) implements IMailRecipientUserDTO { public static ActivationMailRecipientDTO of(User user) { diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_failed_mail/DataExportFailedContentDTO.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_failed_mail/DataExportFailedContentDTO.java index e67b1d297c22..c5708714195f 100644 --- a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_failed_mail/DataExportFailedContentDTO.java +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_failed_mail/DataExportFailedContentDTO.java @@ -2,6 +2,12 @@ import de.tum.cit.aet.artemis.core.domain.DataExport; +/** + * DTO for the content of a data export failed mail + * + * @param reason The reason why the data export failed + * @param exportUsername The username of the user who initiated the data export + */ public record DataExportFailedContentDTO(String reason, String exportUsername) { public static DataExportFailedContentDTO of(Exception exception, DataExport dataExport) { diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_failed_mail/DataExportFailedMailAdminRecipientDTO.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_failed_mail/DataExportFailedMailAdminRecipientDTO.java index 2ee29a7cafcb..4bbab58637a7 100644 --- a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_failed_mail/DataExportFailedMailAdminRecipientDTO.java +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_failed_mail/DataExportFailedMailAdminRecipientDTO.java @@ -3,6 +3,9 @@ import de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.IMailRecipientUserDTO; import de.tum.cit.aet.artemis.core.domain.User; +/** + * DTO for the recipient of the data export failed mail for the admin + */ public record DataExportFailedMailAdminRecipientDTO(String langKey, String email, String login) implements IMailRecipientUserDTO { public static DataExportFailedMailAdminRecipientDTO of(User user) { diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_successful_mail/DataExportSuccessfulContentDTO.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_successful_mail/DataExportSuccessfulContentDTO.java index 9bec98af2b47..6d6179b7411f 100644 --- a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_successful_mail/DataExportSuccessfulContentDTO.java +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_successful_mail/DataExportSuccessfulContentDTO.java @@ -2,6 +2,11 @@ import de.tum.cit.aet.artemis.core.domain.DataExport; +/** + * DTO for the content of a data export successful mail. + * + * @param userLogin the login of the user who requested the data export + */ public record DataExportSuccessfulContentDTO(String userLogin) { public static DataExportSuccessfulContentDTO of(DataExport dataExport) { diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_successful_mail/DataExportSuccessfulContentsDTO.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_successful_mail/DataExportSuccessfulContentsDTO.java index a771831650a8..548ec0800081 100644 --- a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_successful_mail/DataExportSuccessfulContentsDTO.java +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_successful_mail/DataExportSuccessfulContentsDTO.java @@ -5,6 +5,9 @@ import de.tum.cit.aet.artemis.core.domain.DataExport; +/** + * DTO for the contents of a data export successful mail notification. + */ public record DataExportSuccessfulContentsDTO(Set contents) { public static DataExportSuccessfulContentsDTO of(Set exportSet) { diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_successful_mail/DataExportSuccessfulMailAdminRecipientDTO.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_successful_mail/DataExportSuccessfulMailAdminRecipientDTO.java index 7bbaf48458c9..4388ab51549c 100644 --- a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_successful_mail/DataExportSuccessfulMailAdminRecipientDTO.java +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/data_export_successful_mail/DataExportSuccessfulMailAdminRecipientDTO.java @@ -3,6 +3,9 @@ import de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.IMailRecipientUserDTO; import de.tum.cit.aet.artemis.core.domain.User; +/** + * DTO for the admin recipient of the data export successful mail notification. + */ public record DataExportSuccessfulMailAdminRecipientDTO(String langKey, String email) implements IMailRecipientUserDTO { public static DataExportSuccessfulMailAdminRecipientDTO of(User user) { diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/notifications/NotificationMailRecipientDTO.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/notifications/NotificationMailRecipientDTO.java index 156ad8a357d2..3b5ad58713e4 100644 --- a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/notifications/NotificationMailRecipientDTO.java +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/notifications/NotificationMailRecipientDTO.java @@ -3,6 +3,9 @@ import de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.IMailRecipientUserDTO; import de.tum.cit.aet.artemis.core.domain.User; +/** + * DTO for the recipient of a notification mail. + */ public record NotificationMailRecipientDTO(String langKey, String email, String name, String login) implements IMailRecipientUserDTO { public static NotificationMailRecipientDTO of(User user) { diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/password_reset_mail/PasswordResetRecipientDTO.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/password_reset_mail/PasswordResetRecipientDTO.java index 47199a4a546c..1a8f1c3d3124 100644 --- a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/password_reset_mail/PasswordResetRecipientDTO.java +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/password_reset_mail/PasswordResetRecipientDTO.java @@ -3,6 +3,9 @@ import de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.IMailRecipientUserDTO; import de.tum.cit.aet.artemis.core.domain.User; +/** + * DTO for the password reset mail recipient + */ public record PasswordResetRecipientDTO(String langKey, String email, String login, String resetKey) implements IMailRecipientUserDTO { public static PasswordResetRecipientDTO of(User user) { diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/saml2_set_password_mail/SAML2SetPasswordMailRecipientDTO.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/saml2_set_password_mail/SAML2SetPasswordMailRecipientDTO.java index 1ce422464bf8..142305daec62 100644 --- a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/saml2_set_password_mail/SAML2SetPasswordMailRecipientDTO.java +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/saml2_set_password_mail/SAML2SetPasswordMailRecipientDTO.java @@ -3,6 +3,9 @@ import de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.IMailRecipientUserDTO; import de.tum.cit.aet.artemis.core.domain.User; +/** + * DTO for the recipient of the SAML2SetPasswordMail + */ public record SAML2SetPasswordMailRecipientDTO(String langKey, String email, String login, String resetKey) implements IMailRecipientUserDTO { public static SAML2SetPasswordMailRecipientDTO of(User user) { diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklyExerciseSummaryDTO.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklyExerciseSummaryDTO.java index 90bdf4627fdc..bcd16d024668 100644 --- a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklyExerciseSummaryDTO.java +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklyExerciseSummaryDTO.java @@ -3,6 +3,17 @@ import de.tum.cit.aet.artemis.core.service.TimeService; import de.tum.cit.aet.artemis.exercise.domain.Exercise; +/** + * A Data Transfer Object (DTO) representing a summary of an exercise for the weekly summary email. + * + * @param title the title of the exercise + * @param type the type of the exercise + * @param difficulty the difficulty level of the exercise + * @param releaseDate the release date of the exercise in a human-readable format + * @param dueDate the due date of the exercise in a human-readable format + * @param maxPoints the maximum points that can be earned for the exercise + * @param bonusPoints the bonus points that can be earned for the exercise + */ public record WeeklyExerciseSummaryDTO(String title, String type, String difficulty, String releaseDate, String dueDate, double maxPoints, double bonusPoints) { public static WeeklyExerciseSummaryDTO of(Exercise exercise, TimeService timeService) { diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklySummaryMailContentDTO.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklySummaryMailContentDTO.java index 5f4365d16aee..d0579c601a49 100644 --- a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklySummaryMailContentDTO.java +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklySummaryMailContentDTO.java @@ -6,8 +6,21 @@ import de.tum.cit.aet.artemis.core.service.TimeService; import de.tum.cit.aet.artemis.exercise.domain.Exercise; +/** + * A Data Transfer Object (DTO) representing the content of a weekly summary email. + * + * @param hasNewExercises indicates if there are new exercises in the summary + * @param exerciseSummaries a set of summaries for each exercise included in the weekly summary + */ public record WeeklySummaryMailContentDTO(boolean hasNewExercises, Set exerciseSummaries) { + /** + * Creates a new instance of WeeklySummaryMailContentDTO from a set of exercises. + * + * @param exercises the set of exercises to be included in the summary + * @param timeService the service used to convert dates to a human-readable format + * @return a new instance of WeeklySummaryMailContentDTO + */ public static WeeklySummaryMailContentDTO of(Set exercises, TimeService timeService) { boolean hasNewExercises = !exercises.isEmpty(); Set exerciseSummaries = exercises.stream().map(exercise -> WeeklyExerciseSummaryDTO.of(exercise, timeService)).collect(Collectors.toSet()); diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklySummaryMailRecipientDTO.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklySummaryMailRecipientDTO.java index 5bc6c2a18550..783eaeecee38 100644 --- a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklySummaryMailRecipientDTO.java +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklySummaryMailRecipientDTO.java @@ -3,6 +3,9 @@ import de.tum.cit.aet.artemis.communication.service.notifications.mails.dto.IMailRecipientUserDTO; import de.tum.cit.aet.artemis.core.domain.User; +/** + * DTO for the weekly summary mail recipient. + */ public record WeeklySummaryMailRecipientDTO(String langKey, String email, String name) implements IMailRecipientUserDTO { public static WeeklySummaryMailRecipientDTO of(User user) { diff --git a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/ActivationMailTest.java b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/ActivationMailTest.java index b4dfe2c65e5b..b8bf8b39de18 100644 --- a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/ActivationMailTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/ActivationMailTest.java @@ -8,6 +8,9 @@ class ActivationMailTest extends AbstractMailContentTest { + /** + * Test that the variables injected in the template are used in the generated HTML content. + */ @Test void testThatVariablesAreInjectedIntoTheTemplate() { // Arrange: diff --git a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/DataExportFailedMailTest.java b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/DataExportFailedMailTest.java index c5826bec402a..8b80b5301cda 100644 --- a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/DataExportFailedMailTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/DataExportFailedMailTest.java @@ -9,6 +9,9 @@ class DataExportFailedMailTest extends AbstractMailContentTest { + /** + * Test that the variables injected in the template are used in the generated HTML content. + */ @Test void testThatVariablesAreInjectedIntoTheTemplate() { // Arrange: diff --git a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/DataExportSuccessfulMailTest.java b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/DataExportSuccessfulMailTest.java index 3776addca809..4a1e66a8b5f1 100644 --- a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/DataExportSuccessfulMailTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/DataExportSuccessfulMailTest.java @@ -11,6 +11,9 @@ class DataExportSuccessfulMailTest extends AbstractMailContentTest { + /** + * Test that the variables injected in the template are used in the generated HTML content. + */ @Test void testThatVariablesAreInjectedIntoTheTemplate() { // Arrange: diff --git a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/PasswordResetMailTest.java b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/PasswordResetMailTest.java index b441153b1adf..4b65a90ee9aa 100644 --- a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/PasswordResetMailTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/PasswordResetMailTest.java @@ -8,6 +8,9 @@ class PasswordResetMailTest extends AbstractMailContentTest { + /** + * Test that the variables injected in the template are used in the generated HTML content. + */ @Test void testThatVariablesAreInjectedIntoTheTemplate() { // Arrange: diff --git a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/SAML2SetPasswordMailTest.java b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/SAML2SetPasswordMailTest.java index cdb6eaacd6af..7b9ec3d97ecb 100644 --- a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/SAML2SetPasswordMailTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/SAML2SetPasswordMailTest.java @@ -8,6 +8,9 @@ class SAML2SetPasswordMailTest extends AbstractMailContentTest { + /** + * Test that the variables injected in the template are used in the generated HTML content. + */ @Test void testThatVariablesAreInjectedIntoTheTemplate() { // Arrange: diff --git a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/WeeklySummaryMailTest.java b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/WeeklySummaryMailTest.java index 60fb5b75d66d..537fc7ab71a3 100644 --- a/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/WeeklySummaryMailTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/communication/notifications/service/mail/WeeklySummaryMailTest.java @@ -15,6 +15,9 @@ class WeeklySummaryMailTest extends AbstractMailContentTest { + /** + * Test that the variables injected in the template are used in the generated HTML content. + */ @Test void testThatVariablesAreInjectedIntoTheTemplate() { // Arrange: From 7733976eacf48a7fe9980dec8652da62a1aa2234 Mon Sep 17 00:00:00 2001 From: Hassan Matout Date: Tue, 26 Nov 2024 01:54:07 +0100 Subject: [PATCH 5/5] Development: Add missing javadocs to weekly summary dto creation method --- .../dto/weekly_summary_mail/WeeklyExerciseSummaryDTO.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklyExerciseSummaryDTO.java b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklyExerciseSummaryDTO.java index bcd16d024668..a571f41f82ce 100644 --- a/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklyExerciseSummaryDTO.java +++ b/src/main/java/de/tum/cit/aet/artemis/communication/service/notifications/mails/dto/weekly_summary_mail/WeeklyExerciseSummaryDTO.java @@ -16,6 +16,14 @@ */ public record WeeklyExerciseSummaryDTO(String title, String type, String difficulty, String releaseDate, String dueDate, double maxPoints, double bonusPoints) { + /** + * Creates a new `WeeklyExerciseSummaryDTO` instance from the given `Exercise` instance. + * The release and due dates are converted to human-readable format using the given `TimeService`. + * + * @param exercise the exercise to be summarized + * @param timeService the service to convert dates to human-readable format + * @return a new `WeeklyExerciseSummaryDTO` instance + */ public static WeeklyExerciseSummaryDTO of(Exercise exercise, TimeService timeService) { String releaseDate = null, dueDate = null; if (exercise.getReleaseDate() != null) {