Search in sources :

Example 76 with Notification

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

the class DefaultNotificationManagerTest method shouldPersist.

@Test
public void shouldPersist() {
    Notification notification = new Notification("test");
    underTest.scheduleForSending(notification);
    verify(notificationQueueDao, only()).insert(any(List.class));
}
Also used : List(java.util.List) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 77 with Notification

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

the class DefaultNotificationManagerTest method shouldNotFailWhenUnableToDeserialize.

// SONAR-4739
@Test
public void shouldNotFailWhenUnableToDeserialize() throws Exception {
    NotificationQueueDto dto1 = mock(NotificationQueueDto.class);
    when(dto1.toNotification()).thenThrow(new InvalidClassException("Pouet"));
    List<NotificationQueueDto> dtos = Arrays.asList(dto1);
    when(notificationQueueDao.selectOldest(1)).thenReturn(dtos);
    underTest = spy(underTest);
    assertThat(underTest.<Notification>getFromQueue()).isNull();
    assertThat(underTest.<Notification>getFromQueue()).isNull();
    verify(underTest, times(1)).logDeserializationIssue();
}
Also used : NotificationQueueDto(org.sonar.db.notification.NotificationQueueDto) InvalidClassException(java.io.InvalidClassException) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 78 with Notification

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

the class NotificationServiceTest method deliverEmails_collection_has_no_effect_if_no_handler_nor_dispatcher.

@Test
public void deliverEmails_collection_has_no_effect_if_no_handler_nor_dispatcher() {
    List<Notification> notifications = IntStream.range(0, 1 + new Random().nextInt(20)).mapToObj(i -> mock(Notification.class)).collect(Collectors.toList());
    NotificationService underTest = new NotificationService(dbClient);
    assertThat(underTest.deliverEmails(notifications)).isZero();
    verifyZeroInteractions(dbClient);
}
Also used : IntStream(java.util.stream.IntStream) ImmutableSet(com.google.common.collect.ImmutableSet) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) Notification(org.sonar.api.notifications.Notification) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Random(java.util.Random) Test(org.junit.Test) PropertiesDao(org.sonar.db.property.PropertiesDao) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) DbClient(org.sonar.db.DbClient) ArgumentMatchers.anyCollection(org.mockito.ArgumentMatchers.anyCollection) List(java.util.List) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Optional(java.util.Optional) Collections(java.util.Collections) Mockito.reset(org.mockito.Mockito.reset) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Random(java.util.Random) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 79 with Notification

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

the class NotificationServiceTest method deliverEmails_fails_with_IAE_if_type_of_collection_is_Notification.

@Test
public void deliverEmails_fails_with_IAE_if_type_of_collection_is_Notification() {
    NotificationHandler handler = mock(NotificationHandler1.class);
    List<Notification> notifications = IntStream.range(0, 1 + new Random().nextInt(20)).mapToObj(i -> new Notification("i")).collect(Collectors.toList());
    NotificationService underTest = new NotificationService(dbClient, new NotificationHandler[] { handler });
    assertThatThrownBy(() -> underTest.deliverEmails(notifications)).isInstanceOf(IllegalArgumentException.class).hasMessage("Type of notification objects must be a subtype of Notification");
}
Also used : IntStream(java.util.stream.IntStream) ImmutableSet(com.google.common.collect.ImmutableSet) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) Notification(org.sonar.api.notifications.Notification) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Random(java.util.Random) Test(org.junit.Test) PropertiesDao(org.sonar.db.property.PropertiesDao) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) DbClient(org.sonar.db.DbClient) ArgumentMatchers.anyCollection(org.mockito.ArgumentMatchers.anyCollection) List(java.util.List) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Optional(java.util.Optional) Collections(java.util.Collections) Mockito.reset(org.mockito.Mockito.reset) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Random(java.util.Random) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 80 with Notification

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

the class QGChangeEmailTemplateTest method shouldFormatNewAlertWithSeveralMessages.

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