Search in sources :

Example 31 with EmailNotificationChannel

use of org.sonar.server.notification.email.EmailNotificationChannel in project sonarqube by SonarSource.

the class ChangesOnMyIssueNotificationHandlerTest method deliver_has_no_effect_if_emailNotificationChannel_is_disabled.

@Test
public void deliver_has_no_effect_if_emailNotificationChannel_is_disabled() {
    when(emailNotificationChannel.isActivated()).thenReturn(false);
    Set<IssuesChangesNotification> notifications = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> mock(IssuesChangesNotification.class)).collect(toSet());
    int deliver = underTest.deliver(notifications);
    assertThat(deliver).isZero();
    verifyZeroInteractions(notificationManager);
    verify(emailNotificationChannel).isActivated();
    verifyNoMoreInteractions(emailNotificationChannel);
    notifications.forEach(Mockito::verifyZeroInteractions);
}
Also used : IntStream(java.util.stream.IntStream) ArgumentMatchers.anySet(org.mockito.ArgumentMatchers.anySet) ALL_MUST_HAVE_ROLE_USER(org.sonar.server.notification.NotificationManager.SubscriberPermissionsOnProject.ALL_MUST_HAVE_ROLE_USER) ListMultimap(com.google.common.collect.ListMultimap) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Random(java.util.Random) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) ArgumentCaptor(org.mockito.ArgumentCaptor) EmailDeliveryRequest(org.sonar.server.notification.email.EmailNotificationChannel.EmailDeliveryRequest) MoreCollectors.index(org.sonar.core.util.stream.MoreCollectors.index) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) AnalysisChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange) NotificationManager(org.sonar.server.notification.NotificationManager) MoreCollectors(org.sonar.core.util.stream.MoreCollectors) Nullable(javax.annotation.Nullable) Collectors.toSet(java.util.stream.Collectors.toSet) MoreCollectors.unorderedIndex(org.sonar.core.util.stream.MoreCollectors.unorderedIndex) User(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User) ImmutableSet(com.google.common.collect.ImmutableSet) Project(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) Set(java.util.Set) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) UserChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange) PER_PROJECT_NOTIFICATION(org.sonar.server.notification.NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION) Mockito.verify(org.mockito.Mockito.verify) IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule) Mockito(org.mockito.Mockito) Rule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Rule) List(java.util.List) Stream(java.util.stream.Stream) GLOBAL_NOTIFICATION(org.sonar.server.notification.NotificationDispatcherMetadata.GLOBAL_NOTIFICATION) Change(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Change) NotificationDispatcherMetadata(org.sonar.server.notification.NotificationDispatcherMetadata) EmailNotificationChannel(org.sonar.server.notification.email.EmailNotificationChannel) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) Random(java.util.Random) Mockito(org.mockito.Mockito) Test(org.junit.Test)

Example 32 with EmailNotificationChannel

use of org.sonar.server.notification.email.EmailNotificationChannel in project sonarqube by SonarSource.

the class QGChangeNotificationHandlerTest method deliver_has_no_effect_if_no_notification_has_projectKey.

@Test
public void deliver_has_no_effect_if_no_notification_has_projectKey() {
    when(emailNotificationChannel.isActivated()).thenReturn(true);
    Set<QGChangeNotification> notifications = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> newNotification(null)).collect(toSet());
    int deliver = underTest.deliver(notifications);
    assertThat(deliver).isZero();
    verifyZeroInteractions(notificationManager);
    verify(emailNotificationChannel).isActivated();
    verifyNoMoreInteractions(emailNotificationChannel);
    notifications.forEach(notification -> {
        verify(notification).getProjectKey();
        verifyNoMoreInteractions(notification);
    });
}
Also used : IntStream(java.util.stream.IntStream) ALL_MUST_HAVE_ROLE_USER(org.sonar.server.notification.NotificationManager.SubscriberPermissionsOnProject.ALL_MUST_HAVE_ROLE_USER) Collections.emptySet(java.util.Collections.emptySet) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) Random(java.util.Random) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) PER_PROJECT_NOTIFICATION(org.sonar.server.notification.NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION) Mockito.verify(org.mockito.Mockito.verify) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) Mockito(org.mockito.Mockito) Stream(java.util.stream.Stream) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) GLOBAL_NOTIFICATION(org.sonar.server.notification.NotificationDispatcherMetadata.GLOBAL_NOTIFICATION) NotificationDispatcherMetadata(org.sonar.server.notification.NotificationDispatcherMetadata) EmailNotificationChannel(org.sonar.server.notification.email.EmailNotificationChannel) NotificationManager(org.sonar.server.notification.NotificationManager) Collections(java.util.Collections) Nullable(javax.annotation.Nullable) Collectors.toSet(java.util.stream.Collectors.toSet) Mockito.mock(org.mockito.Mockito.mock) Random(java.util.Random) Test(org.junit.Test)

Example 33 with EmailNotificationChannel

use of org.sonar.server.notification.email.EmailNotificationChannel in project sonarqube by SonarSource.

the class BuiltInQPChangeNotificationHandlerTest method deliver_has_no_effect_if_emailNotificationChannel_is_disabled.

@Test
public void deliver_has_no_effect_if_emailNotificationChannel_is_disabled() {
    when(emailNotificationChannel.isActivated()).thenReturn(false);
    Set<BuiltInQPChangeNotification> notifications = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> mock(BuiltInQPChangeNotification.class)).collect(toSet());
    int deliver = underTest.deliver(notifications);
    assertThat(deliver).isZero();
    verify(emailNotificationChannel).isActivated();
    verifyNoMoreInteractions(emailNotificationChannel);
    verifyZeroInteractions(dbClient);
    notifications.forEach(Mockito::verifyZeroInteractions);
}
Also used : IntStream(java.util.stream.IntStream) Collections.emptySet(java.util.Collections.emptySet) AuthorizationDao(org.sonar.db.permission.AuthorizationDao) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) Random(java.util.Random) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) DbSession(org.sonar.db.DbSession) Mockito.verify(org.mockito.Mockito.verify) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) Mockito(org.mockito.Mockito) DbClient(org.sonar.db.DbClient) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) EmailSubscriberDto(org.sonar.db.EmailSubscriberDto) EmailNotificationChannel(org.sonar.server.notification.email.EmailNotificationChannel) Collectors.toSet(java.util.stream.Collectors.toSet) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Random(java.util.Random) Mockito(org.mockito.Mockito) Test(org.junit.Test)

Example 34 with EmailNotificationChannel

use of org.sonar.server.notification.email.EmailNotificationChannel in project sonarqube by SonarSource.

the class BuiltInQPChangeNotificationHandlerTest method deliver_has_no_effect_if_there_is_no_global_administer_email_subscriber.

@Test
public void deliver_has_no_effect_if_there_is_no_global_administer_email_subscriber() {
    when(emailNotificationChannel.isActivated()).thenReturn(true);
    Set<BuiltInQPChangeNotification> notifications = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> mock(BuiltInQPChangeNotification.class)).collect(toSet());
    when(authorizationDao.selectQualityProfileAdministratorLogins(dbSession)).thenReturn(emptySet());
    int deliver = underTest.deliver(notifications);
    assertThat(deliver).isZero();
    verify(emailNotificationChannel).isActivated();
    verifyNoMoreInteractions(emailNotificationChannel);
    verify(dbClient).openSession(false);
    verify(dbClient).authorizationDao();
    verifyNoMoreInteractions(dbClient);
    verify(authorizationDao).selectQualityProfileAdministratorLogins(dbSession);
    verifyNoMoreInteractions(authorizationDao);
    notifications.forEach(Mockito::verifyZeroInteractions);
}
Also used : IntStream(java.util.stream.IntStream) Collections.emptySet(java.util.Collections.emptySet) AuthorizationDao(org.sonar.db.permission.AuthorizationDao) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) Random(java.util.Random) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) DbSession(org.sonar.db.DbSession) Mockito.verify(org.mockito.Mockito.verify) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) Mockito(org.mockito.Mockito) DbClient(org.sonar.db.DbClient) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) EmailSubscriberDto(org.sonar.db.EmailSubscriberDto) EmailNotificationChannel(org.sonar.server.notification.email.EmailNotificationChannel) Collectors.toSet(java.util.stream.Collectors.toSet) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Random(java.util.Random) Mockito(org.mockito.Mockito) Test(org.junit.Test)

Aggregations

Random (java.util.Random)34 Set (java.util.Set)34 Collectors.toSet (java.util.stream.Collectors.toSet)34 IntStream (java.util.stream.IntStream)34 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)34 Test (org.junit.Test)34 Mockito (org.mockito.Mockito)34 Mockito.mock (org.mockito.Mockito.mock)34 Mockito.verify (org.mockito.Mockito.verify)34 Mockito.verifyNoMoreInteractions (org.mockito.Mockito.verifyNoMoreInteractions)34 Mockito.verifyZeroInteractions (org.mockito.Mockito.verifyZeroInteractions)34 Mockito.when (org.mockito.Mockito.when)34 EmailNotificationChannel (org.sonar.server.notification.email.EmailNotificationChannel)34 Stream (java.util.stream.Stream)31 RandomStringUtils.randomAlphabetic (org.apache.commons.lang.RandomStringUtils.randomAlphabetic)31 NotificationDispatcherMetadata (org.sonar.server.notification.NotificationDispatcherMetadata)31 GLOBAL_NOTIFICATION (org.sonar.server.notification.NotificationDispatcherMetadata.GLOBAL_NOTIFICATION)31 PER_PROJECT_NOTIFICATION (org.sonar.server.notification.NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION)31 NotificationManager (org.sonar.server.notification.NotificationManager)31 ALL_MUST_HAVE_ROLE_USER (org.sonar.server.notification.NotificationManager.SubscriberPermissionsOnProject.ALL_MUST_HAVE_ROLE_USER)28