Skip to content

Commit

Permalink
SONAR-4624 complete "new FP issues" with resolution "won't fix"
Browse files Browse the repository at this point in the history
-> dispatcher becomes "Issues resolved as false positive or won't fix"
  • Loading branch information
Simon Brandhof committed Mar 6, 2015
1 parent e26b33b commit 35ecb68
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 44 deletions.
Expand Up @@ -29,17 +29,15 @@
import java.util.Map; import java.util.Map;


/** /**
* This dispatcher means: "notify me when someone resolves an issue as false positive". * This dispatcher means: "notify me when an issue is resolved as false positive or won't fix".
*
* @since 3.6
*/ */
public class NewFalsePositiveNotificationDispatcher extends NotificationDispatcher { public class DoNotFixNotificationDispatcher extends NotificationDispatcher {


public static final String KEY = "NewFalsePositiveIssue"; public static final String KEY = "NewFalsePositiveIssue";


private final NotificationManager notifications; private final NotificationManager notifications;


public NewFalsePositiveNotificationDispatcher(NotificationManager notifications) { public DoNotFixNotificationDispatcher(NotificationManager notifications) {
super(IssueChangeNotification.TYPE); super(IssueChangeNotification.TYPE);
this.notifications = notifications; this.notifications = notifications;
} }
Expand All @@ -58,7 +56,7 @@ public static NotificationDispatcherMetadata newMetadata() {
@Override @Override
public void dispatch(Notification notification, Context context) { public void dispatch(Notification notification, Context context) {
String newResolution = notification.getFieldValue("new.resolution"); String newResolution = notification.getFieldValue("new.resolution");
if (Objects.equal(newResolution, Issue.RESOLUTION_FALSE_POSITIVE)) { if (Objects.equal(newResolution, Issue.RESOLUTION_FALSE_POSITIVE) || Objects.equal(newResolution, Issue.RESOLUTION_WONT_FIX)) {
String author = notification.getFieldValue("changeAuthor"); String author = notification.getFieldValue("changeAuthor");
String projectKey = notification.getFieldValue("projectKey"); String projectKey = notification.getFieldValue("projectKey");
Multimap<String, NotificationChannel> subscribedRecipients = notifications.findNotificationSubscribers(this, projectKey); Multimap<String, NotificationChannel> subscribedRecipients = notifications.findNotificationSubscribers(this, projectKey);
Expand Down
Expand Up @@ -165,7 +165,7 @@
import org.sonar.server.issue.index.IssueIndexer; import org.sonar.server.issue.index.IssueIndexer;
import org.sonar.server.issue.notification.ChangesOnMyIssueNotificationDispatcher; import org.sonar.server.issue.notification.ChangesOnMyIssueNotificationDispatcher;
import org.sonar.server.issue.notification.IssueChangesEmailTemplate; 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.NewIssuesEmailTemplate;
import org.sonar.server.issue.notification.NewIssuesNotificationDispatcher; import org.sonar.server.issue.notification.NewIssuesNotificationDispatcher;
import org.sonar.server.issue.ws.ComponentTagsAction; import org.sonar.server.issue.ws.ComponentTagsAction;
Expand Down Expand Up @@ -690,8 +690,8 @@ void startLevel4Components(ComponentContainer pico) {
pico.addSingleton(ChangesOnMyIssueNotificationDispatcher.newMetadata()); pico.addSingleton(ChangesOnMyIssueNotificationDispatcher.newMetadata());
pico.addSingleton(NewIssuesNotificationDispatcher.class); pico.addSingleton(NewIssuesNotificationDispatcher.class);
pico.addSingleton(NewIssuesNotificationDispatcher.newMetadata()); pico.addSingleton(NewIssuesNotificationDispatcher.newMetadata());
pico.addSingleton(NewFalsePositiveNotificationDispatcher.class); pico.addSingleton(DoNotFixNotificationDispatcher.class);
pico.addSingleton(NewFalsePositiveNotificationDispatcher.newMetadata()); pico.addSingleton(DoNotFixNotificationDispatcher.newMetadata());


// issue filters // issue filters
pico.addSingleton(IssueFilterService.class); pico.addSingleton(IssueFilterService.class);
Expand Down
Expand Up @@ -21,52 +21,37 @@


import com.google.common.collect.HashMultimap; import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.sonar.api.issue.Issue;
import org.mockito.Mock; import org.sonar.api.notifications.Notification;
import org.mockito.runners.MockitoJUnitRunner; import org.sonar.api.notifications.NotificationChannel;
import org.sonar.api.notifications.*; 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.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;


@RunWith(MockitoJUnitRunner.class) public class DoNotFixNotificationDispatcherTest {
public class NewFalsePositiveNotificationDispatcherTest { NotificationManager notifications = mock(NotificationManager.class);
@Mock NotificationDispatcher.Context context = mock(NotificationDispatcher.Context.class);
NotificationManager notifications; NotificationChannel emailChannel = mock(NotificationChannel.class);

NotificationChannel twitterChannel = mock(NotificationChannel.class);
@Mock DoNotFixNotificationDispatcher sut = new DoNotFixNotificationDispatcher(notifications);;
NotificationDispatcher.Context context;

@Mock
NotificationChannel emailChannel;

@Mock
NotificationChannel twitterChannel;

NewFalsePositiveNotificationDispatcher dispatcher;

@Before
public void setUp() {
dispatcher = new NewFalsePositiveNotificationDispatcher(notifications);
}


@Test @Test
public void test_metadata() throws Exception { public void test_metadata() throws Exception {
NotificationDispatcherMetadata metadata = NewFalsePositiveNotificationDispatcher.newMetadata(); NotificationDispatcherMetadata metadata = DoNotFixNotificationDispatcher.newMetadata();
assertThat(metadata.getDispatcherKey()).isEqualTo(dispatcher.getKey()); assertThat(metadata.getDispatcherKey()).isEqualTo(sut.getKey());
assertThat(metadata.getProperty(NotificationDispatcherMetadata.GLOBAL_NOTIFICATION)).isEqualTo("true"); assertThat(metadata.getProperty(NotificationDispatcherMetadata.GLOBAL_NOTIFICATION)).isEqualTo("true");
assertThat(metadata.getProperty(NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION)).isEqualTo("true"); assertThat(metadata.getProperty(NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION)).isEqualTo("true");
} }


@Test @Test
public void should_not_dispatch_if_other_notification_type() throws Exception { public void should_not_dispatch_if_other_notification_type() throws Exception {
Notification notification = new Notification("other"); Notification notification = new Notification("other");
dispatcher.performDispatch(notification, context); sut.performDispatch(notification, context);


verify(context, never()).addUser(any(String.class), any(NotificationChannel.class)); verify(context, never()).addUser(any(String.class), any(NotificationChannel.class));
} }
Expand All @@ -77,13 +62,13 @@ public void should_dispatch_to_subscribers() {
recipients.put("simon", emailChannel); recipients.put("simon", emailChannel);
recipients.put("freddy", twitterChannel); recipients.put("freddy", twitterChannel);
recipients.put("godin", twitterChannel); recipients.put("godin", twitterChannel);
when(notifications.findNotificationSubscribers(dispatcher, "struts")).thenReturn(recipients); when(notifications.findNotificationSubscribers(sut, "struts")).thenReturn(recipients);


Notification notification = new IssueChangeNotification().setFieldValue("projectKey", "struts") Notification fpNotif = new IssueChangeNotification().setFieldValue("projectKey", "struts")
.setFieldValue("changeAuthor", "godin") .setFieldValue("changeAuthor", "godin")
.setFieldValue("new.resolution", "FALSE-POSITIVE") .setFieldValue("new.resolution", Issue.RESOLUTION_FALSE_POSITIVE)
.setFieldValue("assignee", "freddy"); .setFieldValue("assignee", "freddy");
dispatcher.performDispatch(notification, context); sut.performDispatch(fpNotif, context);


verify(context).addUser("simon", emailChannel); verify(context).addUser("simon", emailChannel);
verify(context).addUser("freddy", twitterChannel); verify(context).addUser("freddy", twitterChannel);
Expand All @@ -92,4 +77,22 @@ public void should_dispatch_to_subscribers() {
verifyNoMoreInteractions(context); 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);
}
} }
Expand Up @@ -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.ChangesOnMyIssue=Changes in issues assigned to me or reported by me
notification.dispatcher.NewIssues=New issues notification.dispatcher.NewIssues=New issues
notification.dispatcher.NewAlerts=New quality gate status 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




#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
Expand Down

0 comments on commit 35ecb68

Please sign in to comment.