Search in sources :

Example 6 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)

Example 7 with NotificationChannel

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

the class NewIssuesNotificationDispatcherTest method shouldDispatchToUsersWhoHaveSubscribedAndFlaggedProjectAsFavourite.

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

Example 8 with NotificationChannel

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

the class AddActionTest method setUp.

@Before
public void setUp() {
    NotificationDispatcherMetadata metadata1 = NotificationDispatcherMetadata.create(NOTIF_MY_NEW_ISSUES).setProperty(GLOBAL_NOTIFICATION, "true").setProperty(PER_PROJECT_NOTIFICATION, "true");
    NotificationDispatcherMetadata metadata2 = NotificationDispatcherMetadata.create(NOTIF_NEW_ISSUES).setProperty(GLOBAL_NOTIFICATION, "true");
    NotificationDispatcherMetadata metadata3 = NotificationDispatcherMetadata.create(NOTIF_NEW_QUALITY_GATE_STATUS).setProperty(GLOBAL_NOTIFICATION, "true").setProperty(PER_PROJECT_NOTIFICATION, "true");
    notificationCenter = new NotificationCenter(new NotificationDispatcherMetadata[] { metadata1, metadata2, metadata3 }, new NotificationChannel[] { emailChannel, twitterChannel, defaultChannel });
    underTest = new AddAction(notificationCenter, new NotificationUpdater(userSession, dbClient), dbClient, new ComponentFinder(dbClient), userSession);
    ws = new WsActionTester(underTest);
}
Also used : NotificationChannel(org.sonar.api.notifications.NotificationChannel) ComponentFinder(org.sonar.server.component.ComponentFinder) NotificationCenter(org.sonar.server.notification.NotificationCenter) NotificationDispatcherMetadata(org.sonar.server.notification.NotificationDispatcherMetadata) NotificationUpdater(org.sonar.server.notification.NotificationUpdater) WsActionTester(org.sonar.server.ws.WsActionTester) Before(org.junit.Before)

Example 9 with NotificationChannel

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

the class DefaultNotificationManager method findSubscribedRecipientsForDispatcher.

/**
   * {@inheritDoc}
   */
@Override
public Multimap<String, NotificationChannel> findSubscribedRecipientsForDispatcher(NotificationDispatcher dispatcher, @Nullable String projectUuid) {
    String dispatcherKey = dispatcher.getKey();
    SetMultimap<String, NotificationChannel> recipients = HashMultimap.create();
    for (NotificationChannel channel : notificationChannels) {
        String channelKey = channel.getKey();
        // Find users subscribed globally to the dispatcher (i.e. not on a specific project)
        addUsersToRecipientListForChannel(propertiesDao.selectUsersForNotification(dispatcherKey, channelKey, null), recipients, channel);
        if (projectUuid != null) {
            // Find users subscribed to the dispatcher specifically for the project
            addUsersToRecipientListForChannel(propertiesDao.selectUsersForNotification(dispatcherKey, channelKey, projectUuid), recipients, channel);
        }
    }
    return recipients;
}
Also used : NotificationChannel(org.sonar.api.notifications.NotificationChannel)

Example 10 with NotificationChannel

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

the class NewAlertsTest method should_dispatch_to_users_who_have_subscribed.

@Test
public void should_dispatch_to_users_who_have_subscribed() {
    Multimap<String, NotificationChannel> recipients = HashMultimap.create();
    recipients.put("user1", emailChannel);
    recipients.put("user2", twitterChannel);
    when(notificationManager.findSubscribedRecipientsForDispatcher(dispatcher, "uuid_34")).thenReturn(recipients);
    Notification notification = new Notification("alerts").setFieldValue("projectUuid", "uuid_34");
    dispatcher.performDispatch(notification, context);
    verify(context).addUser("user1", emailChannel);
    verify(context).addUser("user2", twitterChannel);
    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)15 Test (org.junit.Test)8 Notification (org.sonar.api.notifications.Notification)7 Collection (java.util.Collection)2 Map (java.util.Map)2 Before (org.junit.Before)2 ComponentFinder (org.sonar.server.component.ComponentFinder)2 NotificationCenter (org.sonar.server.notification.NotificationCenter)2 NotificationDispatcherMetadata (org.sonar.server.notification.NotificationDispatcherMetadata)2 NotificationUpdater (org.sonar.server.notification.NotificationUpdater)2 WsActionTester (org.sonar.server.ws.WsActionTester)2