@Test public void test_metadata() { NotificationDispatcherMetadata metadata = ChangesOnMyIssueNotificationDispatcher.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 projectKey = notification.getFieldValue("projectKey"); Multimap<String, NotificationChannel> subscribedRecipients = notificationManager .findSubscribedRecipientsForDispatcher(this, projectKey, ALL_MUST_HAVE_ROLE_USER); // See available fields in the class IssueNotifications. // All the following users can be null String changeAuthor = notification.getFieldValue("changeAuthor"); String assignee = notification.getFieldValue("assignee"); if (!Objects.equals(changeAuthor, assignee)) { addUserToContextIfSubscribed(context, assignee, subscribedRecipients); } }
@Test public void should_not_dispatch_if_other_notification_type() { Notification notification = new Notification("other-notif"); underTest.performDispatch(notification, context); verify(context, never()).addUser(any(String.class), any(NotificationChannel.class)); }
IssueChangesEmailTemplate.class, ChangesOnMyIssueNotificationDispatcher.class, ChangesOnMyIssueNotificationDispatcher.newMetadata(), NewIssuesNotificationDispatcher.class, NewIssuesNotificationDispatcher.newMetadata(),
IssueChangesEmailTemplate.class, ChangesOnMyIssueNotificationDispatcher.class, ChangesOnMyIssueNotificationDispatcher.newMetadata(), NewIssuesNotificationDispatcher.class, NewIssuesNotificationDispatcher.newMetadata(),
IssueChangesEmailTemplate.class, ChangesOnMyIssueNotificationDispatcher.class, ChangesOnMyIssueNotificationDispatcher.newMetadata(), NewIssuesNotificationDispatcher.class, NewIssuesNotificationDispatcher.newMetadata(),
@Override public void dispatch(Notification notification, Context context) { String projectKey = notification.getFieldValue("projectKey"); Multimap<String, NotificationChannel> subscribedRecipients = notificationManager .findSubscribedRecipientsForDispatcher(this, projectKey, ALL_MUST_HAVE_ROLE_USER); // See available fields in the class IssueNotifications. // All the following users can be null String changeAuthor = notification.getFieldValue("changeAuthor"); String assignee = notification.getFieldValue("assignee"); if (!Objects.equals(changeAuthor, assignee)) { addUserToContextIfSubscribed(context, assignee, subscribedRecipients); } }
@Test public void should_dispatch_to_assignee() { 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 notification = new IssueChangeNotification() .setFieldValue("projectKey", "struts") .setFieldValue("changeAuthor", "olivier") .setFieldValue("assignee", "freddy"); underTest.performDispatch(notification, context); verify(context).addUser("freddy", twitterChannel); verify(context, never()).addUser("godin", twitterChannel); verifyNoMoreInteractions(context); }
IssueChangesEmailTemplate.class, ChangesOnMyIssueNotificationDispatcher.class, ChangesOnMyIssueNotificationDispatcher.newMetadata(), NewIssuesNotificationDispatcher.class, NewIssuesNotificationDispatcher.newMetadata(),
@Test public void should_not_dispatch_to_author_of_changes() { Multimap<String, NotificationChannel> recipients = HashMultimap.create(); recipients.put("simon", emailChannel); recipients.put("freddy", twitterChannel); recipients.put("godin", twitterChannel); when(notifications.findSubscribedRecipientsForDispatcher(underTest, "uuid1", new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER))).thenReturn(recipients); // change author is the assignee underTest.performDispatch( new IssueChangeNotification() .setFieldValue("projectKey", "struts") .setFieldValue("projectUuid", "uuid1") .setFieldValue("changeAuthor", "simon") .setFieldValue("assignee", "simon"), context); // no change author underTest.performDispatch(new IssueChangeNotification().setFieldValue("projectKey", "struts") .setFieldValue("new.resolution", "FIXED"), context); verifyNoMoreInteractions(context); } }