Search in sources :

Example 31 with EmailMessage

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

the class EmailNotificationChannelTest method shouldSendThreadedEmail.

@Test
public void shouldSendThreadedEmail() throws Exception {
    configure();
    EmailMessage emailMessage = new EmailMessage().setMessageId("reviews/view/1").setFrom("Full Username").setTo("user@nowhere").setSubject("Review #3").setMessage("I'll take care of this violation.");
    underTest.deliver(emailMessage);
    List<WiserMessage> messages = smtpServer.getMessages();
    assertThat(messages).hasSize(1);
    MimeMessage email = messages.get(0).getMimeMessage();
    assertThat(email.getHeader("Content-Type", null)).isEqualTo("text/plain; charset=UTF-8");
    assertThat(email.getHeader("In-Reply-To", null)).isEqualTo("<reviews/view/1@nemo.sonarsource.org>");
    assertThat(email.getHeader("References", null)).isEqualTo("<reviews/view/1@nemo.sonarsource.org>");
    assertThat(email.getHeader("List-ID", null)).isEqualTo("SonarQube <sonar.nemo.sonarsource.org>");
    assertThat(email.getHeader("List-Archive", null)).isEqualTo("http://nemo.sonarsource.org");
    assertThat(email.getHeader("From", ",")).isEqualTo("\"Full Username (SonarQube)\" <server@nowhere>");
    assertThat(email.getHeader("To", null)).isEqualTo("<user@nowhere>");
    assertThat(email.getHeader("Subject", null)).isEqualTo("[SONARQUBE] Review #3");
    assertThat((String) email.getContent()).startsWith("I'll take care of this violation.");
}
Also used : EmailMessage(org.sonar.plugins.emailnotifications.api.EmailMessage) MimeMessage(javax.mail.internet.MimeMessage) WiserMessage(org.subethamail.wiser.WiserMessage) Test(org.junit.Test)

Example 32 with EmailMessage

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

the class EmailNotificationChannelTest method shouldNotSendEmailWhenHostnameNotConfigured.

@Test
public void shouldNotSendEmailWhenHostnameNotConfigured() {
    EmailMessage emailMessage = new EmailMessage().setTo("user@nowhere").setSubject("Foo").setMessage("Bar");
    underTest.deliver(emailMessage);
    assertThat(smtpServer.getMessages()).isEmpty();
}
Also used : EmailMessage(org.sonar.plugins.emailnotifications.api.EmailMessage) Test(org.junit.Test)

Example 33 with EmailMessage

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

the class AlertsEmailTemplateTest method shouldFormatAlertWithSeveralMessages.

@Test
public void shouldFormatAlertWithSeveralMessages() {
    Notification notification = createNotification("Orange (was Red)", "violations > 4, coverage < 75%", "WARN", "false");
    EmailMessage message = template.format(notification);
    assertThat(message.getMessageId(), is("alerts/45"));
    assertThat(message.getSubject(), is("Quality gate status changed on \"Foo\""));
    assertThat(message.getMessage(), is("" + "Project: Foo\n" + "Quality gate status: Orange (was Red)\n" + "\n" + "Quality gate thresholds:\n" + "  - violations > 4\n" + "  - coverage < 75%\n" + "\n" + "See it in SonarQube: http://nemo.sonarsource.org/dashboard/index/org.sonar.foo:foo"));
}
Also used : EmailMessage(org.sonar.plugins.emailnotifications.api.EmailMessage) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 34 with EmailMessage

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

the class AbstractNewIssuesEmailTemplate method format.

@Override
public EmailMessage format(Notification notification) {
    if (shouldNotFormat(notification)) {
        return null;
    }
    String projectName = checkNotNull(notification.getFieldValue(FIELD_PROJECT_NAME));
    StringBuilder message = new StringBuilder();
    message.append("Project: ").append(projectName).append(NEW_LINE).append(NEW_LINE);
    appendSeverity(message, notification);
    appendAssignees(message, notification);
    appendRules(message, notification);
    appendTags(message, notification);
    appendComponents(message, notification);
    appendFooter(message, notification);
    return new EmailMessage().setMessageId(notification.getType() + "/" + notification.getFieldValue(FIELD_PROJECT_KEY)).setSubject(subject(notification, projectName)).setMessage(message.toString());
}
Also used : EmailMessage(org.sonar.plugins.emailnotifications.api.EmailMessage)

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