use of org.sonar.server.notification.NotificationManager.EmailRecipient in project sonarqube by SonarSource.
the class DefaultNotificationManagerTest method findSubscribedEmailRecipients_returns_empty_if_no_email_recipients_in_project_for_dispatcher_key.
@Test
public void findSubscribedEmailRecipients_returns_empty_if_no_email_recipients_in_project_for_dispatcher_key() {
String dispatcherKey = randomAlphabetic(12);
String globalPermission = randomAlphanumeric(4);
String projectPermission = randomAlphanumeric(5);
String projectKey = randomAlphabetic(6);
when(propertiesDao.findEmailSubscribersForNotification(dbSession, dispatcherKey, "EmailNotificationChannel", projectKey)).thenReturn(Collections.emptySet());
Set<EmailRecipient> emailRecipients = underTest.findSubscribedEmailRecipients(dispatcherKey, projectKey, new SubscriberPermissionsOnProject(globalPermission, projectPermission));
assertThat(emailRecipients).isEmpty();
verify(authorizationDao, times(0)).keepAuthorizedLoginsOnProject(any(DbSession.class), anySet(), anyString(), anyString());
}
use of org.sonar.server.notification.NotificationManager.EmailRecipient in project sonarqube by SonarSource.
the class DefaultNotificationManagerTest method findSubscribedEmailRecipients_with_logins_does_not_call_DB_for_project_permission_filtering_if_there_is_no_global_subscriber.
@Test
public void findSubscribedEmailRecipients_with_logins_does_not_call_DB_for_project_permission_filtering_if_there_is_no_global_subscriber() {
String dispatcherKey = randomAlphabetic(12);
String globalPermission = randomAlphanumeric(4);
String projectPermission = randomAlphanumeric(5);
String projectKey = randomAlphabetic(6);
Set<EmailSubscriberDto> subscribers = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> EmailSubscriberDto.create("user" + i, false, "user" + i + "@sonarsource.com")).collect(Collectors.toSet());
Set<String> logins = subscribers.stream().map(EmailSubscriberDto::getLogin).collect(Collectors.toSet());
when(propertiesDao.findEmailSubscribersForNotification(dbSession, dispatcherKey, "EmailNotificationChannel", projectKey, logins)).thenReturn(subscribers);
when(authorizationDao.keepAuthorizedLoginsOnProject(dbSession, logins, projectKey, projectPermission)).thenReturn(logins);
Set<EmailRecipient> emailRecipients = underTest.findSubscribedEmailRecipients(dispatcherKey, projectKey, logins, new SubscriberPermissionsOnProject(globalPermission, projectPermission));
Set<EmailRecipient> expected = subscribers.stream().map(i -> new EmailRecipient(i.getLogin(), i.getEmail())).collect(Collectors.toSet());
assertThat(emailRecipients).isEqualTo(expected);
verify(authorizationDao, times(0)).keepAuthorizedLoginsOnProject(eq(dbSession), anySet(), anyString(), eq(globalPermission));
verify(authorizationDao, times(1)).keepAuthorizedLoginsOnProject(eq(dbSession), anySet(), anyString(), eq(projectPermission));
}
use of org.sonar.server.notification.NotificationManager.EmailRecipient in project sonarqube by SonarSource.
the class EmailRecipientTest method constructor_fails_with_NPE_if_email_is_null.
@Test
public void constructor_fails_with_NPE_if_email_is_null() {
String login = randomAlphabetic(12);
assertThatThrownBy(() -> new EmailRecipient(login, null)).isInstanceOf(NullPointerException.class).hasMessage("email can't be null");
}
use of org.sonar.server.notification.NotificationManager.EmailRecipient in project sonarqube by SonarSource.
the class EmailRecipientTest method equals_is_based_on_login_and_email.
@Test
public void equals_is_based_on_login_and_email() {
String login = randomAlphabetic(11);
String email = randomAlphabetic(12);
EmailRecipient underTest = new EmailRecipient(login, email);
assertThat(underTest).isEqualTo(new EmailRecipient(login, email)).isNotNull().isNotEqualTo(new Object()).isNotEqualTo(new EmailRecipient(email, login)).isNotEqualTo(new EmailRecipient(randomAlphabetic(5), email)).isNotEqualTo(new EmailRecipient(login, randomAlphabetic(5))).isNotEqualTo(new EmailRecipient(randomAlphabetic(5), randomAlphabetic(6)));
}
use of org.sonar.server.notification.NotificationManager.EmailRecipient 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);
}
Aggregations