use of org.sonar.server.notification.NotificationManager.EmailRecipient in project sonarqube by SonarSource.
the class MyNewIssuesNotificationHandlerTest method deliver_ignores_notification_without_assignee.
@Test
public void deliver_ignores_notification_without_assignee() {
String projectKey = randomAlphabetic(10);
Set<MyNewIssuesNotification> withAssignee = IntStream.range(0, 1 + new Random().nextInt(5)).mapToObj(i -> newNotification(projectKey, randomAlphabetic(11 + i))).collect(toSet());
Set<MyNewIssuesNotification> noAssignee = randomSetOfNotifications(projectKey, null);
Set<MyNewIssuesNotification> noProjectKeyNoAssignee = randomSetOfNotifications(null, null);
Set<EmailRecipient> authorizedRecipients = withAssignee.stream().map(n -> new EmailRecipient(n.getAssignee(), n.getAssignee() + "@foo")).collect(toSet());
Set<EmailDeliveryRequest> expectedRequests = withAssignee.stream().map(n -> new EmailDeliveryRequest(n.getAssignee() + "@foo", n)).collect(toSet());
when(emailNotificationChannel.isActivated()).thenReturn(true);
Set<String> assignees = withAssignee.stream().map(MyNewIssuesNotification::getAssignee).collect(toSet());
when(notificationManager.findSubscribedEmailRecipients(MY_NEW_ISSUES_DISPATCHER_KEY, projectKey, assignees, ALL_MUST_HAVE_ROLE_USER)).thenReturn(authorizedRecipients);
Set<MyNewIssuesNotification> notifications = Stream.of(withAssignee.stream(), noAssignee.stream(), noProjectKeyNoAssignee.stream()).flatMap(t -> t).collect(toSet());
int deliver = underTest.deliver(notifications);
assertThat(deliver).isZero();
verify(notificationManager).findSubscribedEmailRecipients(MY_NEW_ISSUES_DISPATCHER_KEY, projectKey, assignees, ALL_MUST_HAVE_ROLE_USER);
verifyNoMoreInteractions(notificationManager);
verify(emailNotificationChannel).isActivated();
verify(emailNotificationChannel).deliverAll(expectedRequests);
verifyNoMoreInteractions(emailNotificationChannel);
}
use of org.sonar.server.notification.NotificationManager.EmailRecipient in project sonarqube by SonarSource.
the class MyNewIssuesNotificationHandlerTest method deliver_ignores_notification_without_projectKey.
@Test
public void deliver_ignores_notification_without_projectKey() {
String projectKey = randomAlphabetic(10);
Set<MyNewIssuesNotification> withProjectKey = IntStream.range(0, 1 + new Random().nextInt(5)).mapToObj(i -> newNotification(projectKey, randomAlphabetic(11 + i))).collect(toSet());
Set<MyNewIssuesNotification> noProjectKey = IntStream.range(0, 1 + new Random().nextInt(5)).mapToObj(i -> newNotification(null, randomAlphabetic(11 + i))).collect(toSet());
Set<MyNewIssuesNotification> noProjectKeyNoAssignee = randomSetOfNotifications(null, null);
Set<EmailRecipient> authorizedRecipients = withProjectKey.stream().map(n -> new EmailRecipient(n.getAssignee(), n.getAssignee() + "@foo")).collect(toSet());
Set<EmailDeliveryRequest> expectedRequests = withProjectKey.stream().map(n -> new EmailDeliveryRequest(n.getAssignee() + "@foo", n)).collect(toSet());
when(emailNotificationChannel.isActivated()).thenReturn(true);
Set<String> assignees = withProjectKey.stream().map(MyNewIssuesNotification::getAssignee).collect(toSet());
when(notificationManager.findSubscribedEmailRecipients(MY_NEW_ISSUES_DISPATCHER_KEY, projectKey, assignees, ALL_MUST_HAVE_ROLE_USER)).thenReturn(authorizedRecipients);
Set<MyNewIssuesNotification> notifications = Stream.of(withProjectKey.stream(), noProjectKey.stream(), noProjectKeyNoAssignee.stream()).flatMap(t -> t).collect(toSet());
int deliver = underTest.deliver(notifications);
assertThat(deliver).isZero();
verify(notificationManager).findSubscribedEmailRecipients(MY_NEW_ISSUES_DISPATCHER_KEY, projectKey, assignees, ALL_MUST_HAVE_ROLE_USER);
verifyNoMoreInteractions(notificationManager);
verify(emailNotificationChannel).isActivated();
verify(emailNotificationChannel).deliverAll(expectedRequests);
verifyNoMoreInteractions(emailNotificationChannel);
}
use of org.sonar.server.notification.NotificationManager.EmailRecipient 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.NotificationManager.EmailRecipient in project sonarqube by SonarSource.
the class DefaultNotificationManagerTest method findSubscribedEmailRecipients_with_logins_returns_empty_if_login_set_is_empty.
@Test
public void findSubscribedEmailRecipients_with_logins_returns_empty_if_login_set_is_empty() {
String dispatcherKey = randomAlphabetic(12);
String projectKey = randomAlphabetic(6);
Set<EmailRecipient> recipients = underTest.findSubscribedEmailRecipients(dispatcherKey, projectKey, ImmutableSet.of(), ALL_MUST_HAVE_ROLE_USER);
assertThat(recipients).isEmpty();
}
use of org.sonar.server.notification.NotificationManager.EmailRecipient in project sonarqube by SonarSource.
the class DefaultNotificationManagerTest method findSubscribedEmailRecipients_does_not_call_DB_for_project_permission_filtering_if_there_is_no_global_subscriber.
@Test
public void findSubscribedEmailRecipients_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)).thenReturn(subscribers);
when(authorizationDao.keepAuthorizedLoginsOnProject(dbSession, logins, projectKey, projectPermission)).thenReturn(logins);
Set<EmailRecipient> emailRecipients = underTest.findSubscribedEmailRecipients(dispatcherKey, projectKey, 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));
}
Aggregations