Search in sources :

Example 11 with NotificationChannel

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

the class NewAlertsTest method should_not_dispatch_if_missing_project_id.

@Test
public void should_not_dispatch_if_missing_project_id() {
    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");
    dispatcher.performDispatch(notification, context);
    verifyNoMoreInteractions(context);
}
Also used : NotificationChannel(org.sonar.api.notifications.NotificationChannel) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 12 with NotificationChannel

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

the class ChangesOnMyIssueNotificationDispatcherTest method should_dispatch_to_assignee.

@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.findNotificationSubscribers(dispatcher, "struts")).thenReturn(recipients);
    Notification notification = new IssueChangeNotification().setFieldValue("projectKey", "struts").setFieldValue("changeAuthor", "olivier").setFieldValue("assignee", "freddy");
    dispatcher.performDispatch(notification, context);
    verify(context).addUser("freddy", twitterChannel);
    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 13 with NotificationChannel

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

the class NotificationChannelTest method defaultMethods.

@Test
public void defaultMethods() {
    NotificationChannel channel = new FakeNotificationChannel();
    assertThat(channel.getKey()).isEqualTo("FakeNotificationChannel");
    assertThat(channel.toString()).isEqualTo("FakeNotificationChannel");
}
Also used : NotificationChannel(org.sonar.api.notifications.NotificationChannel) Test(org.junit.Test)

Example 14 with NotificationChannel

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

the class RemoveActionTest 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 });
    notificationUpdater = new NotificationUpdater(userSession, dbClient);
    underTest = new RemoveAction(notificationCenter, notificationUpdater, 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 15 with NotificationChannel

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

the class NewIssuesNotificationDispatcher method dispatch.

@Override
public void dispatch(Notification notification, Context context) {
    String projectKey = notification.getFieldValue("projectKey");
    Multimap<String, NotificationChannel> subscribedRecipients = manager.findNotificationSubscribers(this, projectKey);
    for (Map.Entry<String, Collection<NotificationChannel>> channelsByRecipients : subscribedRecipients.asMap().entrySet()) {
        String userLogin = channelsByRecipients.getKey();
        for (NotificationChannel channel : channelsByRecipients.getValue()) {
            context.addUser(userLogin, channel);
        }
    }
}
Also used : NotificationChannel(org.sonar.api.notifications.NotificationChannel) Collection(java.util.Collection) Map(java.util.Map)

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