Search in sources :

Example 6 with EmailMessage

use of org.sonar.plugins.emailnotifications.api.EmailMessage in project sonarqube by SonarSource.

the class NewIssuesEmailTemplateTest method format_email_with_all_fields_filled.

@Test
public void format_email_with_all_fields_filled() throws Exception {
    Notification notification = newNotification();
    addAssignees(notification);
    addRules(notification);
    addTags(notification);
    addComponents(notification);
    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_all_details.txt"), StandardCharsets.UTF_8);
    assertThat(message.getMessage()).startsWith(StringUtils.remove(expectedContent, '\r'));
}
Also used : EmailMessage(org.sonar.plugins.emailnotifications.api.EmailMessage) Matchers.anyString(org.mockito.Matchers.anyString) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 7 with EmailMessage

use of org.sonar.plugins.emailnotifications.api.EmailMessage in project sonarqube by SonarSource.

the class IssueChangesEmailTemplateTest method email_should_display_assignee_change.

@Test
public void email_should_display_assignee_change() throws Exception {
    Notification notification = generateNotification().setFieldValue("old.assignee", "simon").setFieldValue("new.assignee", "louis");
    EmailMessage email = underTest.format(notification);
    assertThat(email.getMessageId()).isEqualTo("issue-changes/ABCDE");
    assertThat(email.getSubject()).isEqualTo("Struts, change on issue #ABCDE");
    String message = email.getMessage();
    String expected = Resources.toString(Resources.getResource("org/sonar/server/issue/notification/IssueChangesEmailTemplateTest/email_with_assignee_change.txt"), StandardCharsets.UTF_8);
    expected = StringUtils.remove(expected, '\r');
    assertThat(message).isEqualTo(expected);
    assertThat(email.getFrom()).isNull();
}
Also used : EmailMessage(org.sonar.plugins.emailnotifications.api.EmailMessage) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 8 with EmailMessage

use of org.sonar.plugins.emailnotifications.api.EmailMessage in project sonarqube by SonarSource.

the class IssueChangesEmailTemplateTest method test_email_with_multiple_changes.

@Test
public void test_email_with_multiple_changes() throws Exception {
    Notification notification = generateNotification().setFieldValue("comment", "How to fix it?").setFieldValue("old.assignee", "simon").setFieldValue("new.assignee", "louis").setFieldValue("new.resolution", "FALSE-POSITIVE").setFieldValue("new.status", "RESOLVED").setFieldValue("new.type", "BUG").setFieldValue("new.tags", "bug performance");
    EmailMessage email = underTest.format(notification);
    assertThat(email.getMessageId()).isEqualTo("issue-changes/ABCDE");
    assertThat(email.getSubject()).isEqualTo("Struts, change on issue #ABCDE");
    String message = email.getMessage();
    String expected = Resources.toString(Resources.getResource("org/sonar/server/issue/notification/IssueChangesEmailTemplateTest/email_with_multiple_changes.txt"), StandardCharsets.UTF_8);
    expected = StringUtils.remove(expected, '\r');
    assertThat(message).isEqualTo(expected);
    assertThat(email.getFrom()).isNull();
}
Also used : EmailMessage(org.sonar.plugins.emailnotifications.api.EmailMessage) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 9 with EmailMessage

use of org.sonar.plugins.emailnotifications.api.EmailMessage in project sonarqube by SonarSource.

the class IssueChangesEmailTemplateTest method display_component_key_if_no_component_name.

@Test
public void display_component_key_if_no_component_name() throws Exception {
    Notification notification = generateNotification().setFieldValue("componentName", null);
    EmailMessage email = underTest.format(notification);
    assertThat(email.getMessageId()).isEqualTo("issue-changes/ABCDE");
    assertThat(email.getSubject()).isEqualTo("Struts, change on issue #ABCDE");
    String message = email.getMessage();
    String expected = Resources.toString(Resources.getResource("org/sonar/server/issue/notification/IssueChangesEmailTemplateTest/display_component_key_if_no_component_name.txt"), StandardCharsets.UTF_8);
    expected = StringUtils.remove(expected, '\r');
    assertThat(message).isEqualTo(expected);
}
Also used : EmailMessage(org.sonar.plugins.emailnotifications.api.EmailMessage) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 10 with EmailMessage

use of org.sonar.plugins.emailnotifications.api.EmailMessage in project sonarqube by SonarSource.

the class IssueChangesEmailTemplateTest method email_should_display_resolution_change.

@Test
public void email_should_display_resolution_change() throws Exception {
    Notification notification = generateNotification().setFieldValue("old.resolution", "FALSE-POSITIVE").setFieldValue("new.resolution", "FIXED");
    EmailMessage email = underTest.format(notification);
    assertThat(email.getMessageId()).isEqualTo("issue-changes/ABCDE");
    assertThat(email.getSubject()).isEqualTo("Struts, change on issue #ABCDE");
    String message = email.getMessage();
    String expected = Resources.toString(Resources.getResource("org/sonar/server/issue/notification/IssueChangesEmailTemplateTest/email_should_display_resolution_change.txt"), StandardCharsets.UTF_8);
    expected = StringUtils.remove(expected, '\r');
    assertThat(message).isEqualTo(expected);
    assertThat(email.getFrom()).isNull();
}
Also used : EmailMessage(org.sonar.plugins.emailnotifications.api.EmailMessage) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Aggregations

EmailMessage (org.sonar.plugins.emailnotifications.api.EmailMessage)34 Test (org.junit.Test)29 Notification (org.sonar.api.notifications.Notification)25 MimeMessage (javax.mail.internet.MimeMessage)2 Matchers.anyString (org.mockito.Matchers.anyString)2 WiserMessage (org.subethamail.wiser.WiserMessage)2 EmailException (org.apache.commons.mail.EmailException)1 User (org.sonar.api.user.User)1