use of org.sonar.server.issue.notification.EmailMessage in project sonarqube by SonarSource.
the class QGChangeEmailTemplateTest method shouldFormatNewAlertWithOneMessage.
@Test
public void shouldFormatNewAlertWithOneMessage() {
Notification notification = createNotification("Failed", "violations > 4", "ERROR", "true");
EmailMessage message = template.format(notification);
assertThat(message.getMessageId(), is("alerts/45"));
assertThat(message.getSubject(), is("New quality gate threshold reached on \"Foo\""));
assertThat(message.getMessage(), is("" + "Project: Foo\n" + "Version: V1-SNAP\n" + "Quality gate status: Failed\n" + "\n" + "New quality gate threshold: violations > 4\n" + "\n" + "More details at: http://nemo.sonarsource.org/dashboard?id=org.sonar.foo:foo"));
}
use of org.sonar.server.issue.notification.EmailMessage in project sonarqube by SonarSource.
the class QGChangeEmailTemplateTest method shouldFormatNewAlertWithoutVersion.
@Test
public void shouldFormatNewAlertWithoutVersion() {
Notification notification = createNotification("Failed", "violations > 4", "ERROR", "true").setFieldValue("projectVersion", null);
EmailMessage message = template.format(notification);
assertThat(message.getMessageId(), is("alerts/45"));
assertThat(message.getSubject(), is("New quality gate threshold reached on \"Foo\""));
assertThat(message.getMessage(), is("" + "Project: Foo\n" + "Quality gate status: Failed\n" + "\n" + "New quality gate threshold: violations > 4\n" + "\n" + "More details at: http://nemo.sonarsource.org/dashboard?id=org.sonar.foo:foo"));
}
use of org.sonar.server.issue.notification.EmailMessage in project sonarqube by SonarSource.
the class EmailNotificationChannelTest method deliverAll_ignores_multiple_templates_by_notification_and_takes_the_first_one_only.
@Test
public void deliverAll_ignores_multiple_templates_by_notification_and_takes_the_first_one_only() throws MessagingException, IOException {
String recipientEmail = "foo@donut";
configure();
Notification notification1 = mock(Notification.class);
EmailTemplate template11 = mock(EmailTemplate.class);
EmailTemplate template12 = mock(EmailTemplate.class);
EmailMessage emailMessage11 = new EmailMessage().setTo(recipientEmail).setSubject("sub11").setPlainTextMessage("msg11");
EmailMessage emailMessage12 = new EmailMessage().setTo(recipientEmail).setSubject("sub12").setPlainTextMessage("msg12");
when(template11.format(notification1)).thenReturn(emailMessage11);
when(template12.format(notification1)).thenReturn(emailMessage12);
EmailDeliveryRequest request = new EmailDeliveryRequest(recipientEmail, notification1);
EmailNotificationChannel underTest = new EmailNotificationChannel(configuration, new EmailTemplate[] { template11, template12 }, null);
int count = underTest.deliverAll(Collections.singleton(request));
assertThat(count).isOne();
assertThat(smtpServer.getMessages()).hasSize(1);
assertThat((String) smtpServer.getMessages().iterator().next().getMimeMessage().getContent()).contains(emailMessage11.getMessage());
}
use of org.sonar.server.issue.notification.EmailMessage in project sonarqube by SonarSource.
the class EmailNotificationChannelTest method shouldNotThrowAnExceptionWhenUnableToSendEmail.
@Test
public void shouldNotThrowAnExceptionWhenUnableToSendEmail() {
configure();
smtpServer.stop();
EmailMessage emailMessage = new EmailMessage().setTo("user@nowhere").setSubject("Foo").setPlainTextMessage("Bar");
boolean delivered = underTest.deliver(emailMessage);
assertThat(delivered).isFalse();
}
use of org.sonar.server.issue.notification.EmailMessage in project sonarqube by SonarSource.
the class BuiltInQPChangeNotificationTemplateTest method notification_contains_count_of_removed_rules.
@Test
public void notification_contains_count_of_removed_rules() {
String profileName = newProfileName();
String languageKey = newLanguageKey();
String languageName = newLanguageName();
BuiltInQPChangeNotificationBuilder notification = new BuiltInQPChangeNotificationBuilder().addProfile(Profile.newBuilder().setProfileName(profileName).setLanguageKey(languageKey).setLanguageName(languageName).setRemovedRules(2).build());
EmailMessage emailMessage = underTest.format(notification.build());
assertMessage(emailMessage, "\n 2 rules removed\n");
}
Aggregations