Search in sources :

Example 6 with EmailMessage

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"));
}
Also used : EmailMessage(org.sonar.server.issue.notification.EmailMessage) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 7 with EmailMessage

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"));
}
Also used : EmailMessage(org.sonar.server.issue.notification.EmailMessage) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 8 with EmailMessage

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());
}
Also used : EmailMessage(org.sonar.server.issue.notification.EmailMessage) EmailTemplate(org.sonar.server.issue.notification.EmailTemplate) EmailDeliveryRequest(org.sonar.server.notification.email.EmailNotificationChannel.EmailDeliveryRequest) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 9 with EmailMessage

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();
}
Also used : EmailMessage(org.sonar.server.issue.notification.EmailMessage) Test(org.junit.Test)

Example 10 with EmailMessage

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");
}
Also used : EmailMessage(org.sonar.server.issue.notification.EmailMessage) Test(org.junit.Test)

Aggregations

EmailMessage (org.sonar.server.issue.notification.EmailMessage)32 Test (org.junit.Test)27 Notification (org.sonar.api.notifications.Notification)13 CheckForNull (javax.annotation.CheckForNull)3 MimeMessage (javax.mail.internet.MimeMessage)3 WiserMessage (org.subethamail.wiser.WiserMessage)3 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 Date (java.util.Date)2 EmailException (org.apache.commons.mail.EmailException)2 DateUtils.formatDate (org.sonar.api.utils.DateUtils.formatDate)2 EmailTemplate (org.sonar.server.issue.notification.EmailTemplate)2 EmailDeliveryRequest (org.sonar.server.notification.email.EmailNotificationChannel.EmailDeliveryRequest)2 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)1 DataProviderRunner (com.tngtech.java.junit.dataprovider.DataProviderRunner)1 IOException (java.io.IOException)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Random (java.util.Random)1 Set (java.util.Set)1