Search in sources :

Example 6 with Notification

use of org.sonar.api.notifications.Notification 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 Notification

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

the class NewIssuesNotificationDispatcherTest method shouldNotDispatchIfNotNewViolationsNotification.

@Test
public void shouldNotDispatchIfNotNewViolationsNotification() {
    Notification notification = new Notification("other-notif");
    dispatcher.performDispatch(notification, context);
    verify(context, never()).addUser(any(String.class), any(NotificationChannel.class));
}
Also used : NotificationChannel(org.sonar.api.notifications.NotificationChannel) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 8 with Notification

use of org.sonar.api.notifications.Notification 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 9 with Notification

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

the class IssueChangesEmailTemplateTest method email_should_display_assignee_change.

@Test
public void email_should_display_assignee_change() throws Exception {
    Notification notification = generateNotification().setFieldValue("old.assignee", "simon").setFieldValue("new.assignee", "louis");
    EmailMessage email = underTest.format(notification);
    assertThat(email.getMessageId()).isEqualTo("issue-changes/ABCDE");
    assertThat(email.getSubject()).isEqualTo("Struts, change on issue #ABCDE");
    String message = email.getMessage();
    String expected = Resources.toString(Resources.getResource("org/sonar/server/issue/notification/IssueChangesEmailTemplateTest/email_with_assignee_change.txt"), StandardCharsets.UTF_8);
    expected = StringUtils.remove(expected, '\r');
    assertThat(message).isEqualTo(expected);
    assertThat(email.getFrom()).isNull();
}
Also used : EmailMessage(org.sonar.plugins.emailnotifications.api.EmailMessage) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Example 10 with Notification

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

the class IssueChangesEmailTemplateTest method test_email_with_multiple_changes.

@Test
public void test_email_with_multiple_changes() throws Exception {
    Notification notification = generateNotification().setFieldValue("comment", "How to fix it?").setFieldValue("old.assignee", "simon").setFieldValue("new.assignee", "louis").setFieldValue("new.resolution", "FALSE-POSITIVE").setFieldValue("new.status", "RESOLVED").setFieldValue("new.type", "BUG").setFieldValue("new.tags", "bug performance");
    EmailMessage email = underTest.format(notification);
    assertThat(email.getMessageId()).isEqualTo("issue-changes/ABCDE");
    assertThat(email.getSubject()).isEqualTo("Struts, change on issue #ABCDE");
    String message = email.getMessage();
    String expected = Resources.toString(Resources.getResource("org/sonar/server/issue/notification/IssueChangesEmailTemplateTest/email_with_multiple_changes.txt"), StandardCharsets.UTF_8);
    expected = StringUtils.remove(expected, '\r');
    assertThat(message).isEqualTo(expected);
    assertThat(email.getFrom()).isNull();
}
Also used : EmailMessage(org.sonar.plugins.emailnotifications.api.EmailMessage) Notification(org.sonar.api.notifications.Notification) Test(org.junit.Test)

Aggregations

Notification (org.sonar.api.notifications.Notification)90 Test (org.junit.Test)83 EmailMessage (org.sonar.plugins.emailnotifications.api.EmailMessage)14 EmailMessage (org.sonar.server.issue.notification.EmailMessage)13 NotificationChannel (org.sonar.api.notifications.NotificationChannel)12 List (java.util.List)7 IntStream (java.util.stream.IntStream)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 Mockito.mock (org.mockito.Mockito.mock)5 Mockito.when (org.mockito.Mockito.when)5 ReportAnalysisFailureNotification (org.sonar.ce.task.projectanalysis.notification.ReportAnalysisFailureNotification)5 Tuple (org.assertj.core.groups.Tuple)4 Languages (org.sonar.api.resources.Languages)4 ActiveRuleChange (org.sonar.server.qualityprofile.ActiveRuleChange)4 Collections (java.util.Collections)3 Random (java.util.Random)3 Before (org.junit.Before)3 Mockito.verify (org.mockito.Mockito.verify)3 Mockito.verifyNoMoreInteractions (org.mockito.Mockito.verifyNoMoreInteractions)3 Mockito.verifyZeroInteractions (org.mockito.Mockito.verifyZeroInteractions)3