use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.
the class CountTest method countStar.
@Test
void countStar() {
Database database = TestDatabase.testDatabase(new AnsiDialect());
database.from(WidgetRow.class, "w").select(count(), "n").where(WidgetRow::manufacturerId).isEqualTo(4002L).list(transaction);
verify(transaction).query(sql.capture(), args.capture(), rowMapper.capture());
assertThat(sql.getValue(), is("select count(*) as n " + "from SIESTA.WIDGET w " + "where w.MANUFACTURER_ID = ?"));
assertThat(args.getValue(), arrayWithSize(1));
assertThat(args.getValue()[0], is(4002L));
}
use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.
the class DataTypeTest method toDatabaseOfOptional.
@ParameterizedTest
@MethodSource("parametersForToDatabase")
<T> void toDatabaseOfOptional(DataType<T> dataType, T input, Object expected) {
if (input != null) {
when(db.dialect()).thenReturn(new AnsiDialect());
}
Object actual = dataType.toDatabase(db, Optional.ofNullable(input));
assertThat(actual, is(expected));
}
use of com.cadenzauk.siesta.dialect.AnsiDialect 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.siesta.dialect.AnsiDialect 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)));
}
}
use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.
the class DataTypeTest method toDatabaseLocalDate.
@ParameterizedTest
@MethodSource("timeZones")
void toDatabaseLocalDate(String timeZone) {
try (UncheckedAutoCloseable ignored = withTimeZone(timeZone)) {
LocalDate input = RandomValues.randomLocalDate();
Date expected = Date.valueOf(input);
when(db.dialect()).thenReturn(new AnsiDialect());
Object result = DataType.LOCAL_DATE.toDatabase(db, input);
assertThat(result, is(expected));
}
}
Aggregations