@Override protected void appendFooter(StringBuilder message, Notification notification) { String projectKey = notification.getFieldValue(FIELD_PROJECT_KEY); String dateString = notification.getFieldValue(FIELD_PROJECT_DATE); String assignee = notification.getFieldValue(FIELD_ASSIGNEE); if (projectKey != null && dateString != null && assignee != null) { Date date = DateUtils.parseDateTime(dateString); String url = String.format("%s/project/issues?id=%s&assignees=%s", settings.getServerBaseURL(), encode(projectKey), encode(assignee)); String branchName = notification.getFieldValue(FIELD_BRANCH); if (branchName != null) { url += "&branch=" + encode(branchName); } String pullRequest = notification.getFieldValue(FIELD_PULL_REQUEST); if (pullRequest != null) { url += "&pullRequest=" + encode(pullRequest); } url += "&createdAt=" + encode(DateUtils.formatDateTime(date)); message .append("More details at: ") .append(url) .append(NEW_LINE); } } }
@Test public void message_id() { Notification notification = newNotification(32); EmailMessage message = underTest.format(notification); assertThat(message.getMessageId()).isEqualTo("my-new-issues/org.apache:struts"); }
@Test public void subject() { Notification notification = newNotification(32); EmailMessage message = underTest.format(notification); assertThat(message.getSubject()).isEqualTo("You have 32 new issues on project Struts"); }
@Override protected void appendFooter(StringBuilder message, Notification notification) { String projectKey = notification.getFieldValue(FIELD_PROJECT_KEY); String dateString = notification.getFieldValue(FIELD_PROJECT_DATE); String assignee = notification.getFieldValue(FIELD_ASSIGNEE); if (projectKey != null && dateString != null && assignee != null) { Date date = DateUtils.parseDateTime(dateString); String url = String.format("%s/project/issues?id=%s&assignees=%s", settings.getServerBaseURL(), encode(projectKey), encode(assignee)); String branchName = notification.getFieldValue(FIELD_BRANCH); if (branchName != null) { url += "&branch=" + encode(branchName); } String pullRequest = notification.getFieldValue(FIELD_PULL_REQUEST); if (pullRequest != null) { url += "&pullRequest=" + encode(pullRequest); } url += "&createdAt=" + encode(DateUtils.formatDateTime(date)); message .append("More details at: ") .append(url) .append(NEW_LINE); } } }
@Test public void format_email_supports_single_issue() { Notification notification = newNotification(1); EmailMessage message = underTest.format(notification); assertThat(message.getSubject()) .isEqualTo("You have 1 new issue on project Struts"); assertThat(message.getMessage()) .contains("1 new issue (new debt: 1d3h)\n"); }
@Test public void no_format_if_not_the_correct_notif() { Notification notification = new Notification("new-issues"); EmailMessage message = underTest.format(notification); assertThat(message).isNull(); }
@Test public void subject_on_branch() { Notification notification = newNotification(32) .setFieldValue("branch", "feature1"); EmailMessage message = underTest.format(notification); assertThat(message.getSubject()).isEqualTo("You have 32 new issues on project Struts (feature1)"); }
@Test public void do_not_add_footer_when_properties_missing() { Notification notification = new Notification(MyNewIssuesNotification.MY_NEW_ISSUES_NOTIF_TYPE) .setFieldValue(RULE_TYPE + ".count", "32") .setFieldValue("projectName", "Struts"); EmailMessage message = underTest.format(notification); assertThat(message.getMessage()).doesNotContain("See it"); }
@Test public void format_supports_null_version() { Notification notification = newNotification(32) .setFieldValue("branch", "feature1"); EmailMessage message = underTest.format(notification); // TODO datetime to be completed when test is isolated from JVM timezone assertThat(message.getMessage()) .startsWith("Project: Struts\n" + "Branch: feature1\n" + "\n" + "32 new issues (new debt: 1d3h)\n" + "\n" + " Type\n" + " Bug: 1 Vulnerability: 3 Code Smell: 0\n" + "\n" + "More details at: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&assignees=lo.gin&branch=feature1&createdAt=2010-05-18"); }
@Test public void format_email_with_no_assignees_tags_nor_components() { Notification notification = newNotification(32) .setFieldValue("projectVersion", "52.0"); EmailMessage message = underTest.format(notification); // TODO datetime to be completed when test is isolated from JVM timezone assertThat(message.getMessage()) .startsWith("Project: Struts\n" + "Version: 52.0\n" + "\n" + "32 new issues (new debt: 1d3h)\n" + "\n" + " Type\n" + " Bug: 1 Vulnerability: 3 Code Smell: 0\n" + "\n" + "More details at: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&assignees=lo.gin&createdAt=2010-05-18"); }
@Test public void format_email_with_issue_on_branch() { Notification notification = newNotification(32) .setFieldValue("projectVersion", "52.0") .setFieldValue("branch", "feature1"); EmailMessage message = underTest.format(notification); // TODO datetime to be completed when test is isolated from JVM timezone assertThat(message.getMessage()) .startsWith("Project: Struts\n" + "Branch: feature1\n" + "Version: 52.0\n" + "\n" + "32 new issues (new debt: 1d3h)\n" + "\n" + " Type\n" + " Bug: 1 Vulnerability: 3 Code Smell: 0\n" + "\n" + "More details at: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&assignees=lo.gin&branch=feature1&createdAt=2010-05-18"); }
@Test public void format_email_with_all_fields_filled() { Notification notification = newNotification(32); addTags(notification); addRules(notification); addComponents(notification); EmailMessage message = underTest.format(notification); // TODO datetime to be completed when test is isolated from JVM timezone assertThat(message.getMessage()).startsWith( "Project: Struts\n" + "\n" + "32 new issues (new debt: 1d3h)\n" + "\n" + " Type\n" + " Bug: 1 Vulnerability: 3 Code Smell: 0\n" + "\n" + " Rules\n" + " Rule the Universe (Clojure): 42\n" + " Rule the World (Java): 5\n" + "\n" + " Tags\n" + " oscar: 3\n" + " cesar: 10\n" + "\n" + " Most impacted files\n" + " /path/to/file: 3\n" + " /path/to/directory: 7\n" + "\n" + "More details at: http://nemo.sonarsource.org/project/issues?id=org.apache%3Astruts&assignees=lo.gin&createdAt=2010-05-18"); }