use of org.sonar.server.notification.email.EmailNotificationChannel in project sonarqube by SonarSource.
the class NewIssuesNotificationHandlerTest method deliver_has_no_effect_if_no_notification_has_projectKey.
@Test
public void deliver_has_no_effect_if_no_notification_has_projectKey() {
when(emailNotificationChannel.isActivated()).thenReturn(true);
Set<NewIssuesNotification> notifications = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> newNotification(null)).collect(toSet());
int deliver = underTest.deliver(notifications);
assertThat(deliver).isZero();
verifyZeroInteractions(notificationManager);
verify(emailNotificationChannel).isActivated();
verifyNoMoreInteractions(emailNotificationChannel);
notifications.forEach(notification -> {
verify(notification).getProjectKey();
verifyNoMoreInteractions(notification);
});
}
use of org.sonar.server.notification.email.EmailNotificationChannel in project sonarqube by SonarSource.
the class MyNewIssuesNotificationHandlerTest method deliver_ignores_notifications_which_assignee_has_no_subscribed_to_MyNewIssue_notifications.
@Test
public void deliver_ignores_notifications_which_assignee_has_no_subscribed_to_MyNewIssue_notifications() {
String projectKey = randomAlphabetic(5);
String assignee1 = randomAlphabetic(6);
String assignee2 = randomAlphabetic(7);
Set<String> assignees = of(assignee1, assignee2);
// assignee1 is not authorized
Set<MyNewIssuesNotification> assignee1Notifications = randomSetOfNotifications(projectKey, assignee1);
// assignee2 is authorized
Set<MyNewIssuesNotification> assignee2Notifications = randomSetOfNotifications(projectKey, assignee2);
when(emailNotificationChannel.isActivated()).thenReturn(true);
when(notificationManager.findSubscribedEmailRecipients(MY_NEW_ISSUES_DISPATCHER_KEY, projectKey, assignees, ALL_MUST_HAVE_ROLE_USER)).thenReturn(of(emailRecipientOf(assignee2)));
Set<EmailDeliveryRequest> expectedRequests = assignee2Notifications.stream().map(t -> new EmailDeliveryRequest(emailOf(t.getAssignee()), t)).collect(toSet());
int deliveredCount = new Random().nextInt(expectedRequests.size());
when(emailNotificationChannel.deliverAll(expectedRequests)).thenReturn(deliveredCount);
int deliver = underTest.deliver(Stream.concat(assignee1Notifications.stream(), assignee2Notifications.stream()).collect(toSet()));
assertThat(deliver).isEqualTo(deliveredCount);
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.email.EmailNotificationChannel in project sonarqube by SonarSource.
the class MyNewIssuesNotificationHandlerTest 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<MyNewIssuesNotification> notifications = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> mock(MyNewIssuesNotification.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 FPOrWontFixNotificationHandlerTest method deliver_has_no_effect_if_no_issue_has_new_resolution.
@Test
public void deliver_has_no_effect_if_no_issue_has_new_resolution() {
when(emailNotificationChannel.isActivated()).thenReturn(true);
Change changeMock = mock(Change.class);
Set<IssuesChangesNotification> notifications = IntStream.range(0, 2 + new Random().nextInt(5)).mapToObj(j -> new IssuesChangesNotificationBuilder(randomIssues(t -> t.setNewResolution(null)).collect(toSet()), changeMock)).map(serializer::serialize).collect(toSet());
reset(serializer);
int deliver = underTest.deliver(notifications);
assertThat(deliver).isZero();
verify(serializer, times(notifications.size())).from(any(IssuesChangesNotification.class));
verifyZeroInteractions(changeMock);
verifyNoMoreInteractions(serializer);
verifyZeroInteractions(notificationManager);
verify(emailNotificationChannel).isActivated();
verifyNoMoreInteractions(emailNotificationChannel);
}
use of org.sonar.server.notification.email.EmailNotificationChannel in project sonarqube by SonarSource.
the class FPOrWontFixNotificationHandlerTest 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<IssuesChangesNotification> notifications = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> mock(IssuesChangesNotification.class)).collect(toSet());
int deliver = underTest.deliver(notifications);
assertThat(deliver).isZero();
verifyZeroInteractions(notificationManager);
verify(emailNotificationChannel).isActivated();
verifyNoMoreInteractions(emailNotificationChannel);
notifications.forEach(Mockito::verifyZeroInteractions);
}
Aggregations