use of com.cadenzauk.core.lang.UncheckedAutoCloseable in project siesta by cadenzauk.
the class DatabaseIntegrationTest method localDateTimeLiteral.
@SuppressWarnings("UnnecessaryLocalVariable")
@ParameterizedTest
@MethodSource("parametersForLocalDateTimeLiteral")
void localDateTimeLiteral(String timeZone, LocalDateTime value) {
Database database = testDatabase(dataSource, dialect);
try (UncheckedAutoCloseable ignored = withTimeZone(timeZone)) {
LocalDateTime expected = value;
LocalDateTime 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 canRoundTripLocalDateTimes.
@ParameterizedTest
@ArgumentsSource(TestCaseArgumentsProvider.class)
@TestCase({ "America/Anchorage" })
@TestCase({ "America/Sao_Paulo" })
@TestCase({ "UTC" })
@TestCase({ "Europe/London" })
@TestCase({ "Africa/Johannesburg" })
@TestCase({ "Pacific/Chatham" })
void canRoundTripLocalDateTimes(String timeZone) {
Database database = testDatabase(dataSource, dialect);
try (UncheckedAutoCloseable ignored = withTimeZone(timeZone)) {
LocalDateTime expected = randomLocalDateTime();
TestRow input = TestRow.of(expected);
database.insert(input);
LocalDateTime result = database.from(TestRow.class).select(TestRow::localDateTimeOpt).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 currentTimestampTest.
@ParameterizedTest
@ArgumentsSource(TestCaseArgumentsProvider.class)
@TestCase({ "America/Anchorage" })
@TestCase({ "America/Sao_Paulo" })
@TestCase({ "UTC" })
@TestCase({ "Europe/London" })
@TestCase({ "Africa/Johannesburg" })
@TestCase({ "Pacific/Chatham" })
void currentTimestampTest(String timeZone) {
Database database = testDatabase(dataSource, dialect);
try (UncheckedAutoCloseable ignored = TemporalTestUtil.withTimeZone(timeZone)) {
ZonedDateTime before = ZonedDateTime.now(ZoneId.of("UTC")).minusSeconds(10);
ZonedDateTime now = database.select(currentTimestamp()).single();
ZonedDateTime after = ZonedDateTime.now(ZoneId.of("UTC")).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 DataTypeTest method getLocalDate.
@ParameterizedTest
@MethodSource("timeZones")
void getLocalDate(String timeZone) throws SQLException {
try (UncheckedAutoCloseable ignored = withTimeZone(timeZone)) {
LocalDate expected = randomLocalDate();
when(db.dialect()).thenReturn(new AnsiDialect());
when(rs.getDate(eq("someColumn"), any())).thenReturn(Date.valueOf(expected));
Optional<LocalDate> result = DataType.LOCAL_DATE.get(rs, "someColumn", db);
assertThat(result, is(Optional.of(expected)));
}
}
use of com.cadenzauk.core.lang.UncheckedAutoCloseable in project siesta by cadenzauk.
the class DataTypeTest method getLocalDateTime.
@ParameterizedTest
@MethodSource("timeZones")
void getLocalDateTime(String timeZone) throws SQLException {
try (UncheckedAutoCloseable ignored = withTimeZone(timeZone)) {
LocalDateTime expected = randomLocalDateTime();
when(db.dialect()).thenReturn(new AnsiDialect());
when(rs.getTimestamp(eq("someColumn"), any())).thenReturn(Timestamp.valueOf(expected));
Optional<LocalDateTime> result = DataType.LOCAL_DATE_TIME.get(rs, "someColumn", db);
assertThat(result, is(Optional.of(expected)));
}
}
Aggregations