Search in sources :

Example 6 with NotificationConfiguration

use of org.sonarsource.sonarlint.core.client.api.common.NotificationConfiguration in project sonarlint-core by SonarSource.

the class NotificationTimerTaskTest method testSingleProjectWithNotifications.

@Test
public void testSingleProjectWithNotifications() {
    // return one notification for our project
    SonarQubeNotification notif = mock(SonarQubeNotification.class);
    when(notif.projectKey()).thenReturn("myproject");
    when(notificationChecker.request(Collections.singletonMap("myproject", time))).thenReturn(Collections.singletonList(notif));
    // execute with one project
    NotificationConfiguration project = createProject("myproject");
    timerTask.setProjects(Collections.singleton(project));
    timerTask.run();
    // verify checker used once and notification was returned through the listener
    verify(notificationCheckerFactory, times(1)).create(any(ServerConfiguration.class));
    verify(notificationChecker).request(Collections.singletonMap("myproject", time));
    verify(listener).handle(notif);
}
Also used : SonarQubeNotification(org.sonarsource.sonarlint.core.client.api.notifications.SonarQubeNotification) ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) NotificationConfiguration(org.sonarsource.sonarlint.core.client.api.common.NotificationConfiguration) Test(org.junit.Test)

Example 7 with NotificationConfiguration

use of org.sonarsource.sonarlint.core.client.api.common.NotificationConfiguration in project sonarlint-core by SonarSource.

the class NotificationTimerTaskTest method testLimit24h.

@Test
public void testLimit24h() {
    when(notificationTime.get()).thenReturn(ZonedDateTime.now().minusDays(30));
    // return one notification for our project
    SonarQubeNotification notif = mock(SonarQubeNotification.class);
    when(notif.projectKey()).thenReturn("myproject");
    when(notificationChecker.request(anyMap())).thenReturn(Collections.singletonList(notif));
    // execute with one project
    NotificationConfiguration project = createProject("myproject");
    timerTask.setProjects(Collections.singleton(project));
    timerTask.run();
    // verify checker used once and notification was returned through the listener
    verify(notificationCheckerFactory, times(1)).create(any(ServerConfiguration.class));
    verify(notificationChecker).request(ArgumentMatchers.argThat(map -> {
        ZonedDateTime time = map.values().iterator().next();
        return time.isAfter(ZonedDateTime.now().minusHours(25)) && time.isBefore(ZonedDateTime.now().minusHours(23));
    }));
    verify(listener).handle(notif);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers(org.mockito.ArgumentMatchers) Mock(org.mockito.Mock) LastNotificationTime(org.sonarsource.sonarlint.core.client.api.notifications.LastNotificationTime) ZonedDateTime(java.time.ZonedDateTime) SonarQubeNotification(org.sonarsource.sonarlint.core.client.api.notifications.SonarQubeNotification) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) SonarQubeNotificationListener(org.sonarsource.sonarlint.core.client.api.notifications.SonarQubeNotificationListener) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) MockitoAnnotations(org.mockito.MockitoAnnotations) NotificationConfiguration(org.sonarsource.sonarlint.core.client.api.common.NotificationConfiguration) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) Before(org.junit.Before) ZonedDateTime(java.time.ZonedDateTime) SonarQubeNotification(org.sonarsource.sonarlint.core.client.api.notifications.SonarQubeNotification) ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) NotificationConfiguration(org.sonarsource.sonarlint.core.client.api.common.NotificationConfiguration) Test(org.junit.Test)

Example 8 with NotificationConfiguration

use of org.sonarsource.sonarlint.core.client.api.common.NotificationConfiguration in project sonarlint-core by SonarSource.

the class NotificationTimerTaskTest method testSingleProjectWithoutNotifications.

@Test
public void testSingleProjectWithoutNotifications() {
    NotificationConfiguration project = createProject("myproject");
    timerTask.setProjects(Collections.singleton(project));
    timerTask.run();
    verify(notificationCheckerFactory, times(1)).create(any(ServerConfiguration.class));
    verify(notificationChecker).request(Collections.singletonMap("myproject", time));
    verifyZeroInteractions(listener);
}
Also used : ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) NotificationConfiguration(org.sonarsource.sonarlint.core.client.api.common.NotificationConfiguration) Test(org.junit.Test)

Example 9 with NotificationConfiguration

use of org.sonarsource.sonarlint.core.client.api.common.NotificationConfiguration in project sonarlint-intellij by SonarSource.

the class SonarQubeEventNotifications method createConfiguration.

private NotificationConfiguration createConfiguration(SonarLintProjectSettings settings, SonarQubeServer server) {
    String projectKey = settings.getProjectKey();
    ServerConfiguration serverConfiguration = SonarLintUtils.getServerConfiguration(server);
    return new NotificationConfiguration(eventListener, notificationTime, projectKey, serverConfiguration);
}
Also used : ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) NotificationConfiguration(org.sonarsource.sonarlint.core.client.api.common.NotificationConfiguration)

Aggregations

NotificationConfiguration (org.sonarsource.sonarlint.core.client.api.common.NotificationConfiguration)9 ServerConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration)7 Test (org.junit.Test)5 SonarQubeNotification (org.sonarsource.sonarlint.core.client.api.notifications.SonarQubeNotification)4 ZonedDateTime (java.time.ZonedDateTime)2 Collections (java.util.Collections)2 LastNotificationTime (org.sonarsource.sonarlint.core.client.api.notifications.LastNotificationTime)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 TimerTask (java.util.TimerTask)1 BinaryOperator (java.util.function.BinaryOperator)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Before (org.junit.Before)1 ArgumentMatchers (org.mockito.ArgumentMatchers)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 ArgumentMatchers.anyMap (org.mockito.ArgumentMatchers.anyMap)1 Mock (org.mockito.Mock)1