aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server-common/src/test
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2023-05-15 19:49:00 -0500
committersonartech <sonartech@sonarsource.com>2023-06-01 20:02:59 +0000
commit46effb33d74b5b37f097288d6bac6343a2d06a8c (patch)
treed97ed78ac7d0413214353667dcf2424101f79646 /server/sonar-server-common/src/test
parent9bc77e5b117af186e37aff6e22a0ed6da96d5ae5 (diff)
downloadsonarqube-46effb33d74b5b37f097288d6bac6343a2d06a8c.tar.gz
sonarqube-46effb33d74b5b37f097288d6bac6343a2d06a8c.zip
SONAR-18856 Refactor favorites and properties
Diffstat (limited to 'server/sonar-server-common/src/test')
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/notification/DefaultNotificationManagerTest.java119
1 files changed, 0 insertions, 119 deletions
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/notification/DefaultNotificationManagerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/notification/DefaultNotificationManagerTest.java
index d07f5d1567a..310615af703 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/notification/DefaultNotificationManagerTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/notification/DefaultNotificationManagerTest.java
@@ -143,125 +143,6 @@ public class DefaultNotificationManagerTest {
}
@Test
- public void shouldFindNoRecipient() {
- assertThat(underTest.findSubscribedRecipientsForDispatcher(dispatcher, "uuid_45", new SubscriberPermissionsOnProject(UserRole.USER)).asMap().entrySet())
- .isEmpty();
- }
-
- @Test
- public void shouldFindSubscribedRecipientForGivenResource() {
- String projectKey = randomAlphabetic(6);
- String otherProjectKey = randomAlphabetic(7);
- when(propertiesDao.findUsersForNotification("NewViolations", "Email", projectKey))
- .thenReturn(newHashSet(new Subscriber("user1", false), new Subscriber("user3", false), new Subscriber("user3", true)));
- when(propertiesDao.findUsersForNotification("NewViolations", "Twitter", otherProjectKey))
- .thenReturn(newHashSet(new Subscriber("user2", false)));
- when(propertiesDao.findUsersForNotification("NewViolations", "Twitter", projectKey))
- .thenReturn(newHashSet(new Subscriber("user3", true)));
- when(propertiesDao.findUsersForNotification("NewAlerts", "Twitter", projectKey))
- .thenReturn(newHashSet(new Subscriber("user4", false)));
-
- when(authorizationDao.keepAuthorizedLoginsOnProject(dbSession, newHashSet("user1", "user3"), projectKey, "user"))
- .thenReturn(newHashSet("user1", "user3"));
-
- Multimap<String, NotificationChannel> multiMap = underTest.findSubscribedRecipientsForDispatcher(dispatcher, projectKey,
- ALL_MUST_HAVE_ROLE_USER);
- assertThat(multiMap.entries()).hasSize(3);
-
- Map<String, Collection<NotificationChannel>> map = multiMap.asMap();
- assertThat(map.get("user1")).containsOnly(emailChannel);
- assertThat(map.get("user2")).isNull();
- assertThat(map.get("user3")).containsOnly(emailChannel, twitterChannel);
- assertThat(map.get("user4")).isNull();
-
- // code is optimized to perform only 1 SQL requests for all channels
- verify(authorizationDao, times(1)).keepAuthorizedLoginsOnProject(eq(dbSession), anySet(), anyString(), anyString());
- }
-
- @Test
- public void should_apply_distinct_permission_filtering_global_or_project_subscribers() {
- String globalPermission = randomAlphanumeric(4);
- String projectPermission = randomAlphanumeric(5);
- String projectKey = randomAlphabetic(6);
- String otherProjectKey = randomAlphabetic(7);
- when(propertiesDao.findUsersForNotification("NewViolations", "Email", projectKey))
- .thenReturn(newHashSet(new Subscriber("user1", false), new Subscriber("user3", false), new Subscriber("user3", true)));
- when(propertiesDao.findUsersForNotification("NewViolations", "Twitter", otherProjectKey))
- .thenReturn(newHashSet(new Subscriber("user2", false)));
- when(propertiesDao.findUsersForNotification("NewViolations", "Twitter", projectKey))
- .thenReturn(newHashSet(new Subscriber("user3", true)));
- when(propertiesDao.findUsersForNotification("NewAlerts", "Twitter", projectKey))
- .thenReturn(newHashSet(new Subscriber("user4", false)));
-
- when(authorizationDao.keepAuthorizedLoginsOnProject(dbSession, newHashSet("user3", "user4"), projectKey, globalPermission))
- .thenReturn(newHashSet("user3"));
- when(authorizationDao.keepAuthorizedLoginsOnProject(dbSession, newHashSet("user1", "user3"), projectKey, projectPermission))
- .thenReturn(newHashSet("user1", "user3"));
-
- Multimap<String, NotificationChannel> multiMap = underTest.findSubscribedRecipientsForDispatcher(dispatcher, projectKey,
- new SubscriberPermissionsOnProject(globalPermission, projectPermission));
- assertThat(multiMap.entries()).hasSize(3);
-
- Map<String, Collection<NotificationChannel>> map = multiMap.asMap();
- assertThat(map.get("user1")).containsOnly(emailChannel);
- assertThat(map.get("user2")).isNull();
- assertThat(map.get("user3")).containsOnly(emailChannel, twitterChannel);
- assertThat(map.get("user4")).isNull();
-
- // code is optimized to perform only 2 SQL requests for all channels
- verify(authorizationDao, times(1)).keepAuthorizedLoginsOnProject(eq(dbSession), anySet(), anyString(), eq(globalPermission));
- verify(authorizationDao, times(1)).keepAuthorizedLoginsOnProject(eq(dbSession), anySet(), anyString(), eq(projectPermission));
- }
-
- @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));
- }
-
- @Test
- public void do_not_call_db_for_project_permission_filtering_if_there_is_no_global_subscriber() {
- String globalPermission = randomAlphanumeric(4);
- String projectPermission = randomAlphanumeric(5);
- String projectKey = randomAlphabetic(6);
- when(propertiesDao.findUsersForNotification("NewViolations", "Email", projectKey))
- .thenReturn(newHashSet(new Subscriber("user3", false)));
- when(propertiesDao.findUsersForNotification("NewViolations", "Twitter", projectKey))
- .thenReturn(newHashSet(new Subscriber("user3", false)));
-
- when(authorizationDao.keepAuthorizedLoginsOnProject(dbSession, newHashSet("user3"), projectKey, projectPermission))
- .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(0)).keepAuthorizedLoginsOnProject(eq(dbSession), anySet(), anyString(), eq(globalPermission));
- verify(authorizationDao, times(1)).keepAuthorizedLoginsOnProject(eq(dbSession), anySet(), anyString(), eq(projectPermission));
- }
-
- @Test
public void findSubscribedEmailRecipients_fails_with_NPE_if_projectKey_is_null() {
String dispatcherKey = randomAlphabetic(12);