Search in sources :

Example 6 with UncheckedAutoCloseable

use of com.cadenzauk.core.lang.UncheckedAutoCloseable in project siesta by cadenzauk.

the class DatabaseIntegrationTest method canRoundTripZonedDateTimes.

@ParameterizedTest
@ArgumentsSource(TestCaseArgumentsProvider.class)
@TestCase({ "America/Anchorage" })
@TestCase({ "America/Sao_Paulo" })
@TestCase({ "UTC" })
@TestCase({ "Europe/London" })
@TestCase({ "Africa/Johannesburg" })
@TestCase({ "Pacific/Chatham" })
void canRoundTripZonedDateTimes(String timeZone) {
    Database database = testDatabase(dataSource, dialect);
    try (UncheckedAutoCloseable ignored = withTimeZone(timeZone)) {
        ZonedDateTime expected = randomZonedDateTime(ZoneId.of("UTC"));
        TestRow input = TestRow.of(expected);
        database.insert(input);
        ZonedDateTime result = database.from(TestRow.class).select(TestRow::utcDateTimeOpt).where(TestRow::guid).isEqualTo(input.guid()).single();
        assertThat(result, is(expected));
    }
}
Also used : ZonedDateTime(java.time.ZonedDateTime) RandomValues.randomZonedDateTime(com.cadenzauk.core.RandomValues.randomZonedDateTime) TestRow(com.cadenzauk.siesta.model.TestRow) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) UncheckedAutoCloseable(com.cadenzauk.core.lang.UncheckedAutoCloseable) TestCase(com.cadenzauk.core.junit.TestCase) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 7 with UncheckedAutoCloseable

use of com.cadenzauk.core.lang.UncheckedAutoCloseable in project siesta by cadenzauk.

the class DatabaseIntegrationTest method localTimeiteral.

@SuppressWarnings("UnnecessaryLocalVariable")
@ParameterizedTest
@MethodSource("parametersForLocalTimeLiteral")
void localTimeiteral(String timeZone, LocalTime value) {
    Database database = testDatabase(dataSource, dialect);
    try (UncheckedAutoCloseable ignored = withTimeZone(timeZone)) {
        LocalTime expected = value;
        LocalTime result = database.select(literal(value)).single();
        assertThat(result, is(expected));
    }
}
Also used : LocalTime(java.time.LocalTime) RandomValues.randomLocalTime(com.cadenzauk.core.RandomValues.randomLocalTime) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) UncheckedAutoCloseable(com.cadenzauk.core.lang.UncheckedAutoCloseable) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 8 with UncheckedAutoCloseable

use of com.cadenzauk.core.lang.UncheckedAutoCloseable in project siesta by cadenzauk.

the class DatabaseIntegrationTest method currentTimestampLocalTest.

@ParameterizedTest
@ArgumentsSource(TestCaseArgumentsProvider.class)
@TestCase({ "America/Anchorage" })
@TestCase({ "America/Sao_Paulo" })
@TestCase({ "UTC" })
@TestCase({ "Europe/London" })
@TestCase({ "Africa/Johannesburg" })
@TestCase({ "Pacific/Chatham" })
void currentTimestampLocalTest(String timeZone) {
    Database database = testDatabase(dataSource, dialect);
    try (UncheckedAutoCloseable ignored = TemporalTestUtil.withTimeZone(timeZone)) {
        LocalDateTime before = LocalDateTime.now(database.databaseTimeZone()).minusSeconds(10);
        LocalDateTime now = database.select(currentTimestampLocal()).single();
        LocalDateTime after = LocalDateTime.now(database.databaseTimeZone()).plusSeconds(10);
        System.out.printf("%s <= %s <= %s%n", before, now, after);
        assertThat(before.isAfter(now), is(false));
        assertThat(now.isAfter(after), is(false));
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) RandomValues.randomLocalDateTime(com.cadenzauk.core.RandomValues.randomLocalDateTime) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) UncheckedAutoCloseable(com.cadenzauk.core.lang.UncheckedAutoCloseable) TestCase(com.cadenzauk.core.junit.TestCase) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 9 with UncheckedAutoCloseable

use of com.cadenzauk.core.lang.UncheckedAutoCloseable in project siesta by cadenzauk.

the class DatabaseIntegrationTest method currentDateTest.

@ParameterizedTest
@ArgumentsSource(TestCaseArgumentsProvider.class)
@TestCase({ "America/Anchorage" })
@TestCase({ "America/Sao_Paulo" })
@TestCase({ "UTC" })
@TestCase({ "Europe/London" })
@TestCase({ "Africa/Johannesburg" })
@TestCase({ "Pacific/Chatham" })
void currentDateTest(String timeZone) {
    Database database = testDatabase(dataSource, dialect);
    try (UncheckedAutoCloseable ignored = TemporalTestUtil.withTimeZone(timeZone)) {
        LocalDate before = LocalDate.now(database.databaseTimeZone());
        LocalDate now = database.select(currentDate()).single();
        LocalDate after = LocalDate.now(database.databaseTimeZone());
        System.out.printf("%s <= %s <= %s%n", before, now, after);
        assertThat(before.isAfter(now), is(false));
        assertThat(now.isAfter(after), is(false));
    }
}
Also used : TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) UncheckedAutoCloseable(com.cadenzauk.core.lang.UncheckedAutoCloseable) LocalDate(java.time.LocalDate) TestCase(com.cadenzauk.core.junit.TestCase) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 10 with UncheckedAutoCloseable

use of com.cadenzauk.core.lang.UncheckedAutoCloseable in project siesta by cadenzauk.

the class DatabaseIntegrationTest method zonedDateTimeLiteral.

@ParameterizedTest
@MethodSource("parametersForZonedDateTimeLiteral")
void zonedDateTimeLiteral(String timeZone, ZonedDateTime value) {
    Database database = testDatabase(dataSource, dialect);
    try (UncheckedAutoCloseable ignored = withTimeZone(timeZone)) {
        ZonedDateTime expected = value.withZoneSameInstant(ZoneId.of("UTC"));
        ZonedDateTime result = database.select(literal(value)).single();
        assertThat(result, is(expected));
    }
}
Also used : ZonedDateTime(java.time.ZonedDateTime) RandomValues.randomZonedDateTime(com.cadenzauk.core.RandomValues.randomZonedDateTime) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) UncheckedAutoCloseable(com.cadenzauk.core.lang.UncheckedAutoCloseable) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

UncheckedAutoCloseable (com.cadenzauk.core.lang.UncheckedAutoCloseable)22 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)22 MethodSource (org.junit.jupiter.params.provider.MethodSource)16 ZonedDateTime (java.time.ZonedDateTime)10 TestDatabase.testDatabase (com.cadenzauk.siesta.model.TestDatabase.testDatabase)9 Timestamp (java.sql.Timestamp)7 TestCase (com.cadenzauk.core.junit.TestCase)6 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)6 RandomValues.randomLocalDateTime (com.cadenzauk.core.RandomValues.randomLocalDateTime)5 AnsiDialect (com.cadenzauk.siesta.dialect.AnsiDialect)5 LocalDate (java.time.LocalDate)5 LocalDateTime (java.time.LocalDateTime)5 RandomValues.randomZonedDateTime (com.cadenzauk.core.RandomValues.randomZonedDateTime)3 TestRow (com.cadenzauk.siesta.model.TestRow)3 RandomValues.randomLocalDate (com.cadenzauk.core.RandomValues.randomLocalDate)2 RandomValues.randomLocalTime (com.cadenzauk.core.RandomValues.randomLocalTime)2 Date (java.sql.Date)2 LocalTime (java.time.LocalTime)2 ZoneId (java.time.ZoneId)1