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.");
}
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();
}
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"));
}
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());
}
Aggregations