From b56b994e0e67043be18cf5803474ed01ffed100f Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Thu, 28 Jul 2011 05:33:33 +0400 Subject: SONAR-2596 Reduce number of arguments for NotificationService constructor --- .../core/notifications/DefaultNotificationManager.java | 16 +++++++++++++--- .../notifications/DefaultNotificationManagerTest.java | 7 +++++++ .../DefaultNotificationManagerTest/fixture.xml | 8 ++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 sonar-core/src/test/resources/org/sonar/core/notifications/DefaultNotificationManagerTest/fixture.xml (limited to 'sonar-core/src') diff --git a/sonar-core/src/main/java/org/sonar/core/notifications/DefaultNotificationManager.java b/sonar-core/src/main/java/org/sonar/core/notifications/DefaultNotificationManager.java index 4f8b604726a..f9e2107743f 100644 --- a/sonar-core/src/main/java/org/sonar/core/notifications/DefaultNotificationManager.java +++ b/sonar-core/src/main/java/org/sonar/core/notifications/DefaultNotificationManager.java @@ -19,15 +19,17 @@ */ package org.sonar.core.notifications; +import java.util.Date; +import java.util.List; + import org.sonar.api.database.DatabaseSession; +import org.sonar.api.database.configuration.Property; +import org.sonar.api.database.model.User; import org.sonar.api.notifications.Notification; import org.sonar.api.notifications.NotificationManager; import org.sonar.jpa.entity.NotificationQueueElement; import org.sonar.jpa.session.DatabaseSessionFactory; -import java.util.Date; -import java.util.List; - /** * @since 2.10 */ @@ -61,4 +63,12 @@ public class DefaultNotificationManager implements NotificationManager { return notification; } + public boolean isEnabled(String username, String channelKey, String dispatcherKey) { + DatabaseSession session = sessionFactory.getSession(); + User user = session.getSingleResult(User.class, "login", username); + String notificationKey = "notification." + dispatcherKey + "." + channelKey; + Property property = session.getSingleResult(Property.class, "userId", user.getId(), "key", notificationKey); + return property != null && "true".equals(property.getValue()); + } + } diff --git a/sonar-core/src/test/java/org/sonar/core/notifications/DefaultNotificationManagerTest.java b/sonar-core/src/test/java/org/sonar/core/notifications/DefaultNotificationManagerTest.java index 70587fa8493..ae661ae43cc 100644 --- a/sonar-core/src/test/java/org/sonar/core/notifications/DefaultNotificationManagerTest.java +++ b/sonar-core/src/test/java/org/sonar/core/notifications/DefaultNotificationManagerTest.java @@ -49,4 +49,11 @@ public class DefaultNotificationManagerTest extends AbstractDbUnitTestCase { assertThat(manager.getFromQueue(), nullValue()); } + @Test + public void shouldCheckEnablement() { + setupData("fixture"); + assertThat(manager.isEnabled("simon", "email", "CommentOnReviewAssignedToMe"), is(true)); + assertThat(manager.isEnabled("godin", "email", "CommentOnReviewAssignedToMe"), is(false)); + } + } diff --git a/sonar-core/src/test/resources/org/sonar/core/notifications/DefaultNotificationManagerTest/fixture.xml b/sonar-core/src/test/resources/org/sonar/core/notifications/DefaultNotificationManagerTest/fixture.xml new file mode 100644 index 00000000000..7933d24446d --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/notifications/DefaultNotificationManagerTest/fixture.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file -- cgit v1.2.3