aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorFabrice Bellingard <fabrice.bellingard@sonarsource.com>2013-01-29 12:59:58 +0100
committerFabrice Bellingard <fabrice.bellingard@sonarsource.com>2013-01-29 18:01:15 +0100
commit6d28b25606431eef5b911c4900a7ea4fd764b3df (patch)
tree027e196563cd4cd6c2535e8383f60d68b27353d9 /sonar-server
parent8a8a8eb17a2ec05fb4bb8873145721e198cd73a3 (diff)
downloadsonarqube-6d28b25606431eef5b911c4900a7ea4fd764b3df.tar.gz
sonarqube-6d28b25606431eef5b911c4900a7ea4fd764b3df.zip
SONAR-3959 Enhance NotifManager to help finding subscribed users
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/notifications/NotificationService.java12
-rw-r--r--sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceTest.java15
2 files changed, 16 insertions, 11 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/notifications/NotificationService.java b/sonar-server/src/main/java/org/sonar/server/notifications/NotificationService.java
index 867a197e54c..49b4e8237c0 100644
--- a/sonar-server/src/main/java/org/sonar/server/notifications/NotificationService.java
+++ b/sonar-server/src/main/java/org/sonar/server/notifications/NotificationService.java
@@ -65,7 +65,6 @@ public class NotificationService implements ServerComponent {
private final long delayInSeconds;
private final DefaultNotificationManager manager;
private final NotificationDispatcher[] dispatchers;
- private final NotificationChannel[] channels;
private ScheduledExecutorService executorService;
private boolean stopping = false;
@@ -73,19 +72,18 @@ public class NotificationService implements ServerComponent {
/**
* Constructor for {@link NotificationService}
*/
- public NotificationService(Settings settings, DefaultNotificationManager manager, NotificationDispatcher[] dispatchers, NotificationChannel[] channels) {
+ public NotificationService(Settings settings, DefaultNotificationManager manager, NotificationDispatcher[] dispatchers) {
delayInSeconds = settings.getLong(PROPERTY_DELAY);
this.manager = manager;
- this.channels = channels;
this.dispatchers = dispatchers;
}
/**
* Default constructor when no channels.
*/
- public NotificationService(Settings settings, DefaultNotificationManager manager, NotificationDispatcher[] dispatchers) {
- this(settings, manager, dispatchers, new NotificationChannel[0]);
- LOG.warn("There is no channels - all notifications will be ignored!");
+ public NotificationService(Settings settings, DefaultNotificationManager manager) {
+ this(settings, manager, new NotificationDispatcher[0]);
+ LOG.warn("There is no dispatcher - all notifications will be ignored!");
}
public void start() {
@@ -171,7 +169,7 @@ public class NotificationService implements ServerComponent {
}
public List<NotificationChannel> getChannels() {
- return Arrays.asList(channels);
+ return manager.getChannels();
}
}
diff --git a/sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceTest.java b/sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceTest.java
index f866a8e81a8..d2eeb8cce86 100644
--- a/sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.server.notifications;
+import com.google.common.collect.Lists;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@@ -62,6 +63,7 @@ public class NotificationServiceTest {
when(commentOnReviewCreatedByMe.getKey()).thenReturn("comment on review created by me");
when(queueElement.getNotification()).thenReturn(notification);
when(manager.getFromQueue()).thenReturn(queueElement).thenReturn(null);
+ when(manager.getChannels()).thenReturn(Lists.newArrayList(emailChannel, gtalkChannel));
Settings settings = new Settings().setProperty("sonar.notifications.delay", 1L);
@@ -178,15 +180,20 @@ public class NotificationServiceTest {
@Test
public void shouldReturnDispatcherAndChannelListsUsedInWebapp() {
- Settings settings = new Settings().setProperty("sonar.notifications.delay", 1L);
- NotificationService service = new NotificationService(settings, manager,
- new NotificationDispatcher[] {commentOnReviewAssignedToMe, commentOnReviewCreatedByMe},
- new NotificationChannel[] {emailChannel, gtalkChannel});
+ setUpMocks(CREATOR_SIMON, ASSIGNEE_SIMON);
assertThat(service.getChannels()).containsOnly(emailChannel, gtalkChannel);
assertThat(service.getDispatchers()).containsOnly(commentOnReviewAssignedToMe, commentOnReviewCreatedByMe);
}
+ @Test
+ public void shouldReturnNoDispatcher() {
+ Settings settings = new Settings().setProperty("sonar.notifications.delay", 1L);
+
+ service = new NotificationService(settings, manager);
+ assertThat(service.getDispatchers()).hasSize(0);
+ }
+
private static Answer<Object> addUser(final String user, final NotificationChannel channel) {
return addUser(user, new NotificationChannel[] {channel});
}