@Test public void test_metadata() { NotificationDispatcherMetadata metadata = DoNotFixNotificationDispatcher.newMetadata(); assertThat(metadata.getDispatcherKey()).isEqualTo(underTest.getKey()); assertThat(metadata.getProperty(NotificationDispatcherMetadata.GLOBAL_NOTIFICATION)).isEqualTo("true"); assertThat(metadata.getProperty(NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION)).isEqualTo("true"); }
@Override public void dispatch(Notification notification, Context context) { String newResolution = notification.getFieldValue("new.resolution"); if (Objects.equals(newResolution, Issue.RESOLUTION_FALSE_POSITIVE) || Objects.equals(newResolution, Issue.RESOLUTION_WONT_FIX)) { String author = notification.getFieldValue("changeAuthor"); String projectKey = notification.getFieldValue("projectKey"); Multimap<String, NotificationChannel> subscribedRecipients = notifications .findSubscribedRecipientsForDispatcher(this, projectKey, ALL_MUST_HAVE_ROLE_USER); notify(author, context, subscribedRecipients); } }
@Test public void should_not_dispatch_if_other_notification_type() { Notification notification = new Notification("other"); underTest.performDispatch(notification, context); verify(context, never()).addUser(any(String.class), any(NotificationChannel.class)); }
MyNewIssuesNotificationDispatcher.newMetadata(), DoNotFixNotificationDispatcher.class, DoNotFixNotificationDispatcher.newMetadata(), NewIssuesNotificationFactory.class, // used by SendIssueNotificationsStep
MyNewIssuesNotificationDispatcher.newMetadata(), DoNotFixNotificationDispatcher.class, DoNotFixNotificationDispatcher.newMetadata(), NewIssuesNotificationFactory.class,
MyNewIssuesNotificationDispatcher.newMetadata(), DoNotFixNotificationDispatcher.class, DoNotFixNotificationDispatcher.newMetadata(), NewIssuesNotificationFactory.class, // used by SendIssueNotificationsStep
@Override public void dispatch(Notification notification, Context context) { String newResolution = notification.getFieldValue("new.resolution"); if (Objects.equals(newResolution, Issue.RESOLUTION_FALSE_POSITIVE) || Objects.equals(newResolution, Issue.RESOLUTION_WONT_FIX)) { String author = notification.getFieldValue("changeAuthor"); String projectKey = notification.getFieldValue("projectKey"); Multimap<String, NotificationChannel> subscribedRecipients = notifications .findSubscribedRecipientsForDispatcher(this, projectKey, ALL_MUST_HAVE_ROLE_USER); notify(author, context, subscribedRecipients); } }
@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.findSubscribedRecipientsForDispatcher(underTest, "struts", new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER))).thenReturn(recipients); Notification fpNotif = new IssueChangeNotification() .setFieldValue("projectKey", "struts") .setFieldValue("changeAuthor", "godin") .setFieldValue("new.resolution", Issue.RESOLUTION_FALSE_POSITIVE) .setFieldValue("assignee", "freddy"); underTest.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); }
MyNewIssuesNotificationDispatcher.newMetadata(), DoNotFixNotificationDispatcher.class, DoNotFixNotificationDispatcher.newMetadata(), NewIssuesNotificationFactory.class,
/** * Only false positive and won't fix resolutions */ @Test public void ignore_other_resolutions() { Notification fixedNotif = new IssueChangeNotification().setFieldValue("projectKey", "struts") .setFieldValue("changeAuthor", "godin") .setFieldValue("new.resolution", Issue.RESOLUTION_FIXED) .setFieldValue("assignee", "freddy"); underTest.performDispatch(fixedNotif, context); verifyZeroInteractions(context); } }