aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src/test/java
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2011-07-28 03:55:18 +0400
committerEvgeny Mandrikov <mandrikov@gmail.com>2011-07-28 06:06:02 +0400
commit223cc999564d32633fbdc493e11556e8a29e2d8b (patch)
tree2fe08f3837a2c5847f41e7034147aa3c428746d9 /sonar-server/src/test/java
parentc5dfbf80a5befb9464b9b43c3120a8000ca13d55 (diff)
downloadsonarqube-223cc999564d32633fbdc493e11556e8a29e2d8b.tar.gz
sonarqube-223cc999564d32633fbdc493e11556e8a29e2d8b.zip
SONAR-2649 Add server property 'sonar.notifications.delay'
Can be defined in conf/sonar.properties and specifies delay in seconds between processing of notifications queue, default value is 60.
Diffstat (limited to 'sonar-server/src/test/java')
-rw-r--r--sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceDbTest.java5
-rw-r--r--sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceTest.java25
2 files changed, 21 insertions, 9 deletions
diff --git a/sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceDbTest.java b/sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceDbTest.java
index a7a57c9044b..82f1c4fbad7 100644
--- a/sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceDbTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/notifications/NotificationServiceDbTest.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import org.apache.commons.configuration.Configuration;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.notifications.NotificationChannel;
@@ -37,11 +38,11 @@ public class NotificationServiceDbTest extends AbstractDbUnitTestCase {
@Before
public void setUp() {
setupData("fixture");
- notificationService = new NotificationService(getSessionFactory(), null, null);
+ notificationService = new NotificationService(mock(Configuration.class), getSessionFactory(), null, null);
}
@Test
- public void should() {
+ public void shouldCheckEnablement() {
NotificationChannel email = mock(NotificationChannel.class);
when(email.getKey()).thenReturn("EmailNotificationChannel");
NotificationDispatcher commentOnReviewAssignedToMe = mock(NotificationDispatcher.class);
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 d17ada17562..1bc824b1413 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
@@ -20,8 +20,18 @@
package org.sonar.server.notifications;
import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.*;
-
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
+import org.apache.commons.configuration.BaseConfiguration;
+import org.apache.commons.configuration.Configuration;
import org.junit.Before;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
@@ -77,7 +87,9 @@ public class NotificationServiceTest {
NotificationDispatcher[] dispatchers = new NotificationDispatcher[] { commentOnReviewAssignedToMe, commentOnReviewCreatedByMe };
NotificationChannel[] channels = new NotificationChannel[] { emailChannel, gtalkChannel };
manager = mock(DefaultNotificationManager.class);
- service = spy(new NotificationService(null, manager, dispatchers, channels));
+ Configuration configuration = new BaseConfiguration();
+ configuration.setProperty("sonar.notifications.delay", "1"); // delay 1 second
+ service = spy(new NotificationService(configuration, null, manager, dispatchers, channels));
doReturn(false).when(service).isEnabled(any(String.class), any(NotificationChannel.class), any(NotificationDispatcher.class));
}
@@ -86,15 +98,14 @@ public class NotificationServiceTest {
NotificationQueueElement queueElement = mock(NotificationQueueElement.class);
Notification notification = mock(Notification.class);
when(queueElement.getNotification()).thenReturn(notification);
- when(manager.getFromQueue()).thenReturn(queueElement).thenReturn(null);
+ when(manager.getFromQueue()).thenReturn(queueElement).thenReturn(null).thenReturn(queueElement).thenReturn(null).thenReturn(queueElement).thenReturn(null);
doNothing().when(service).deliver(any(Notification.class));
- service.setPeriod(10);
service.start();
- Thread.sleep(50);
+ Thread.sleep(1500); // sleep 1.5 second to process queue
service.stop();
- verify(service).deliver(notification);
+ verify(service, times(3)).deliver(notification); // 3 times - 1 on start, 1 after delay, 1 on stop
}
/**