From: Simon Brandhof Date: Fri, 6 Mar 2015 08:47:38 +0000 (+0100) Subject: SONAR-4624 complete "new FP issues" with resolution "won't fix" X-Git-Tag: 5.1-RC2~32 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F136%2Fhead;p=sonarqube.git SONAR-4624 complete "new FP issues" with resolution "won't fix" -> dispatcher becomes "Issues resolved as false positive or won't fix" --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcher.java b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcher.java new file mode 100644 index 00000000000..16b3de6fc05 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcher.java @@ -0,0 +1,79 @@ +/* + * 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 subscribedRecipients = notifications.findNotificationSubscribers(this, projectKey); + notify(author, context, subscribedRecipients); + } + } + + private void notify(String author, Context context, Multimap subscribedRecipients) { + for (Map.Entry> 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); + } + } + } + } + +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewFalsePositiveNotificationDispatcher.java b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewFalsePositiveNotificationDispatcher.java deleted file mode 100644 index be916cfdd42..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewFalsePositiveNotificationDispatcher.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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 subscribedRecipients = notifications.findNotificationSubscribers(this, projectKey); - notify(author, context, subscribedRecipients); - } - } - - private void notify(String author, Context context, Multimap subscribedRecipients) { - for (Map.Entry> 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); - } - } - } - } - -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java index 1c03d4fb89c..3144159e1ad 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java @@ -165,7 +165,7 @@ import org.sonar.server.issue.index.IssueIndexDefinition; 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; @@ -690,8 +690,8 @@ class ServerComponents { 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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcherTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcherTest.java new file mode 100644 index 00000000000..0bc96d60002 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcherTest.java @@ -0,0 +1,98 @@ +/* + * 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 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 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); + } +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewFalsePositiveNotificationDispatcherTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewFalsePositiveNotificationDispatcherTest.java deleted file mode 100644 index ac434d62372..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewFalsePositiveNotificationDispatcherTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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 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); - } - -} diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index f7c7f68f0e3..3736c11e312 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -2030,7 +2030,7 @@ notification.dispatcher.information=Subscribe to following channels to be notifi 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 #------------------------------------------------------------------------------