Search in sources :

Example 16 with EmailMessage

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

the class AlertsEmailTemplateTest method shouldFormatNewAlertWithOneMessage.

@Test
public void shouldFormatNewAlertWithOneMessage() {
    Notification notification = createNotification("Orange (was Red)", "violations > 4", "WARN", "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" + "Quality gate status: Orange (was Red)\n" + "\n" + "New quality gate threshold: violations > 4\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 17 with EmailMessage

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

the class AlertsEmailTemplateTest method shouldNotFormatIfNotCorrectNotification.

@Test
public void shouldNotFormatIfNotCorrectNotification() {
    Notification notification = new Notification("other-notif");
    EmailMessage message = template.format(notification);
    assertThat(message, nullValue());
}
Also used : EmailMessage(org.sonar.plugins.emailnotifications.api.EmailMessage) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 18 with EmailMessage

use of org.sonar.plugins.emailnotifications.api.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").setMessage("Bar");
    underTest.deliver(emailMessage);
}
Also used : EmailMessage(org.sonar.plugins.emailnotifications.api.EmailMessage) Test(org.junit.Test)

Example 19 with EmailMessage

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

the class IssueChangesEmailTemplateTest method email_should_display_plan_change.

@Test
public void email_should_display_plan_change() throws Exception {
    Notification notification = generateNotification().setFieldValue("old.actionPlan", null).setFieldValue("new.actionPlan", "ABC 1.0");
    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_action_plan_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 20 with EmailMessage

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

the class IssueChangesEmailTemplateTest method notification_contains_user_login_when_user_is_removed.

@Test
public void notification_contains_user_login_when_user_is_removed() {
    db.users().insertUser(newUserDto().setLogin("simon").setName("Simon").setActive(false));
    Notification notification = new IssueChangeNotification().setChangeAuthorLogin("simon").setProject("Struts", "org.apache:struts");
    EmailMessage message = underTest.format(notification);
    assertThat(message.getFrom()).isEqualTo("simon");
}
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