Search in sources :

Example 1 with NotificationChannel

use of org.sonar.api.notifications.NotificationChannel in project sonarqube by SonarSource.

the class MyNewIssuesNotificationDispatcher method dispatch.

@Override
public void dispatch(Notification notification, Context context) {
    String projectKey = notification.getFieldValue("projectKey");
    String assignee = notification.getFieldValue("assignee");
    Multimap<String, NotificationChannel> subscribedRecipients = manager.findNotificationSubscribers(this, projectKey);
    Collection<NotificationChannel> channels = subscribedRecipients.get(assignee);
    for (NotificationChannel channel : channels) {
        context.addUser(assignee, channel);
    }
}
Also used : NotificationChannel(org.sonar.api.notifications.NotificationChannel)

Example 2 with NotificationChannel

use of org.sonar.api.notifications.NotificationChannel in project sonarqube by SonarSource.

the class DefaultNotificationManager method findNotificationSubscribers.

@Override
public Multimap<String, NotificationChannel> findNotificationSubscribers(NotificationDispatcher dispatcher, @Nullable String componentKey) {
    String dispatcherKey = dispatcher.getKey();
    SetMultimap<String, NotificationChannel> recipients = HashMultimap.create();
    for (NotificationChannel channel : notificationChannels) {
        addUsersToRecipientListForChannel(propertiesDao.selectNotificationSubscribers(dispatcherKey, channel.getKey(), componentKey), recipients, channel);
    }
    return recipients;
}
Also used : NotificationChannel(org.sonar.api.notifications.NotificationChannel)

Example 3 with NotificationChannel

use of org.sonar.api.notifications.NotificationChannel in project sonarqube by SonarSource.

the class DoNotFixNotificationDispatcherTest method ignore_other_resolutions.

/**
   * 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(underTest, "struts")).thenReturn(recipients);
    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);
}
Also used : NotificationChannel(org.sonar.api.notifications.NotificationChannel) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 4 with NotificationChannel

use of org.sonar.api.notifications.NotificationChannel in project sonarqube by SonarSource.

the class DoNotFixNotificationDispatcherTest method should_dispatch_to_subscribers.

@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(underTest, "struts")).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);
}
Also used : NotificationChannel(org.sonar.api.notifications.NotificationChannel) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 5 with NotificationChannel

use of org.sonar.api.notifications.NotificationChannel in project sonarqube by SonarSource.

the class MyNewIssuesNotificationDispatcherTest method dispatch_to_users_who_have_subscribed_to_notification_and_project.

@Test
public void dispatch_to_users_who_have_subscribed_to_notification_and_project() {
    Multimap<String, NotificationChannel> recipients = HashMultimap.create();
    recipients.put("user1", emailChannel);
    recipients.put("user2", twitterChannel);
    when(notificationManager.findNotificationSubscribers(underTest, "struts")).thenReturn(recipients);
    Notification notification = new Notification(MyNewIssuesNotification.MY_NEW_ISSUES_NOTIF_TYPE).setFieldValue("projectKey", "struts").setFieldValue("assignee", "user1");
    underTest.performDispatch(notification, context);
    verify(context).addUser("user1", emailChannel);
    verifyNoMoreInteractions(context);
}
Also used : NotificationChannel(org.sonar.api.notifications.NotificationChannel) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Aggregations

NotificationChannel (org.sonar.api.notifications.NotificationChannel)21 Test (org.junit.Test)12 Notification (org.sonar.api.notifications.Notification)8 Collection (java.util.Collection)6 Subscriber (org.sonar.db.property.Subscriber)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Before (org.junit.Before)3 NotificationDispatcherMetadata (org.sonar.server.notification.NotificationDispatcherMetadata)3 SubscriberPermissionsOnProject (org.sonar.server.notification.NotificationManager.SubscriberPermissionsOnProject)3 Map (java.util.Map)2 ComponentFinder (org.sonar.server.component.ComponentFinder)2 NotificationCenter (org.sonar.server.notification.NotificationCenter)2 NotificationUpdater (org.sonar.server.notification.NotificationUpdater)2 WsActionTester (org.sonar.server.ws.WsActionTester)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)1 Multimap (com.google.common.collect.Multimap)1 IOException (java.io.IOException)1 InvalidClassException (java.io.InvalidClassException)1