use of com.cadenzauk.siesta.model.TestRow in project siesta by cadenzauk.
the class DatabaseIntegrationTest method canRoundTripLocalTimes.
@ParameterizedTest
@ArgumentsSource(TestCaseArgumentsProvider.class)
@TestCase({ "America/Anchorage" })
@TestCase({ "America/Sao_Paulo" })
@TestCase({ "UTC" })
@TestCase({ "Europe/London" })
@TestCase({ "Africa/Johannesburg" })
@TestCase({ "Pacific/Chatham" })
void canRoundTripLocalTimes(String timeZone) {
Database database = testDatabase(dataSource, dialect);
try (UncheckedAutoCloseable ignored = withTimeZone(timeZone)) {
LocalTime expected = randomLocalTime();
TestRow input = TestRow.of(expected);
database.insert(input);
LocalTime result = database.from(TestRow.class).select(TestRow::localTimeOpt).where(TestRow::guid).isEqualTo(input.guid()).single();
assertThat(result, is(expected));
}
}
use of com.cadenzauk.siesta.model.TestRow 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.siesta.model.TestRow in project siesta by cadenzauk.
the class FunctionTest method functionTest.
@ParameterizedTest
@MethodSource("parametersForFunctionTest")
void functionTest(Function<Alias<TestRow>, TypedExpression<?>> sutSupplier, String expectedSql, Object[] expectedArgs) {
MockitoAnnotations.initMocks(this);
Database database = testDatabase(new AnsiDialect());
Alias<TestRow> alias = database.table(TestRow.class).as("s");
database.from(alias).select(sutSupplier.apply(alias), "foo").list(transaction);
verify(transaction).query(sql.capture(), args.capture(), rowMapper.capture());
assertThat(sql.getValue(), is("select " + expectedSql + " as foo from SIESTA.TEST_TABLE s"));
assertThat(args.getValue(), is(expectedArgs));
}
use of com.cadenzauk.siesta.model.TestRow 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.siesta.model.TestRow in project siesta by cadenzauk.
the class DatabaseIntegrationTest method roundTripNulls.
@SuppressWarnings("OptionalAssignedToNull")
@Test
void roundTripNulls() {
Database database = testDatabase(dataSource, dialect);
UUID guid = UUID.randomUUID();
database.insert(TestRow.newBuilder().guid(guid).decimalOpt(null).decimalReq(null).integerOpt(null).integerReq(null).localDateOpt(null).localDateReq(null).localDateTimeOpt(null).localDateTimeReq(null).localTimeOpt(null).localTimeReq(null).stringOpt(null).stringReq(null).utcDateTimeOpt(null).utcDateTimeReq(null).build());
TestRow result = database.from(TestRow.class).where(TestRow::guid).isEqualTo(guid).single();
assertThat(result.decimalOpt(), is(Optional.empty()));
assertThat(result.decimalReq(), nullValue());
assertThat(result.integerOpt(), is(Optional.empty()));
assertThat(result.integerReq(), nullValue());
assertThat(result.localDateOpt(), is(Optional.empty()));
assertThat(result.localDateReq(), nullValue());
assertThat(result.localDateTimeOpt(), is(Optional.empty()));
assertThat(result.localDateTimeReq(), nullValue());
assertThat(result.localTimeOpt(), is(Optional.empty()));
assertThat(result.localTimeReq(), nullValue());
assertThat(result.stringOpt(), is(Optional.empty()));
assertThat(result.stringReq(), nullValue());
assertThat(result.utcDateTimeOpt(), is(Optional.empty()));
assertThat(result.utcDateTimeReq(), nullValue());
}
Aggregations