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