--- /dev/null
+/*
+ * 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.server.issue.notification;
+
+import com.google.common.base.Objects;
+import com.google.common.collect.Multimap;
+import org.sonar.api.issue.Issue;
+import org.sonar.api.notifications.*;
+
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * This dispatcher means: "notify me when an issue is resolved as false positive or won't fix".
+ */
+public class DoNotFixNotificationDispatcher extends NotificationDispatcher {
+
+ public static final String KEY = "NewFalsePositiveIssue";
+
+ private final NotificationManager notifications;
+
+ public DoNotFixNotificationDispatcher(NotificationManager notifications) {
+ super(IssueChangeNotification.TYPE);
+ this.notifications = notifications;
+ }
+
+ @Override
+ public String getKey() {
+ return KEY;
+ }
+
+ public static NotificationDispatcherMetadata newMetadata() {
+ return NotificationDispatcherMetadata.create(KEY)
+ .setProperty(NotificationDispatcherMetadata.GLOBAL_NOTIFICATION, String.valueOf(true))
+ .setProperty(NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION, String.valueOf(true));
+ }
+
+ @Override
+ public void dispatch(Notification notification, Context context) {
+ String newResolution = notification.getFieldValue("new.resolution");
+ if (Objects.equal(newResolution, Issue.RESOLUTION_FALSE_POSITIVE) || Objects.equal(newResolution, Issue.RESOLUTION_WONT_FIX)) {
+ String author = notification.getFieldValue("changeAuthor");
+ String projectKey = notification.getFieldValue("projectKey");
+ Multimap<String, NotificationChannel> subscribedRecipients = notifications.findNotificationSubscribers(this, projectKey);
+ notify(author, context, subscribedRecipients);
+ }
+ }
+
+ private void notify(String author, Context context, Multimap<String, NotificationChannel> subscribedRecipients) {
+ for (Map.Entry<String, Collection<NotificationChannel>> channelsByRecipients : subscribedRecipients.asMap().entrySet()) {
+ String login = channelsByRecipients.getKey();
+ // Do not notify the person that resolved the issue
+ if (!Objects.equal(author, login)) {
+ for (NotificationChannel channel : channelsByRecipients.getValue()) {
+ context.addUser(login, channel);
+ }
+ }
+ }
+ }
+
+}
+++ /dev/null
-/*
- * 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.server.issue.notification;
-
-import com.google.common.base.Objects;
-import com.google.common.collect.Multimap;
-import org.sonar.api.issue.Issue;
-import org.sonar.api.notifications.*;
-
-import java.util.Collection;
-import java.util.Map;
-
-/**
- * This dispatcher means: "notify me when someone resolves an issue as false positive".
- *
- * @since 3.6
- */
-public class NewFalsePositiveNotificationDispatcher extends NotificationDispatcher {
-
- public static final String KEY = "NewFalsePositiveIssue";
-
- private final NotificationManager notifications;
-
- public NewFalsePositiveNotificationDispatcher(NotificationManager notifications) {
- super(IssueChangeNotification.TYPE);
- this.notifications = notifications;
- }
-
- @Override
- public String getKey() {
- return KEY;
- }
-
- public static NotificationDispatcherMetadata newMetadata() {
- return NotificationDispatcherMetadata.create(KEY)
- .setProperty(NotificationDispatcherMetadata.GLOBAL_NOTIFICATION, String.valueOf(true))
- .setProperty(NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION, String.valueOf(true));
- }
-
- @Override
- public void dispatch(Notification notification, Context context) {
- String newResolution = notification.getFieldValue("new.resolution");
- if (Objects.equal(newResolution, Issue.RESOLUTION_FALSE_POSITIVE)) {
- String author = notification.getFieldValue("changeAuthor");
- String projectKey = notification.getFieldValue("projectKey");
- Multimap<String, NotificationChannel> subscribedRecipients = notifications.findNotificationSubscribers(this, projectKey);
- notify(author, context, subscribedRecipients);
- }
- }
-
- private void notify(String author, Context context, Multimap<String, NotificationChannel> subscribedRecipients) {
- for (Map.Entry<String, Collection<NotificationChannel>> channelsByRecipients : subscribedRecipients.asMap().entrySet()) {
- String login = channelsByRecipients.getKey();
- // Do not notify the person that resolved the issue
- if (!Objects.equal(author, login)) {
- for (NotificationChannel channel : channelsByRecipients.getValue()) {
- context.addUser(login, channel);
- }
- }
- }
- }
-
-}
import org.sonar.server.issue.index.IssueIndexer;
import org.sonar.server.issue.notification.ChangesOnMyIssueNotificationDispatcher;
import org.sonar.server.issue.notification.IssueChangesEmailTemplate;
-import org.sonar.server.issue.notification.NewFalsePositiveNotificationDispatcher;
+import org.sonar.server.issue.notification.DoNotFixNotificationDispatcher;
import org.sonar.server.issue.notification.NewIssuesEmailTemplate;
import org.sonar.server.issue.notification.NewIssuesNotificationDispatcher;
import org.sonar.server.issue.ws.ComponentTagsAction;
pico.addSingleton(ChangesOnMyIssueNotificationDispatcher.newMetadata());
pico.addSingleton(NewIssuesNotificationDispatcher.class);
pico.addSingleton(NewIssuesNotificationDispatcher.newMetadata());
- pico.addSingleton(NewFalsePositiveNotificationDispatcher.class);
- pico.addSingleton(NewFalsePositiveNotificationDispatcher.newMetadata());
+ pico.addSingleton(DoNotFixNotificationDispatcher.class);
+ pico.addSingleton(DoNotFixNotificationDispatcher.newMetadata());
// issue filters
pico.addSingleton(IssueFilterService.class);
--- /dev/null
+/*
+ * 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.server.issue.notification;
+
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Multimap;
+import org.junit.Test;
+import org.sonar.api.issue.Issue;
+import org.sonar.api.notifications.Notification;
+import org.sonar.api.notifications.NotificationChannel;
+import org.sonar.api.notifications.NotificationDispatcher;
+import org.sonar.api.notifications.NotificationDispatcherMetadata;
+import org.sonar.api.notifications.NotificationManager;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.*;
+
+public class DoNotFixNotificationDispatcherTest {
+ NotificationManager notifications = mock(NotificationManager.class);
+ NotificationDispatcher.Context context = mock(NotificationDispatcher.Context.class);
+ NotificationChannel emailChannel = mock(NotificationChannel.class);
+ NotificationChannel twitterChannel = mock(NotificationChannel.class);
+ DoNotFixNotificationDispatcher sut = new DoNotFixNotificationDispatcher(notifications);;
+
+ @Test
+ public void test_metadata() throws Exception {
+ NotificationDispatcherMetadata metadata = DoNotFixNotificationDispatcher.newMetadata();
+ assertThat(metadata.getDispatcherKey()).isEqualTo(sut.getKey());
+ assertThat(metadata.getProperty(NotificationDispatcherMetadata.GLOBAL_NOTIFICATION)).isEqualTo("true");
+ assertThat(metadata.getProperty(NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION)).isEqualTo("true");
+ }
+
+ @Test
+ public void should_not_dispatch_if_other_notification_type() throws Exception {
+ Notification notification = new Notification("other");
+ sut.performDispatch(notification, context);
+
+ verify(context, never()).addUser(any(String.class), any(NotificationChannel.class));
+ }
+
+ @Test
+ public void should_dispatch_to_subscribers() {
+ Multimap<String, NotificationChannel> recipients = HashMultimap.create();
+ recipients.put("simon", emailChannel);
+ recipients.put("freddy", twitterChannel);
+ recipients.put("godin", twitterChannel);
+ when(notifications.findNotificationSubscribers(sut, "struts")).thenReturn(recipients);
+
+ Notification fpNotif = new IssueChangeNotification().setFieldValue("projectKey", "struts")
+ .setFieldValue("changeAuthor", "godin")
+ .setFieldValue("new.resolution", Issue.RESOLUTION_FALSE_POSITIVE)
+ .setFieldValue("assignee", "freddy");
+ sut.performDispatch(fpNotif, context);
+
+ verify(context).addUser("simon", emailChannel);
+ verify(context).addUser("freddy", twitterChannel);
+ // do not notify the person who flagged the issue as false-positive
+ verify(context, never()).addUser("godin", twitterChannel);
+ verifyNoMoreInteractions(context);
+ }
+
+ /**
+ * Only false positive and won't fix resolutions
+ */
+ @Test
+ public void ignore_other_resolutions() {
+ Multimap<String, NotificationChannel> recipients = HashMultimap.create();
+ recipients.put("simon", emailChannel);
+ recipients.put("freddy", twitterChannel);
+ when(notifications.findNotificationSubscribers(sut, "struts")).thenReturn(recipients);
+
+ Notification fixedNotif = new IssueChangeNotification().setFieldValue("projectKey", "struts")
+ .setFieldValue("changeAuthor", "godin")
+ .setFieldValue("new.resolution", Issue.RESOLUTION_FIXED)
+ .setFieldValue("assignee", "freddy");
+ sut.performDispatch(fixedNotif, context);
+
+ verifyZeroInteractions(context);
+ }
+}
+++ /dev/null
-/*
- * 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.server.issue.notification;
-
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.Multimap;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.api.notifications.*;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.*;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class NewFalsePositiveNotificationDispatcherTest {
- @Mock
- NotificationManager notifications;
-
- @Mock
- NotificationDispatcher.Context context;
-
- @Mock
- NotificationChannel emailChannel;
-
- @Mock
- NotificationChannel twitterChannel;
-
- NewFalsePositiveNotificationDispatcher dispatcher;
-
- @Before
- public void setUp() {
- dispatcher = new NewFalsePositiveNotificationDispatcher(notifications);
- }
-
- @Test
- public void test_metadata() throws Exception {
- NotificationDispatcherMetadata metadata = NewFalsePositiveNotificationDispatcher.newMetadata();
- assertThat(metadata.getDispatcherKey()).isEqualTo(dispatcher.getKey());
- assertThat(metadata.getProperty(NotificationDispatcherMetadata.GLOBAL_NOTIFICATION)).isEqualTo("true");
- assertThat(metadata.getProperty(NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION)).isEqualTo("true");
- }
-
- @Test
- public void should_not_dispatch_if_other_notification_type() throws Exception {
- Notification notification = new Notification("other");
- dispatcher.performDispatch(notification, context);
-
- verify(context, never()).addUser(any(String.class), any(NotificationChannel.class));
- }
-
- @Test
- public void should_dispatch_to_subscribers() {
- Multimap<String, NotificationChannel> recipients = HashMultimap.create();
- recipients.put("simon", emailChannel);
- recipients.put("freddy", twitterChannel);
- recipients.put("godin", twitterChannel);
- when(notifications.findNotificationSubscribers(dispatcher, "struts")).thenReturn(recipients);
-
- Notification notification = new IssueChangeNotification().setFieldValue("projectKey", "struts")
- .setFieldValue("changeAuthor", "godin")
- .setFieldValue("new.resolution", "FALSE-POSITIVE")
- .setFieldValue("assignee", "freddy");
- dispatcher.performDispatch(notification, context);
-
- verify(context).addUser("simon", emailChannel);
- verify(context).addUser("freddy", twitterChannel);
- // do not notify the person who flagged the issue as false-positive
- verify(context, never()).addUser("godin", twitterChannel);
- verifyNoMoreInteractions(context);
- }
-
-}
notification.dispatcher.ChangesOnMyIssue=Changes in issues assigned to me or reported by me
notification.dispatcher.NewIssues=New issues
notification.dispatcher.NewAlerts=New quality gate status
-notification.dispatcher.NewFalsePositiveIssue=New false positives
+notification.dispatcher.NewFalsePositiveIssue=Issues resolved as false positive or won't fix
#------------------------------------------------------------------------------