use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.
the class BooleanExpressionTest method testOr.
@ParameterizedTest
@MethodSource("argsForOr")
void testOr(BiFunction<Alias<SalespersonRow>, BooleanExpression, BooleanExpression> method, String expectedSql) {
MockitoAnnotations.initMocks(this);
Database database = testDatabase(new AnsiDialect());
Alias<SalespersonRow> alias = database.table(SalespersonRow.class).as("s");
Scope scope = new Scope(database, alias);
when(sut.precedence()).thenReturn(Precedence.UNARY);
method.apply(alias, sut);
verify(sut).appendOr(appendArg.capture());
assertThat(appendArg.getValue().sql(scope), is(expectedSql));
}
use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.
the class CaseExpressionTest method initialWhen.
@ParameterizedTest
@MethodSource("parametersForInitialWhen")
void initialWhen(String expected, Function<Alias<WidgetRow>, CaseExpression<String>> f, Object[] expectedArgs) {
Database database = testDatabase(new AnsiDialect());
Alias<WidgetRow> w = database.table(WidgetRow.class).as("w");
database.from(w).select(f.apply(w).orElse(literal("DEFAULT")), "name").list(transaction);
verify(transaction).query(sql.capture(), args.capture(), any());
assertThat(sql.getValue(), is("select case " + expected + " else 'DEFAULT' end as name " + "from SIESTA.WIDGET w"));
assertThat(args.getValue(), is(expectedArgs));
}
use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.
the class CoalesceFunctionTest method coalesceTest.
@ParameterizedTest
@MethodSource("parametersForCoalesce")
void coalesceTest(String name, Function<Alias<WidgetRow>, CoalesceFunction<String>> f, String expected) {
Database database = testDatabase(new AnsiDialect());
Alias<WidgetRow> w = database.table(WidgetRow.class).as("w");
String sql = database.from(w).select(f.apply(w), "name").where(WidgetRow::manufacturerId).isEqualTo(2L).sql();
assertThat(sql, is("select " + expected + " as name " + "from SIESTA.WIDGET w " + "where w.MANUFACTURER_ID = ?"));
}
use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.
the class ExpressionBuilderTest method testExpression.
@ParameterizedTest
@MethodSource("argsForTestExpression")
void testExpression(BiFunction<ExpressionBuilder<String, InWhereExpectingAnd<String>>, Alias<SalespersonRow>, InWhereExpectingAnd<String>> method, String expectedSql, Object[] expectedArgs) {
MockitoAnnotations.initMocks(this);
Database database = testDatabase(new AnsiDialect());
Alias<SalespersonRow> alias = database.table(SalespersonRow.class).as("s");
ExpressionBuilder<String, InWhereExpectingAnd<String>> select = database.from(alias).select(SalespersonRow::firstName, "name").where(SalespersonRow::firstName);
method.apply(select, alias).list(transaction);
verify(transaction).query(sql.capture(), args.capture(), any());
assertThat(sql.getValue(), is("select s.FIRST_NAME as name from SIESTA.SALESPERSON s where s.FIRST_NAME " + expectedSql));
assertThat(args.getValue(), is(expectedArgs));
}
use of com.cadenzauk.siesta.Database 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));
}
Aggregations