Search in sources :

Example 11 with Notification

use of org.sonar.api.notifications.Notification in project sonarqube by SonarSource.

the class IssueChangesEmailTemplateTest method display_component_key_if_no_component_name.

@Test
public void display_component_key_if_no_component_name() throws Exception {
    Notification notification = generateNotification().setFieldValue("componentName", null);
    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/display_component_key_if_no_component_name.txt"), StandardCharsets.UTF_8);
    expected = StringUtils.remove(expected, '\r');
    assertThat(message).isEqualTo(expected);
}
Also used : EmailMessage(org.sonar.plugins.emailnotifications.api.EmailMessage) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 12 with Notification

use of org.sonar.api.notifications.Notification in project sonarqube by SonarSource.

the class IssueChangesEmailTemplateTest method email_should_display_resolution_change.

@Test
public void email_should_display_resolution_change() throws Exception {
    Notification notification = generateNotification().setFieldValue("old.resolution", "FALSE-POSITIVE").setFieldValue("new.resolution", "FIXED");
    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_should_display_resolution_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 13 with Notification

use of org.sonar.api.notifications.Notification in project sonarqube by SonarSource.

the class AlertsEmailTemplateTest method shouldFormatNewAlertWithSeveralMessages.

@Test
public void shouldFormatNewAlertWithSeveralMessages() {
    Notification notification = createNotification("Orange (was Red)", "violations > 4, coverage < 75%", "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 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 14 with Notification

use of org.sonar.api.notifications.Notification 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 15 with Notification

use of org.sonar.api.notifications.Notification 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)

Aggregations

Notification (org.sonar.api.notifications.Notification)90 Test (org.junit.Test)83 EmailMessage (org.sonar.plugins.emailnotifications.api.EmailMessage)14 EmailMessage (org.sonar.server.issue.notification.EmailMessage)13 NotificationChannel (org.sonar.api.notifications.NotificationChannel)12 List (java.util.List)7 IntStream (java.util.stream.IntStream)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 Mockito.mock (org.mockito.Mockito.mock)5 Mockito.when (org.mockito.Mockito.when)5 ReportAnalysisFailureNotification (org.sonar.ce.task.projectanalysis.notification.ReportAnalysisFailureNotification)5 Tuple (org.assertj.core.groups.Tuple)4 Languages (org.sonar.api.resources.Languages)4 ActiveRuleChange (org.sonar.server.qualityprofile.ActiveRuleChange)4 Collections (java.util.Collections)3 Random (java.util.Random)3 Before (org.junit.Before)3 Mockito.verify (org.mockito.Mockito.verify)3 Mockito.verifyNoMoreInteractions (org.mockito.Mockito.verifyNoMoreInteractions)3 Mockito.verifyZeroInteractions (org.mockito.Mockito.verifyZeroInteractions)3