Search in sources :

Example 46 with Notification

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

the class AlertsEmailTemplateTest method shouldFormatAlertWithSeveralMessages.

@Test
public void shouldFormatAlertWithSeveralMessages() {
    Notification notification = createNotification("Orange (was Red)", "violations > 4, coverage < 75%", "WARN", "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" + "Quality gate status: Orange (was Red)\n" + "\n" + "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 47 with Notification

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

the class NotificationQueueDto method toNotification.

public Notification toNotification() throws IOException, ClassNotFoundException {
    if (this.data == null) {
        return null;
    }
    ByteArrayInputStream byteArrayInputStream = null;
    try {
        byteArrayInputStream = new ByteArrayInputStream(this.data);
        ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
        Object result = objectInputStream.readObject();
        objectInputStream.close();
        return (Notification) result;
    } finally {
        IOUtils.closeQuietly(byteArrayInputStream);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Notification(org.sonar.api.notifications.Notification) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

Notification (org.sonar.api.notifications.Notification)47 Test (org.junit.Test)42 EmailMessage (org.sonar.plugins.emailnotifications.api.EmailMessage)25 NotificationChannel (org.sonar.api.notifications.NotificationChannel)12 Matchers.anyString (org.mockito.Matchers.anyString)2 Event (org.sonar.server.computation.task.projectanalysis.event.Event)2 QualityGateStatus (org.sonar.server.computation.task.projectanalysis.measure.QualityGateStatus)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 List (java.util.List)1 InOrder (org.mockito.InOrder)1 NotificationQueueDto (org.sonar.db.notification.NotificationQueueDto)1