Search in sources :

Example 81 with Notification

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

the class QGChangeEmailTemplateTest 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.server.issue.notification.EmailMessage) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 82 with Notification

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

the class QGChangeEmailTemplateTest method shouldFormatAlertWithSeveralMessagesOnBranch.

@Test
public void shouldFormatAlertWithSeveralMessagesOnBranch() {
    Notification notification = createNotification("Failed", "violations > 4, coverage < 75%", "ERROR", "false").setFieldValue("branch", "feature");
    EmailMessage message = template.format(notification);
    assertThat(message.getMessageId(), is("alerts/45"));
    assertThat(message.getSubject(), is("Quality gate status changed on \"Foo (feature)\""));
    assertThat(message.getMessage(), is("" + "Project: Foo\n" + "Branch: feature\n" + "Version: V1-SNAP\n" + "Quality gate status: Failed\n" + "\n" + "Quality gate thresholds:\n" + "  - violations > 4\n" + "  - coverage < 75%\n" + "\n" + "More details at: http://nemo.sonarsource.org/dashboard?id=org.sonar.foo:foo&branch=feature"));
}
Also used : EmailMessage(org.sonar.server.issue.notification.EmailMessage) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 83 with Notification

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

the class QGChangeEmailTemplateTest method shouldFormatBackToGreenMessage.

@Test
public void shouldFormatBackToGreenMessage() {
    Notification notification = createNotification("Passed", "", "OK", "false");
    EmailMessage message = template.format(notification);
    assertThat(message.getMessageId(), is("alerts/45"));
    assertThat(message.getSubject(), is("\"Foo\" is back to green"));
    assertThat(message.getMessage(), is("" + "Project: Foo\n" + "Version: V1-SNAP\n" + "Quality gate status: Passed\n" + "\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 84 with Notification

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

the class QGChangeEmailTemplateTest method shouldFormatNewAlertWithOneMessageOnBranch.

@Test
public void shouldFormatNewAlertWithOneMessageOnBranch() {
    Notification notification = createNotification("Failed", "violations > 4", "ERROR", "true").setFieldValue("branch", "feature");
    EmailMessage message = template.format(notification);
    assertThat(message.getMessageId(), is("alerts/45"));
    assertThat(message.getSubject(), is("New quality gate threshold reached on \"Foo (feature)\""));
    assertThat(message.getMessage(), is("" + "Project: Foo\n" + "Branch: feature\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&branch=feature"));
}
Also used : EmailMessage(org.sonar.server.issue.notification.EmailMessage) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 85 with Notification

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

the class QGChangeEmailTemplateTest method shouldFormatAlertWithSeveralMessages.

@Test
public void shouldFormatAlertWithSeveralMessages() {
    Notification notification = createNotification("Failed", "violations > 4, coverage < 75%", "ERROR", "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" + "Version: V1-SNAP\n" + "Quality gate status: Failed\n" + "\n" + "Quality gate thresholds:\n" + "  - violations > 4\n" + "  - coverage < 75%\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)

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