Search in sources :

Example 1 with NotificationConfiguration

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

the class NotificationTimerTask method requestForServer.

private void requestForServer(ServerConfiguration serverConfiguration, List<NotificationConfiguration> configs) {
    try {
        Map<String, ZonedDateTime> request = configs.stream().collect(Collectors.toMap(NotificationConfiguration::projectKey, NotificationTimerTask::getLastNotificationTime, MERGE_TIMES));
        NotificationChecker notificationChecker = checkerFactory.create(serverConfiguration);
        List<SonarQubeNotification> notifications = notificationChecker.request(request);
        for (SonarQubeNotification n : notifications) {
            Stream<NotificationConfiguration> matchingConfStream = configs.stream();
            if (n.projectKey() != null) {
                matchingConfStream = matchingConfStream.filter(c -> c.projectKey().equals(n.projectKey()));
            }
            matchingConfStream.forEach(c -> {
                c.listener().handle(n);
                c.lastNotificationTime().set(n.time());
            });
        }
    } catch (Exception e) {
        LOG.warn("Failed to request SonarQube events to " + serverConfiguration.getUrl(), e);
    }
}
Also used : Logger(org.slf4j.Logger) ZonedDateTime(java.time.ZonedDateTime) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) SonarQubeNotification(org.sonarsource.sonarlint.core.client.api.notifications.SonarQubeNotification) ServerConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration) Collectors(java.util.stream.Collectors) BinaryOperator(java.util.function.BinaryOperator) ArrayList(java.util.ArrayList) List(java.util.List) Stream(java.util.stream.Stream) NotificationConfiguration(org.sonarsource.sonarlint.core.client.api.common.NotificationConfiguration) Map(java.util.Map) TimerTask(java.util.TimerTask) Collections(java.util.Collections) ZonedDateTime(java.time.ZonedDateTime) SonarQubeNotification(org.sonarsource.sonarlint.core.client.api.notifications.SonarQubeNotification) NotificationConfiguration(org.sonarsource.sonarlint.core.client.api.common.NotificationConfiguration)

Example 2 with NotificationConfiguration

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

the class NotificationTimerTaskTest method testRepeatedProject.

@Test
public void testRepeatedProject() {
    // 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");
    NotificationConfiguration project2 = createProject("myproject");
    LastNotificationTime notificationTime = mock(LastNotificationTime.class);
    when(notificationTime.get()).thenReturn(ZonedDateTime.now().minusHours(2));
    when(project2.lastNotificationTime()).thenReturn(notificationTime);
    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));
    // should use the most recent time
    verify(notificationChecker).request(Collections.singletonMap("myproject", time));
    verify(listener).handle(notif);
}
Also used : LastNotificationTime(org.sonarsource.sonarlint.core.client.api.notifications.LastNotificationTime) 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 3 with NotificationConfiguration

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

the class SonarQubeEventNotifications method register.

private void register(SonarLintProjectSettings settings) {
    unregister();
    if (settings.isBindingEnabled()) {
        SonarQubeServer server;
        try {
            server = bindingManager.getSonarQubeServer();
        } catch (InvalidBindingException e) {
            // do nothing
            return;
        }
        if (server.enableNotifications()) {
            NotificationConfiguration config = createConfiguration(settings, server);
            SonarQubeNotifications.get().register(config);
        }
    }
}
Also used : InvalidBindingException(org.sonarlint.intellij.exception.InvalidBindingException) SonarQubeServer(org.sonarlint.intellij.config.global.SonarQubeServer) NotificationConfiguration(org.sonarsource.sonarlint.core.client.api.common.NotificationConfiguration)

Example 4 with NotificationConfiguration

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

the class NotificationTimerTaskTest method createProject.

private NotificationConfiguration createProject(String key, ServerConfiguration config) {
    NotificationConfiguration project = mock(NotificationConfiguration.class);
    when(project.listener()).thenReturn(listener);
    when(project.projectKey()).thenReturn(key);
    when(project.serverConfiguration()).thenReturn(config);
    when(project.lastNotificationTime()).thenReturn(notificationTime);
    return project;
}
Also used : NotificationConfiguration(org.sonarsource.sonarlint.core.client.api.common.NotificationConfiguration)

Example 5 with NotificationConfiguration

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

the class NotificationTimerTaskTest method testErrorParsing.

@Test
public void testErrorParsing() {
    when(notificationChecker.request(anyMap())).thenThrow(new IllegalStateException());
    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)

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