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();
}
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();
}
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());
}
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();
}
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);
}
Aggregations