use of org.sonar.server.notification.email.EmailNotificationChannel in project sonarqube by SonarSource.
the class NewIssuesNotificationHandlerTest method deliver_has_no_effect_if_emailNotificationChannel_is_disabled.
@Test
public void deliver_has_no_effect_if_emailNotificationChannel_is_disabled() {
when(emailNotificationChannel.isActivated()).thenReturn(false);
Set<NewIssuesNotification> notifications = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> mock(NewIssuesNotification.class)).collect(toSet());
int deliver = underTest.deliver(notifications);
assertThat(deliver).isZero();
verifyZeroInteractions(notificationManager);
verify(emailNotificationChannel).isActivated();
verifyNoMoreInteractions(emailNotificationChannel);
notifications.forEach(Mockito::verifyZeroInteractions);
}
use of org.sonar.server.notification.email.EmailNotificationChannel in project sonarqube by SonarSource.
the class NewIssuesNotificationHandlerTest method deliver_ignores_notification_without_projectKey.
@Test
public void deliver_ignores_notification_without_projectKey() {
String projectKey = randomAlphabetic(10);
Set<NewIssuesNotification> withProjectKey = IntStream.range(0, 1 + new Random().nextInt(5)).mapToObj(i -> newNotification(projectKey)).collect(toSet());
Set<NewIssuesNotification> noProjectKey = IntStream.range(0, 1 + new Random().nextInt(5)).mapToObj(i -> newNotification(null)).collect(toSet());
Set<EmailRecipient> emailRecipients = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> "user_" + i).map(login -> new EmailRecipient(login, emailOf(login))).collect(toSet());
Set<EmailDeliveryRequest> expectedRequests = emailRecipients.stream().flatMap(emailRecipient -> withProjectKey.stream().map(notif -> new EmailDeliveryRequest(emailRecipient.getEmail(), notif))).collect(toSet());
when(emailNotificationChannel.isActivated()).thenReturn(true);
when(notificationManager.findSubscribedEmailRecipients(NEW_ISSUES_DISPATCHER_KEY, projectKey, ALL_MUST_HAVE_ROLE_USER)).thenReturn(emailRecipients);
Set<NewIssuesNotification> notifications = Stream.of(withProjectKey.stream(), noProjectKey.stream()).flatMap(t -> t).collect(toSet());
int deliver = underTest.deliver(notifications);
assertThat(deliver).isZero();
verify(notificationManager).findSubscribedEmailRecipients(NEW_ISSUES_DISPATCHER_KEY, projectKey, ALL_MUST_HAVE_ROLE_USER);
verifyNoMoreInteractions(notificationManager);
verify(emailNotificationChannel).isActivated();
verify(emailNotificationChannel).deliverAll(expectedRequests);
verifyNoMoreInteractions(emailNotificationChannel);
}
use of org.sonar.server.notification.email.EmailNotificationChannel in project sonarqube by SonarSource.
the class BuiltInQPChangeNotificationHandlerTest method deliver_create_emailRequest_for_each_notification_and_for_each_global_administer_email_subscriber.
@Test
public void deliver_create_emailRequest_for_each_notification_and_for_each_global_administer_email_subscriber() {
when(emailNotificationChannel.isActivated()).thenReturn(true);
Set<BuiltInQPChangeNotification> notifications = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> mock(BuiltInQPChangeNotification.class)).collect(toSet());
Set<EmailSubscriberDto> emailSubscribers = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> EmailSubscriberDto.create("login_" + i, true, "login_" + i + "@foo")).collect(toSet());
when(authorizationDao.selectQualityProfileAdministratorLogins(dbSession)).thenReturn(emailSubscribers);
Set<EmailNotificationChannel.EmailDeliveryRequest> expectedRequests = notifications.stream().flatMap(notification -> emailSubscribers.stream().map(subscriber -> new EmailNotificationChannel.EmailDeliveryRequest(subscriber.getEmail(), notification))).collect(toSet());
int deliveries = new Random().nextInt(expectedRequests.size());
when(emailNotificationChannel.deliverAll(expectedRequests)).thenReturn(deliveries);
int deliver = underTest.deliver(notifications);
assertThat(deliver).isEqualTo(deliveries);
verify(emailNotificationChannel).isActivated();
verify(emailNotificationChannel).deliverAll(expectedRequests);
verifyNoMoreInteractions(emailNotificationChannel);
verify(dbClient).openSession(false);
verify(dbClient).authorizationDao();
verifyNoMoreInteractions(dbClient);
verify(authorizationDao).selectQualityProfileAdministratorLogins(dbSession);
verifyNoMoreInteractions(authorizationDao);
notifications.forEach(Mockito::verifyZeroInteractions);
}
use of org.sonar.server.notification.email.EmailNotificationChannel in project sonarqube by SonarSource.
the class ReportAnalysisFailureNotificationHandlerTest method deliver_ignores_notification_without_projectKey.
@Test
public void deliver_ignores_notification_without_projectKey() {
String projectKey = randomAlphabetic(10);
Set<ReportAnalysisFailureNotification> withProjectKey = IntStream.range(0, 1 + new Random().nextInt(5)).mapToObj(i -> newNotification(projectKey)).collect(toSet());
Set<ReportAnalysisFailureNotification> noProjectKey = IntStream.range(0, 1 + new Random().nextInt(5)).mapToObj(i -> newNotification(null)).collect(toSet());
Set<EmailRecipient> emailRecipients = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> "user_" + i).map(login -> new EmailRecipient(login, emailOf(login))).collect(toSet());
Set<EmailDeliveryRequest> expectedRequests = emailRecipients.stream().flatMap(emailRecipient -> withProjectKey.stream().map(notif -> new EmailDeliveryRequest(emailRecipient.getEmail(), notif))).collect(toSet());
when(emailNotificationChannel.isActivated()).thenReturn(true);
when(notificationManager.findSubscribedEmailRecipients(REPORT_FAILURE_DISPATCHER_KEY, projectKey, REQUIRED_SUBSCRIBER_PERMISSIONS)).thenReturn(emailRecipients);
Set<ReportAnalysisFailureNotification> notifications = Stream.of(withProjectKey.stream(), noProjectKey.stream()).flatMap(t -> t).collect(toSet());
int deliver = underTest.deliver(notifications);
assertThat(deliver).isZero();
verify(notificationManager).findSubscribedEmailRecipients(REPORT_FAILURE_DISPATCHER_KEY, projectKey, REQUIRED_SUBSCRIBER_PERMISSIONS);
verifyNoMoreInteractions(notificationManager);
verify(emailNotificationChannel).isActivated();
verify(emailNotificationChannel).deliverAll(expectedRequests);
verifyNoMoreInteractions(emailNotificationChannel);
}
use of org.sonar.server.notification.email.EmailNotificationChannel in project sonarqube by SonarSource.
the class QGChangeNotificationHandlerTest method deliver_ignores_notification_without_projectKey.
@Test
public void deliver_ignores_notification_without_projectKey() {
String projectKey = randomAlphabetic(10);
Set<QGChangeNotification> withProjectKey = IntStream.range(0, 1 + new Random().nextInt(5)).mapToObj(i -> newNotification(projectKey)).collect(toSet());
Set<QGChangeNotification> noProjectKey = IntStream.range(0, 1 + new Random().nextInt(5)).mapToObj(i -> newNotification(null)).collect(toSet());
Set<NotificationManager.EmailRecipient> emailRecipients = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> "user_" + i).map(login -> new NotificationManager.EmailRecipient(login, emailOf(login))).collect(toSet());
Set<EmailNotificationChannel.EmailDeliveryRequest> expectedRequests = emailRecipients.stream().flatMap(emailRecipient -> withProjectKey.stream().map(notif -> new EmailNotificationChannel.EmailDeliveryRequest(emailRecipient.getEmail(), notif))).collect(toSet());
when(emailNotificationChannel.isActivated()).thenReturn(true);
when(notificationManager.findSubscribedEmailRecipients(QG_CHANGE_DISPATCHER_KEY, projectKey, ALL_MUST_HAVE_ROLE_USER)).thenReturn(emailRecipients);
Set<QGChangeNotification> notifications = Stream.of(withProjectKey.stream(), noProjectKey.stream()).flatMap(t -> t).collect(toSet());
int deliver = underTest.deliver(notifications);
assertThat(deliver).isZero();
verify(notificationManager).findSubscribedEmailRecipients(QG_CHANGE_DISPATCHER_KEY, projectKey, ALL_MUST_HAVE_ROLE_USER);
verifyNoMoreInteractions(notificationManager);
verify(emailNotificationChannel).isActivated();
verify(emailNotificationChannel).deliverAll(expectedRequests);
verifyNoMoreInteractions(emailNotificationChannel);
}
Aggregations