UserNotificationService { public void notifyCreatorOnProjectStatusUpdate(ProjectEntity project) { final StandardEvaluationContext context = new StandardEvaluationContext(); final String projectLink = buildProjectLink(project.getId()); context.setVariable("link", projectLink); context.setVariable("userName", project.getCreator().getFullName()); switch (project.getStatus()) { case PUBLISHED: final String publishMessage = projectPublishedEmailTemplate.getValue(context, String.class); sendMail(project.getCreator().getEmail(), SUBJECT_PROJECT_PUBLISHED, publishMessage); break; case REJECTED: final String rejectedMessage = projectRejectedEmailTemplate.getValue(context, String.class); sendMail(project.getCreator().getEmail(), SUBJECT_PROJECT_REJECTED, rejectedMessage); break; case DEFERRED: case PUBLISHED_DEFERRED: final String deferringMessage = projectDeferredEmailTemplate.getValue(context, String.class); sendMail(project.getCreator().getEmail(), SUBJECT_PROJECT_DEFERRED, deferringMessage); break; default: final String defaultMessage = "Das Projekt " + project.getTitle() + " wurde in den Zustand " + project.getStatus().name() + " versetzt."; final String defaultSubject = "Der Zustand des Projekts " + project.getTitle() + " hat sich geändert!"; sendMail(project.getCreator().getEmail(), defaultSubject, defaultMessage); break; } }  void sendActivationMail(UserEntity user); void sendPasswordRecoveryMail(UserEntity user); void notifyCreatorOnProjectStatusUpdate(ProjectEntity project); void notifyCreatorOnComment(CommentEntity comment); void notifyCreatorOnIdeaAccepted(IdeaEntity idea, String campaignTitle); void notifyCreatorOnIdeaRejected(IdeaEntity idea, String rejectionComment, String campaignTitle); void notifyCreatorAndAdminOnProjectModification(ProjectEntity project, UserEntity modifier); void notifyAdminOnProjectCreation(ProjectEntity project, String emailAddress); void notifyAdminOnIdeaCreation(IdeaEntity idea, String emailAddress, String campaignTitle); static final Integer COMMENT_EXCERPT_LENGTH; static final String FROM_ADDRESS; static final String PROJECT_LINK_PATTERN; static final String ACTIVATION_LINK_PATTERN; static final String PASSWORD_RECOVERY_LINK_PATTERN; static final String IDEA_CAMPAIGN_LINK_PATTERN; static final String IDEA_CAMPAIGN_LINK_ADMIN_PATTERN; static final String IDEA_CAMPAIGN_YOUR_IDEAS_LINK_PATTERN; static final String SUBJECT_ACTIVATION; static final String SUBJECT_PASSWORD_FORGOTTEN; static final String SUBJECT_IDEA_CREATED; static final String SUBJECT_IDEA_ACCEPTED; static final String SUBJECT_IDEA_REJECTED; static final String SUBJECT_PROJECT_MODIFIED; static final String SUBJECT_PROJECT_CREATED; static final String SUBJECT_PROJECT_PUBLISHED; static final String SUBJECT_PROJECT_REJECTED; static final String SUBJECT_PROJECT_DEFERRED; static final String SUBJECT_PROJECT_COMMENTED; }
@Test public void testSendUserNotificationMailForPublished() { UserEntity user = aProjectCreator(); userNotificationService.notifyCreatorOnProjectStatusUpdate(project("proj3ctId", ProjectStatus.PUBLISHED, user, "My Super Project")); SimpleMailMessage mail = getMessageFromMailSender(); assertThat(mail.getFrom(), is(UserNotificationService.FROM_ADDRESS)); assertThat(mail.getTo(), arrayContaining(user.getEmail())); assertThat(mail.getSubject(), is(UserNotificationService.SUBJECT_PROJECT_PUBLISHED)); assertThat(replaceLineBreaksIfWindows(mail.getText()), is( "Hallo Guybrush Threepwood,\n\n" + "Dein Projekt wurde erfolgreich freigegeben!\n" + "Weitere Informationen hinsichtlich des Prozesses kannst Du der FAQ entnehmen.\n\n" + "Zu Deinem Projekt:\n\n" + "https: "Mit freundlichen Grüßen\n" + "Dein CrowdSource Team")); }
@Test public void testSendUserNotificationMailForRejected() { UserEntity user = aProjectCreator(); userNotificationService.notifyCreatorOnProjectStatusUpdate(project("proj3ctId", ProjectStatus.REJECTED, user, "My Super Project")); SimpleMailMessage mail = getMessageFromMailSender(); assertThat(mail.getFrom(), is(UserNotificationService.FROM_ADDRESS)); assertThat(mail.getTo(), arrayContaining(user.getEmail())); assertThat(mail.getSubject(), is(UserNotificationService.SUBJECT_PROJECT_REJECTED)); assertThat(replaceLineBreaksIfWindows(mail.getText()), is( "Hallo Guybrush Threepwood,\n\n" + "Dein Projekt wurde leider abgelehnt.\n" + "Das CrowdSource Team wird in Kürze mit Dir in Kontakt treten, um die nächsten Schritte zu besprechen.\n\n" + "Zu Deinem Projekt:\n\n" + "https: "Mit freundlichen Grüßen\nDein CrowdSource Team")); }
@Test public void testSendUserNotificationMailForDeferred() { UserEntity user = aProjectCreator(); userNotificationService.notifyCreatorOnProjectStatusUpdate(project("proj3ctId", ProjectStatus.DEFERRED, user, "My Super Project")); SimpleMailMessage mail = getMessageFromMailSender(); assertThat(mail.getFrom(), is(UserNotificationService.FROM_ADDRESS)); assertThat(mail.getTo(), arrayContaining(user.getEmail())); assertThat(mail.getSubject(), is(UserNotificationService.SUBJECT_PROJECT_DEFERRED)); assertThat(replaceLineBreaksIfWindows(mail.getText()), is( "Hallo Guybrush Threepwood,\n\n" + "Dein Projekt wurde leider zurückgestellt und nimmt daher nicht an der nächsten Finanzierungsrunde teil.\n" + "Das Projekt wird jedoch für die darauf folgende Finanzierungsrunde automatisch freigegeben.\n\n" + "Zu Deinem Projekt:\n\n" + "https: "Mit freundlichen Grüßen\nDein CrowdSource Team")); }
@Test public void testSendUserNotificationMailForPublishedDeferred() { UserEntity user = aProjectCreator(); userNotificationService.notifyCreatorOnProjectStatusUpdate(project("proj3ctId", ProjectStatus.PUBLISHED_DEFERRED, user, "My Super Project")); SimpleMailMessage mail = getMessageFromMailSender(); assertThat(mail.getFrom(), is(UserNotificationService.FROM_ADDRESS)); assertThat(mail.getTo(), arrayContaining(user.getEmail())); assertThat(mail.getSubject(), is(UserNotificationService.SUBJECT_PROJECT_DEFERRED)); assertThat(replaceLineBreaksIfWindows(mail.getText()), is( "Hallo Guybrush Threepwood,\n\n" + "Dein Projekt wurde leider zurückgestellt und nimmt daher nicht an der nächsten Finanzierungsrunde teil.\n" + "Das Projekt wird jedoch für die darauf folgende Finanzierungsrunde automatisch freigegeben.\n\n" + "Zu Deinem Projekt:\n\n" + "https: "Mit freundlichen Grüßen\nDein CrowdSource Team")); }
@Test public void testSendUserNotificationMailForFallback() { UserEntity user = aProjectCreator(); userNotificationService.notifyCreatorOnProjectStatusUpdate(project("proj3ctId", ProjectStatus.PROPOSED, user, "My Super Project")); SimpleMailMessage mail = getMessageFromMailSender(); assertThat(mail.getFrom(), is(UserNotificationService.FROM_ADDRESS)); assertThat(mail.getTo(), arrayContaining(user.getEmail())); assertThat(mail.getSubject(), is("Der Zustand des Projekts My Super Project hat sich geändert!")); assertThat(mail.getText(), is("Das Projekt My Super Project wurde in den Zustand PROPOSED versetzt.")); }