Search in sources :

Example 21 with NotificationChannel

use of org.sonar.api.notifications.NotificationChannel 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

NotificationChannel (org.sonar.api.notifications.NotificationChannel)21 Test (org.junit.Test)12 Notification (org.sonar.api.notifications.Notification)8 Collection (java.util.Collection)6 Subscriber (org.sonar.db.property.Subscriber)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Before (org.junit.Before)3 NotificationDispatcherMetadata (org.sonar.server.notification.NotificationDispatcherMetadata)3 SubscriberPermissionsOnProject (org.sonar.server.notification.NotificationManager.SubscriberPermissionsOnProject)3 Map (java.util.Map)2 ComponentFinder (org.sonar.server.component.ComponentFinder)2 NotificationCenter (org.sonar.server.notification.NotificationCenter)2 NotificationUpdater (org.sonar.server.notification.NotificationUpdater)2 WsActionTester (org.sonar.server.ws.WsActionTester)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)1 Multimap (com.google.common.collect.Multimap)1 IOException (java.io.IOException)1 InvalidClassException (java.io.InvalidClassException)1