Search in sources :

Example 11 with SubscriberPermissionsOnProject

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));
}
Also used : NotificationChannel(org.sonar.api.notifications.NotificationChannel) Subscriber(org.sonar.db.property.Subscriber) SubscriberPermissionsOnProject(org.sonar.server.notification.NotificationManager.SubscriberPermissionsOnProject) Collection(java.util.Collection) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)11 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)11 SubscriberPermissionsOnProject (org.sonar.server.notification.NotificationManager.SubscriberPermissionsOnProject)11 Collection (java.util.Collection)8 NotificationChannel (org.sonar.api.notifications.NotificationChannel)8 Subscriber (org.sonar.db.property.Subscriber)8 EmailRecipient (org.sonar.server.notification.NotificationManager.EmailRecipient)8 ImmutableSet (com.google.common.collect.ImmutableSet)5 Multimap (com.google.common.collect.Multimap)5 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)5 InvalidClassException (java.io.InvalidClassException)5 Arrays (java.util.Arrays)5 Collections (java.util.Collections)5 List (java.util.List)5 Map (java.util.Map)5 Random (java.util.Random)5 Set (java.util.Set)5 Collectors (java.util.stream.Collectors)5 IntStream (java.util.stream.IntStream)5 RandomStringUtils.randomAlphabetic (org.apache.commons.lang.RandomStringUtils.randomAlphabetic)5