aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core/src/test
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2015-05-22 10:59:23 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2015-05-22 14:24:53 +0200
commitb15cb8e004d119a44189e4808ff98fe49a9a66e7 (patch)
tree5c3db11031f4e6b25851ad2c1535c531ca5443bf /sonar-core/src/test
parent850d73923682ad77069c8c4251ca3674ff90c86e (diff)
downloadsonarqube-b15cb8e004d119a44189e4808ff98fe49a9a66e7.tar.gz
sonarqube-b15cb8e004d119a44189e4808ff98fe49a9a66e7.zip
SONAR-6567 disable extension point NotificationDispatcher in batch
Currently it's only removed from API. Will be removed from batch after that events are in Compute Engine (for change of quality gate status)
Diffstat (limited to 'sonar-core/src/test')
-rw-r--r--sonar-core/src/test/java/org/sonar/core/notification/DefaultNotificationManagerTest.java1
-rw-r--r--sonar-core/src/test/java/org/sonar/core/notification/NotificationChannelTest.java44
-rw-r--r--sonar-core/src/test/java/org/sonar/core/notification/NotificationDispatcherMetadataTest.java46
-rw-r--r--sonar-core/src/test/java/org/sonar/core/notification/NotificationDispatcherTest.java101
4 files changed, 191 insertions, 1 deletions
diff --git a/sonar-core/src/test/java/org/sonar/core/notification/DefaultNotificationManagerTest.java b/sonar-core/src/test/java/org/sonar/core/notification/DefaultNotificationManagerTest.java
index 9e1dae9de30..c5e60e1afa5 100644
--- a/sonar-core/src/test/java/org/sonar/core/notification/DefaultNotificationManagerTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/notification/DefaultNotificationManagerTest.java
@@ -28,7 +28,6 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.sonar.api.notifications.Notification;
import org.sonar.api.notifications.NotificationChannel;
-import org.sonar.api.notifications.NotificationDispatcher;
import org.sonar.core.notification.db.NotificationQueueDao;
import org.sonar.core.notification.db.NotificationQueueDto;
import org.sonar.core.properties.PropertiesDao;
diff --git a/sonar-core/src/test/java/org/sonar/core/notification/NotificationChannelTest.java b/sonar-core/src/test/java/org/sonar/core/notification/NotificationChannelTest.java
new file mode 100644
index 00000000000..dcd80b4c08d
--- /dev/null
+++ b/sonar-core/src/test/java/org/sonar/core/notification/NotificationChannelTest.java
@@ -0,0 +1,44 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.core.notification;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+import org.sonar.api.notifications.Notification;
+import org.sonar.api.notifications.NotificationChannel;
+
+public class NotificationChannelTest {
+
+ @Test
+ public void defaultMethods() {
+ NotificationChannel channel = new FakeNotificationChannel();
+ assertThat(channel.getKey(), is("FakeNotificationChannel"));
+ assertThat(channel.toString(), is("FakeNotificationChannel"));
+ }
+
+ class FakeNotificationChannel extends NotificationChannel {
+ @Override
+ public void deliver(Notification notification, String username) {
+ }
+ }
+
+}
diff --git a/sonar-core/src/test/java/org/sonar/core/notification/NotificationDispatcherMetadataTest.java b/sonar-core/src/test/java/org/sonar/core/notification/NotificationDispatcherMetadataTest.java
new file mode 100644
index 00000000000..c19e5453be6
--- /dev/null
+++ b/sonar-core/src/test/java/org/sonar/core/notification/NotificationDispatcherMetadataTest.java
@@ -0,0 +1,46 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.core.notification;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class NotificationDispatcherMetadataTest {
+
+ private NotificationDispatcherMetadata metadata;
+
+ @Before
+ public void init() {
+ metadata = NotificationDispatcherMetadata.create("NewViolations").setProperty("global", "true");
+ }
+
+ @Test
+ public void shouldReturnDispatcherKey() {
+ assertThat(metadata.getDispatcherKey()).isEqualTo("NewViolations");
+ }
+
+ @Test
+ public void shouldReturnProperty() {
+ assertThat(metadata.getProperty("global")).isEqualTo("true");
+ assertThat(metadata.getProperty("per-project")).isNull();
+ }
+}
diff --git a/sonar-core/src/test/java/org/sonar/core/notification/NotificationDispatcherTest.java b/sonar-core/src/test/java/org/sonar/core/notification/NotificationDispatcherTest.java
new file mode 100644
index 00000000000..89296125536
--- /dev/null
+++ b/sonar-core/src/test/java/org/sonar/core/notification/NotificationDispatcherTest.java
@@ -0,0 +1,101 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.core.notification;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.sonar.api.notifications.Notification;
+import org.sonar.api.notifications.NotificationChannel;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class NotificationDispatcherTest {
+
+ @Mock
+ private NotificationChannel channel;
+
+ @Mock
+ private Notification notification;
+
+ @Mock
+ private NotificationDispatcher.Context context;
+
+ @Before
+ public void init() {
+ MockitoAnnotations.initMocks(this);
+ when(notification.getType()).thenReturn("event1");
+ }
+
+ @Test
+ public void defaultMethods() {
+ NotificationDispatcher dispatcher = new FakeGenericNotificationDispatcher();
+ assertThat(dispatcher.getKey(), is("FakeGenericNotificationDispatcher"));
+ assertThat(dispatcher.toString(), is("FakeGenericNotificationDispatcher"));
+ }
+
+ @Test
+ public void shouldAlwaysRunDispatchForGenericDispatcher() {
+ NotificationDispatcher dispatcher = new FakeGenericNotificationDispatcher();
+ dispatcher.performDispatch(notification, context);
+
+ verify(context, times(1)).addUser("user1", channel);
+ }
+
+ @Test
+ public void shouldNotAlwaysRunDispatchForSpecificDispatcher() {
+ NotificationDispatcher dispatcher = new FakeSpecificNotificationDispatcher();
+
+ // a "event1" notif is sent
+ dispatcher.performDispatch(notification, context);
+ verify(context, never()).addUser("user1", channel);
+
+ // now, a "specific-event" notif is sent
+ when(notification.getType()).thenReturn("specific-event");
+ dispatcher.performDispatch(notification, context);
+ verify(context, times(1)).addUser("user1", channel);
+ }
+
+ class FakeGenericNotificationDispatcher extends NotificationDispatcher {
+ @Override
+ public void dispatch(Notification notification, Context context) {
+ context.addUser("user1", channel);
+ }
+ }
+
+ class FakeSpecificNotificationDispatcher extends NotificationDispatcher {
+
+ public FakeSpecificNotificationDispatcher() {
+ super("specific-event");
+ }
+
+ @Override
+ public void dispatch(Notification notification, Context context) {
+ context.addUser("user1", channel);
+ }
+ }
+
+}