]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4624 complete "new FP issues" with resolution "won't fix" 136/head
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 6 Mar 2015 08:47:38 +0000 (09:47 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 6 Mar 2015 08:48:40 +0000 (09:48 +0100)
-> dispatcher becomes "Issues resolved as false positive or won't fix"

server/sonar-server/src/main/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcher.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewFalsePositiveNotificationDispatcher.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
server/sonar-server/src/test/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcherTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewFalsePositiveNotificationDispatcherTest.java [deleted file]
sonar-core/src/main/resources/org/sonar/l10n/core.properties

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 (file)
index 0000000..16b3de6
--- /dev/null
@@ -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<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);
+        }
+      }
+    }
+  }
+
+}
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 (file)
index be916cf..0000000
+++ /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<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);
-        }
-      }
-    }
-  }
-
-}
index 1c03d4fb89caeff4b637c321f89bd342eb680efa..3144159e1ad130d1c043270749c10d0fa09736ee 100644 (file)
@@ -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 (file)
index 0000000..0bc96d6
--- /dev/null
@@ -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<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);
+  }
+}
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 (file)
index ac434d6..0000000
+++ /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<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);
-  }
-
-}
index f7c7f68f0e3fa8f9af9fd06cbdc96295bc4c9fa3..3736c11e312cc5e2ca9528390d153136ba8ea1e9 100644 (file)
@@ -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
 
 
 #------------------------------------------------------------------------------