Search in sources :

Example 41 with Notification

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

the class NotificationDaemonTest method notifications_are_processed_one_by_one_even_with_new_API.

@Test
public void notifications_are_processed_one_by_one_even_with_new_API() {
    Notification notification1 = mock(Notification.class);
    Notification notification2 = mock(Notification.class);
    Notification notification3 = mock(Notification.class);
    Notification notification4 = mock(Notification.class);
    when(manager.getFromQueue()).thenReturn(notification1).thenReturn(notification2).thenReturn(notification3).thenReturn(notification4).thenReturn(null);
    underTest.start();
    verify(notificationService, timeout(2000)).deliver(notification1);
    inOrder.verify(notificationService).deliverEmails(singleton(notification1));
    inOrder.verify(notificationService).deliver(notification1);
    inOrder.verify(notificationService).deliverEmails(singleton(notification2));
    inOrder.verify(notificationService).deliver(notification2);
    inOrder.verify(notificationService).deliverEmails(singleton(notification3));
    inOrder.verify(notificationService).deliver(notification3);
    inOrder.verify(notificationService).deliverEmails(singleton(notification4));
    inOrder.verify(notificationService).deliver(notification4);
    inOrder.verifyNoMoreInteractions();
    underTest.stop();
}
Also used : Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 42 with Notification

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

the class NotificationDaemonTest method calls_both_api_and_deprecated_API.

@Test
public void calls_both_api_and_deprecated_API() {
    Notification notification = mock(Notification.class);
    when(manager.getFromQueue()).thenReturn(notification).thenReturn(null);
    underTest.start();
    verify(notificationService, timeout(2000)).deliver(notification);
    inOrder.verify(notificationService).deliverEmails(singleton(notification));
    inOrder.verify(notificationService).deliver(notification);
    inOrder.verifyNoMoreInteractions();
    underTest.stop();
}
Also used : Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 43 with Notification

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

the class EmailNotificationChannelTest method deliverAll_ignores_multiple_templates_by_notification_and_takes_the_first_one_only.

@Test
public void deliverAll_ignores_multiple_templates_by_notification_and_takes_the_first_one_only() throws MessagingException, IOException {
    String recipientEmail = "foo@donut";
    configure();
    Notification notification1 = mock(Notification.class);
    EmailTemplate template11 = mock(EmailTemplate.class);
    EmailTemplate template12 = mock(EmailTemplate.class);
    EmailMessage emailMessage11 = new EmailMessage().setTo(recipientEmail).setSubject("sub11").setPlainTextMessage("msg11");
    EmailMessage emailMessage12 = new EmailMessage().setTo(recipientEmail).setSubject("sub12").setPlainTextMessage("msg12");
    when(template11.format(notification1)).thenReturn(emailMessage11);
    when(template12.format(notification1)).thenReturn(emailMessage12);
    EmailDeliveryRequest request = new EmailDeliveryRequest(recipientEmail, notification1);
    EmailNotificationChannel underTest = new EmailNotificationChannel(configuration, new EmailTemplate[] { template11, template12 }, null);
    int count = underTest.deliverAll(Collections.singleton(request));
    assertThat(count).isOne();
    assertThat(smtpServer.getMessages()).hasSize(1);
    assertThat((String) smtpServer.getMessages().iterator().next().getMimeMessage().getContent()).contains(emailMessage11.getMessage());
}
Also used : EmailMessage(org.sonar.server.issue.notification.EmailMessage) EmailTemplate(org.sonar.server.issue.notification.EmailTemplate) EmailDeliveryRequest(org.sonar.server.notification.email.EmailNotificationChannel.EmailDeliveryRequest) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 44 with Notification

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

the class BuiltInQPChangeNotificationTest method serialize_and_parse_no_profile.

@Test
public void serialize_and_parse_no_profile() {
    Notification notification = new BuiltInQPChangeNotificationBuilder().build();
    BuiltInQPChangeNotificationBuilder result = BuiltInQPChangeNotificationBuilder.parse(notification);
    assertThat(result.getProfiles()).isEmpty();
}
Also used : Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 45 with Notification

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

the class BuiltInQualityProfilesUpdateListenerTest method add_profile_to_notification_for_removed_rules.

@Test
public void add_profile_to_notification_for_removed_rules() {
    enableNotificationInGlobalSettings();
    Multimap<QProfileName, ActiveRuleChange> profiles = ArrayListMultimap.create();
    Languages languages = new Languages();
    Tuple expectedTuple = addProfile(profiles, languages, DEACTIVATED);
    BuiltInQualityProfilesUpdateListener underTest = new BuiltInQualityProfilesUpdateListener(notificationManager, languages, settings.asConfig());
    underTest.onChange(profiles, 0, 1);
    ArgumentCaptor<Notification> notificationArgumentCaptor = ArgumentCaptor.forClass(Notification.class);
    verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture());
    verifyNoMoreInteractions(notificationManager);
    assertThat(BuiltInQPChangeNotificationBuilder.parse(notificationArgumentCaptor.getValue()).getProfiles()).extracting(Profile::getProfileName, Profile::getLanguageKey, Profile::getLanguageName, Profile::getRemovedRules).containsExactlyInAnyOrder(expectedTuple);
}
Also used : ActiveRuleChange(org.sonar.server.qualityprofile.ActiveRuleChange) Languages(org.sonar.api.resources.Languages) Tuple(org.assertj.core.groups.Tuple) 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