Search in sources :

Example 6 with SonarQubeNotification

use of org.sonarsource.sonarlint.core.client.api.notifications.SonarQubeNotification in project sonarlint-core by SonarSource.

the class NotificationCheckerTest method testSuccess.

@Test
public void testSuccess() {
    ZonedDateTime timestamp = ZonedDateTime.of(2017, 06, 04, 20, 0, 0, 0, ZoneOffset.ofHours(0));
    String expectedUrl = "api/developers/search_events?projects=myproject&from=2017-06-04T20%3A00%3A00%2B0000";
    SonarLintWsClient client = WsClientTestUtils.createMockWithResponse(expectedUrl, VALID_RESPONSE);
    NotificationChecker checker = new NotificationChecker(client);
    List<SonarQubeNotification> notifications = checker.request(Collections.singletonMap("myproject", timestamp));
    assertThat(notifications.size()).isEqualTo(2);
    assertThat(notifications.get(0).category()).isEqualTo("QUALITY_GATE");
    assertThat(notifications.get(0).message()).isEqualTo("Quality Gate is Red (was Orange)");
    assertThat(notifications.get(0).link()).isEqualTo("https://sonarcloud.io/dashboard?id=myproject");
    assertThat(notifications.get(0).projectKey()).isEqualTo("myproject");
    assertThat(notifications.get(0).time()).isEqualTo(ZonedDateTime.of(2017, 7, 17, 9, 55, 26, 0, ZoneOffset.ofHours(2)));
}
Also used : ZonedDateTime(java.time.ZonedDateTime) SonarQubeNotification(org.sonarsource.sonarlint.core.client.api.notifications.SonarQubeNotification) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Example 7 with SonarQubeNotification

use of org.sonarsource.sonarlint.core.client.api.notifications.SonarQubeNotification 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 8 with SonarQubeNotification

use of org.sonarsource.sonarlint.core.client.api.notifications.SonarQubeNotification 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)

Aggregations

SonarQubeNotification (org.sonarsource.sonarlint.core.client.api.notifications.SonarQubeNotification)8 ZonedDateTime (java.time.ZonedDateTime)6 Test (org.junit.Test)6 NotificationConfiguration (org.sonarsource.sonarlint.core.client.api.common.NotificationConfiguration)4 ServerConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ServerConfiguration)4 SonarLintWsClient (org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient)3 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 LastNotificationTime (org.sonarsource.sonarlint.core.client.api.notifications.LastNotificationTime)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)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