Search in sources :

Example 91 with ZonedDateTime

use of java.time.ZonedDateTime 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 92 with ZonedDateTime

use of java.time.ZonedDateTime in project sonarlint-core by SonarSource.

the class NotificationCheckerTest method testFailCode.

@Test
public void testFailCode() {
    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.createMock();
    WsClientTestUtils.addFailedResponse(client, expectedUrl, 404, "failed");
    NotificationChecker checker = new NotificationChecker(client);
    List<SonarQubeNotification> notifications = checker.request(Collections.singletonMap("myproject", timestamp));
    assertThat(notifications).isEmpty();
}
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 93 with ZonedDateTime

use of java.time.ZonedDateTime in project sonarlint-core by SonarSource.

the class NotificationCheckerTest method testFailParsing.

@Test
public void testFailParsing() {
    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, INVALID_RESPONSE);
    NotificationChecker checker = new NotificationChecker(client);
    List<SonarQubeNotification> notifications = checker.request(Collections.singletonMap("myproject", timestamp));
    assertThat(notifications).isEmpty();
}
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 94 with ZonedDateTime

use of java.time.ZonedDateTime in project questdb by bluestreak01.

the class TimeZoneRulesImplTest method testCompatibility.

@Test
public void testCompatibility() {
    Set<String> allZones = ZoneId.getAvailableZoneIds();
    List<String> zoneList = new ArrayList<>(allZones);
    Collections.sort(zoneList);
    List<ZoneId> zones = new ArrayList<>(zoneList.size());
    List<TimeZoneRulesImpl> zoneRules = new ArrayList<>(zoneList.size());
    for (String z : zoneList) {
        ZoneId zone = ZoneId.of(z);
        zones.add(zone);
        zoneRules.add(new TimeZoneRulesImpl(z, zone.getRules()));
    }
    long micros = Dates.toMicros(1900, 1, 1, 0, 0);
    long deadline = Dates.toMicros(2115, 12, 31, 0, 0);
    while (micros < deadline) {
        int y = Dates.getYear(micros);
        boolean leap = Dates.isLeapYear(y);
        int m = Dates.getMonthOfYear(micros, y, leap);
        int d = Dates.getDayOfMonth(micros, y, m, leap);
        LocalDateTime dt = LocalDateTime.of(y, m, d, 0, 0);
        for (int i = 0, n = zones.size(); i < n; i++) {
            ZoneId zone = zones.get(i);
            TimeZoneRulesImpl rules = zoneRules.get(i);
            ZonedDateTime zdt = dt.atZone(zone);
            long expected = zdt.getOffset().getTotalSeconds();
            // find out how much algo added to datetime itself
            long changed = Dates.toMicros(zdt.getYear(), zdt.getMonthValue(), zdt.getDayOfMonth(), zdt.getHour(), zdt.getMinute()) + zdt.getSecond() * Dates.SECOND_MICROS;
            // add any extra time
            expected += (changed - micros) / Dates.SECOND_MICROS;
            long offset = rules.getOffset(micros, y, leap);
            try {
                Assert.assertEquals(expected, offset / Dates.SECOND_MICROS);
            } catch (Throwable e) {
                System.out.println(zone.getId() + "; " + zdt + "; " + Dates.toString(micros + offset));
                System.out.println("e: " + expected + "; a: " + offset);
                System.out.println(dt);
                System.out.println(Dates.toString(micros));
                throw e;
            }
        }
        micros += Dates.DAY_MICROS;
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) ZoneId(java.time.ZoneId) ArrayList(java.util.ArrayList) ZonedDateTime(java.time.ZonedDateTime) Test(org.junit.Test)

Example 95 with ZonedDateTime

use of java.time.ZonedDateTime in project questdb by bluestreak01.

the class TimeZoneRulesImplTest method testSingle.

@Test
public void testSingle() {
    ZoneId zone = ZoneId.of("GMT");
    TimeZoneRulesImpl rules = new TimeZoneRulesImpl("GMT", zone.getRules());
    int y = 2017;
    int m = 3;
    int d = 29;
    LocalDateTime dt = LocalDateTime.of(y, m, d, 0, 0);
    long millis = Dates.toMicros(y, m, d, 0, 0);
    ZonedDateTime zdt = dt.atZone(zone);
    long expected = zdt.getOffset().getTotalSeconds();
    // find out how much algo added to datetime itself
    long changed = Dates.toMicros(zdt.getYear(), zdt.getMonthValue(), zdt.getDayOfMonth(), zdt.getHour(), zdt.getMinute()) + zdt.getSecond() * 1000;
    // add any extra time
    expected += (changed - millis) / 1000;
    long offset = rules.getOffset(millis, y, Dates.isLeapYear(y));
    try {
        Assert.assertEquals(expected, offset / 1000);
    } catch (Throwable e) {
        System.out.println(zone.getId() + "; " + zdt + "; " + Dates.toString(millis + offset));
        throw e;
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) ZoneId(java.time.ZoneId) ZonedDateTime(java.time.ZonedDateTime) Test(org.junit.Test)

Aggregations

ZonedDateTime (java.time.ZonedDateTime)1375 Test (org.junit.Test)570 Test (org.testng.annotations.Test)182 LocalDateTime (java.time.LocalDateTime)136 ZoneId (java.time.ZoneId)122 Instant (java.time.Instant)112 ArrayList (java.util.ArrayList)102 Test (org.junit.jupiter.api.Test)93 LocalDate (java.time.LocalDate)84 DateTimeFormatter (java.time.format.DateTimeFormatter)77 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)76 List (java.util.List)75 Date (java.util.Date)63 IOException (java.io.IOException)58 UUID (java.util.UUID)58 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)54 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)53 HashMap (java.util.HashMap)46 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)44 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)43