Search in sources :

Example 31 with Notification

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

the class ReportAnalysisFailureNotificationExecutionListenerTest method onEnd_ignores_null_CeTaskResult_argument.

@Test
public void onEnd_ignores_null_CeTaskResult_argument() {
    String taskUuid = randomAlphanumeric(12);
    initMocksToPassConditions(taskUuid, random.nextInt(999_999), (long) random.nextInt(999_999));
    Notification notificationMock = mockSerializer();
    underTest.onEnd(ceTaskMock, CeActivityDto.Status.FAILED, randomDuration(), null, null);
    verify(notificationService).deliver(same(notificationMock));
}
Also used : Notification(org.sonar.api.notifications.Notification) ReportAnalysisFailureNotification(org.sonar.ce.task.projectanalysis.notification.ReportAnalysisFailureNotification) Test(org.junit.Test)

Example 32 with Notification

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

the class ReportAnalysisFailureNotificationExecutionListenerTest method onEnd_creates_notification_with_null_error_message_if_Throwable_is_null.

@Test
public void onEnd_creates_notification_with_null_error_message_if_Throwable_is_null() {
    String taskUuid = randomAlphanumeric(12);
    initMocksToPassConditions(taskUuid, random.nextInt(999_999), (long) random.nextInt(999_999));
    Notification notificationMock = mockSerializer();
    underTest.onEnd(ceTaskMock, CeActivityDto.Status.FAILED, randomDuration(), ceTaskResultMock, null);
    verify(notificationService).deliver(same(notificationMock));
    ArgumentCaptor<ReportAnalysisFailureNotificationBuilder> notificationCaptor = verifyAndCaptureSerializedNotification();
    ReportAnalysisFailureNotificationBuilder reportAnalysisFailureNotificationBuilder = notificationCaptor.getValue();
    assertThat(reportAnalysisFailureNotificationBuilder.getErrorMessage()).isNull();
}
Also used : ReportAnalysisFailureNotificationBuilder(org.sonar.ce.task.projectanalysis.notification.ReportAnalysisFailureNotificationBuilder) Notification(org.sonar.api.notifications.Notification) ReportAnalysisFailureNotification(org.sonar.ce.task.projectanalysis.notification.ReportAnalysisFailureNotification) Test(org.junit.Test)

Example 33 with Notification

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

the class ReportAnalysisFailureNotificationExecutionListenerTest method onEnd_uses_system_data_as_failedAt_if_task_has_no_executedAt.

@Test
public void onEnd_uses_system_data_as_failedAt_if_task_has_no_executedAt() {
    String taskUuid = randomAlphanumeric(12);
    initMocksToPassConditions(taskUuid, random.nextInt(999_999), null);
    long now = random.nextInt(999_999);
    when(system2.now()).thenReturn(now);
    Notification notificationMock = mockSerializer();
    underTest.onEnd(ceTaskMock, CeActivityDto.Status.FAILED, randomDuration(), ceTaskResultMock, null);
    verify(notificationService).deliver(same(notificationMock));
    ArgumentCaptor<ReportAnalysisFailureNotificationBuilder> notificationCaptor = verifyAndCaptureSerializedNotification();
    assertThat(notificationCaptor.getValue().getTask().getFailedAt()).isEqualTo(now);
}
Also used : ReportAnalysisFailureNotificationBuilder(org.sonar.ce.task.projectanalysis.notification.ReportAnalysisFailureNotificationBuilder) Notification(org.sonar.api.notifications.Notification) ReportAnalysisFailureNotification(org.sonar.ce.task.projectanalysis.notification.ReportAnalysisFailureNotification) Test(org.junit.Test)

Example 34 with Notification

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

the class NotificationQueueDaoTest method should_insert_new_notification_queue.

@Test
public void should_insert_new_notification_queue() throws Exception {
    NotificationQueueDto notificationQueueDto = toNotificationQueueDto(new Notification("email"));
    dao.insert(Arrays.asList(notificationQueueDto));
    assertThat(dao.count()).isOne();
    assertThat(dao.selectOldest(1).get(0).toNotification().getType()).isEqualTo("email");
}
Also used : NotificationQueueDto.toNotificationQueueDto(org.sonar.db.notification.NotificationQueueDto.toNotificationQueueDto) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 35 with Notification

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

the class NotificationQueueDaoTest method should_delete_notification.

@Test
public void should_delete_notification() {
    List<NotificationQueueDto> notifs = IntStream.range(0, 30).mapToObj(i -> toNotificationQueueDto(new Notification("foo_" + i))).collect(toList());
    dao.insert(notifs);
    db.commit();
    List<String> uuids = selectAllUuid();
    dao.delete(uuids.stream().limit(10).map(uuid -> new NotificationQueueDto().setUuid(uuid)).collect(toList()));
    assertThat(selectAllUuid()).containsOnly(uuids.stream().skip(10).toArray(String[]::new));
}
Also used : IntStream(java.util.stream.IntStream) DbTester(org.sonar.db.DbTester) Arrays(java.util.Arrays) System2(org.sonar.api.utils.System2) Notification(org.sonar.api.notifications.Notification) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Answer(org.mockito.stubbing.Answer) List(java.util.List) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Collectors.toList(java.util.stream.Collectors.toList) NotificationQueueDto.toNotificationQueueDto(org.sonar.db.notification.NotificationQueueDto.toNotificationQueueDto) Rule(org.junit.Rule) Mockito.mock(org.mockito.Mockito.mock) NotificationQueueDto.toNotificationQueueDto(org.sonar.db.notification.NotificationQueueDto.toNotificationQueueDto) 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