@Override public EmailMessage format(Notification notif) { if (!"issue-changes".equals(notif.getType())) { return null; } StringBuilder sb = new StringBuilder(); appendHeader(notif, sb); sb.append(NEW_LINE); appendChanges(notif, sb); sb.append(NEW_LINE); appendFooter(sb, notif); String projectName = notif.getFieldValue("projectName"); String issueKey = notif.getFieldValue("key"); String author = notif.getFieldValue("changeAuthor"); EmailMessage message = new EmailMessage() .setMessageId("issue-changes/" + issueKey) .setSubject(projectName + ", change on issue #" + issueKey) .setMessage(sb.toString()); if (author != null) { message.setFrom(getUserFullName(author)); } return message; }
@Test public void message_id() { Notification notification = newNotification(); EmailMessage message = template.format(notification); assertThat(message.getMessageId()).isEqualTo("new-issues/org.apache:struts"); }
@Test public void subject() { Notification notification = newNotification(); EmailMessage message = template.format(notification); assertThat(message.getSubject()).isEqualTo("Struts: 32 new issues (new debt: 1d3h)"); }
@Test public void subject() { Notification notification = newNotification(); EmailMessage message = sut.format(notification); assertThat(message.getSubject()).isEqualTo("You have 32 new issues on project Struts"); }
@Test public void do_not_add_footer_when_properties_missing() { Notification notification = new Notification(MyNewIssuesNotification.MY_NEW_ISSUES_NOTIF_TYPE) .setFieldValue(SEVERITY + ".count", "32") .setFieldValue("projectName", "Struts"); EmailMessage message = sut.format(notification); assertThat(message.getMessage()).doesNotContain("See it"); }
@Test public void format_email_with_no_assignees_tags_nor_components() throws Exception { Notification notification = newNotification(); EmailMessage message = template.format(notification); // TODO datetime to be completed when test is isolated from JVM timezone String expectedContent = IOUtils.toString( getClass().getResource("NewIssuesEmailTemplateTest/email_with_partial_details.txt"), StandardCharsets.UTF_8); assertThat(message.getMessage()).startsWith(expectedContent); }
@Test public void format_email_with_all_fields_filled() throws Exception { Notification notification = newNotification(); addTags(notification); addRules(notification); addComponents(notification); EmailMessage message = sut.format(notification); // TODO datetime to be completed when test is isolated from JVM timezone String file = IOUtils.toString( getClass().getResource("MyNewIssuesEmailTemplateTest/email_with_all_details.txt"), StandardCharsets.UTF_8); assertThat(message.getMessage()).startsWith(file); }
@Override public EmailMessage format(Notification notification) { if (!"review-changed".equals(notification.getType())) { return null; } String reviewId = notification.getFieldValue("reviewId"); String author = notification.getFieldValue("author"); StringBuilder sb = new StringBuilder(); append(sb, "Project", null, notification.getFieldValue("project")); append(sb, "Resource", null, notification.getFieldValue("resource")); sb.append('\n'); append(sb, null, null, notification.getFieldValue("title")); sb.append('\n'); append( sb, "Status", notification.getFieldValue("old.status"), notification.getFieldValue("new.status")); append( sb, "Resolution", notification.getFieldValue("old.resolution"), notification.getFieldValue("new.resolution")); append( sb, "Assignee", getUserFullName(notification.getFieldValue("old.assignee")), getUserFullName(notification.getFieldValue("new.assignee"))); appendComment(sb, notification); appendFooter(sb, notification); EmailMessage message = new EmailMessage() .setMessageId("review/" + reviewId) .setSubject("Review #" + reviewId) .setMessage(sb.toString()); if (author != null) { message.setFrom(getUserFullName(author)); } return message; }