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)));
}
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);
}
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);
}
Aggregations