Search in sources :

Example 36 with Notification

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

the class NotificationQueueDaoTest method should_count_notification_queue.

@Test
public void should_count_notification_queue() {
    NotificationQueueDto notificationQueueDto = toNotificationQueueDto(new Notification("email"));
    assertThat(dao.count()).isZero();
    dao.insert(Arrays.asList(notificationQueueDto));
    assertThat(dao.count()).isOne();
}
Also used : NotificationQueueDto.toNotificationQueueDto(org.sonar.db.notification.NotificationQueueDto.toNotificationQueueDto) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 37 with Notification

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

the class DefaultNotificationManagerTest method shouldGetFromQueueAndDelete.

@Test
public void shouldGetFromQueueAndDelete() {
    Notification notification = new Notification("test");
    NotificationQueueDto dto = NotificationQueueDto.toNotificationQueueDto(notification);
    List<NotificationQueueDto> dtos = Arrays.asList(dto);
    when(notificationQueueDao.selectOldest(1)).thenReturn(dtos);
    assertThat(underTest.<Notification>getFromQueue()).isNotNull();
    InOrder inOrder = inOrder(notificationQueueDao);
    inOrder.verify(notificationQueueDao).selectOldest(1);
    inOrder.verify(notificationQueueDao).delete(dtos);
}
Also used : NotificationQueueDto(org.sonar.db.notification.NotificationQueueDto) InOrder(org.mockito.InOrder) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 38 with Notification

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

the class QGChangeEmailTemplateTest method shouldFormatNewAlertWithThresholdProperlyFormatted.

@UseDataProvider("alertTextAndFormattedText")
@Test
public void shouldFormatNewAlertWithThresholdProperlyFormatted(String alertText, String expectedFormattedAlertText) {
    Notification notification = createNotification("Failed", alertText, "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: " + expectedFormattedAlertText + "\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) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 39 with Notification

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

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

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