use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.
the class DataTypeTest method toDatabase.
@ParameterizedTest
@MethodSource("parametersForToDatabase")
<T> void toDatabase(DataType<T> dataType, T input, Object expected) {
if (input != null) {
when(db.dialect()).thenReturn(new AnsiDialect());
}
Object actual = dataType.toDatabase(db, input);
assertThat(actual, is(expected));
}
use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.
the class DataTypeTest method toDatabaseLocalDateTime.
@ParameterizedTest
@MethodSource("timeZones")
void toDatabaseLocalDateTime(String jvmTimeZone) {
try (UncheckedAutoCloseable ignored = withTimeZone(jvmTimeZone)) {
LocalDateTime input = RandomValues.randomLocalDateTime();
Timestamp expected = Timestamp.valueOf(input);
when(db.dialect()).thenReturn(new AnsiDialect());
Object result = DataType.LOCAL_DATE_TIME.toDatabase(db, input);
assertThat(result, is(expected));
}
}
use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.
the class EmbeddedTest method embeddedInProjection.
@Test
void embeddedInProjection() {
Database database = testDatabase(new AnsiDialect());
database.from(PartRow.class).select(PartRow::purchasePrice, "pp").comma(PartRow::retailPrice, "rp").comma(column(PartRow::purchasePrice).dot(MoneyAmount::currency), "pc").comma(column(PartRow::retailPrice).dot(MoneyAmount::currency), "rc").where(PartRow::partId).isEqualTo(4L).optional(sqlExecutor);
Mockito.verify(sqlExecutor).query(sql.capture(), args.capture(), any());
assertThat(sql.getValue(), is("select PART.PURCHASE_PRICE_AMOUNT as pp_PURCHASE_PRICE_AMOUNT, " + "PART.PURCHASE_PRICE_CCY as pp_PURCHASE_PRICE_CCY, " + "PART.RETAIL_PRICE_AMOUNT as rp_RETAIL_PRICE_AMOUNT, " + "PART.RETAIL_PRICE_CCY as rp_RETAIL_PRICE_CCY, " + "PART.PURCHASE_PRICE_CCY as pc, " + "PART.RETAIL_PRICE_CCY as rc " + "from SIESTA.PART PART " + "where PART.PART_ID = ?"));
assertThat(args.getValue(), is(toArray(4L)));
}
use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.
the class FromTest method validateInvalidThrows.
@Test
void validateInvalidThrows() {
Database database = testDatabase(new AnsiDialect());
calling(() -> database.from(WidgetRow.class).join(ManufacturerRow.class, "m").on(WidgetRow::name).isEqualTo("Fred").sql()).shouldThrow(InvalidJoinException.class).withMessage(is("Joined table 'SIESTA.MANUFACTURER m' is not referenced in the ON clause."));
}
use of com.cadenzauk.siesta.dialect.AnsiDialect in project siesta by cadenzauk.
the class SelectExpressionTest method isNotLike.
@Test
void isNotLike() {
Database database = testDatabase(new AnsiDialect());
String sql = database.from(WidgetRow.class).where(WidgetRow::name).isNotLike("abc%").sql();
assertThat(sql, is("select WIDGET.WIDGET_ID as WIDGET_WIDGET_ID, " + "WIDGET.NAME as WIDGET_NAME, " + "WIDGET.MANUFACTURER_ID as WIDGET_MANUFACTURER_ID, " + "WIDGET.DESCRIPTION as WIDGET_DESCRIPTION " + "from SIESTA.WIDGET WIDGET " + "where WIDGET.NAME not like ?"));
}
Aggregations