use of org.sonar.server.notification.NotificationManager.SubscriberPermissionsOnProject in project sonarqube by SonarSource.
the class DefaultNotificationManagerTest method do_not_call_db_for_project_permission_filtering_if_there_is_no_project_subscriber.
@Test
public void do_not_call_db_for_project_permission_filtering_if_there_is_no_project_subscriber() {
String globalPermission = randomAlphanumeric(4);
String projectPermission = randomAlphanumeric(5);
String projectKey = randomAlphabetic(6);
when(propertiesDao.findUsersForNotification("NewViolations", "Email", projectKey)).thenReturn(newHashSet(new Subscriber("user3", true)));
when(propertiesDao.findUsersForNotification("NewViolations", "Twitter", projectKey)).thenReturn(newHashSet(new Subscriber("user3", true)));
when(authorizationDao.keepAuthorizedLoginsOnProject(dbSession, newHashSet("user3"), projectKey, globalPermission)).thenReturn(newHashSet("user3"));
Multimap<String, NotificationChannel> multiMap = underTest.findSubscribedRecipientsForDispatcher(dispatcher, projectKey, new SubscriberPermissionsOnProject(globalPermission, projectPermission));
assertThat(multiMap.entries()).hasSize(2);
Map<String, Collection<NotificationChannel>> map = multiMap.asMap();
assertThat(map.get("user3")).containsOnly(emailChannel, twitterChannel);
verify(authorizationDao, times(1)).keepAuthorizedLoginsOnProject(eq(dbSession), anySet(), anyString(), eq(globalPermission));
verify(authorizationDao, times(0)).keepAuthorizedLoginsOnProject(eq(dbSession), anySet(), anyString(), eq(projectPermission));
}
Aggregations