Search in sources :

Example 1 with InWhereExpectingAnd

use of com.cadenzauk.siesta.grammar.select.InWhereExpectingAnd 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));
}
Also used : InWhereExpectingAnd(com.cadenzauk.siesta.grammar.select.InWhereExpectingAnd) AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) Database(com.cadenzauk.siesta.Database) SalespersonRow(com.cadenzauk.siesta.model.SalespersonRow) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with InWhereExpectingAnd

use of com.cadenzauk.siesta.grammar.select.InWhereExpectingAnd in project siesta by cadenzauk.

the class BetweenBuilderTest method and.

@ParameterizedTest
@MethodSource("argsForAnd")
void and(BiFunction<BetweenBuilder<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");
    BetweenBuilder<String, InWhereExpectingAnd<String>> between = database.from(alias).select(SalespersonRow::firstName, "name").where(SalespersonRow::firstName).isBetween(SalespersonRow::middleNames);
    method.apply(between, alias).list(transaction);
    verify(transaction).query(sql.capture(), args.capture(), rowMapper.capture());
    assertThat(sql.getValue(), is("select s.FIRST_NAME as name from SIESTA.SALESPERSON s where s.FIRST_NAME between s.MIDDLE_NAMES and " + expectedSql));
    assertThat(args.getValue(), is(expectedArgs));
}
Also used : InWhereExpectingAnd(com.cadenzauk.siesta.grammar.select.InWhereExpectingAnd) AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) Database(com.cadenzauk.siesta.Database) SalespersonRow(com.cadenzauk.siesta.model.SalespersonRow) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with InWhereExpectingAnd

use of com.cadenzauk.siesta.grammar.select.InWhereExpectingAnd in project siesta by cadenzauk.

the class ExpressionBuilderTest method isNotInWithNoValuesShouldThrow.

@Test
void isNotInWithNoValuesShouldThrow() {
    Database database = testDatabase(new AnsiDialect());
    ExpressionBuilder<String, InWhereExpectingAnd<SalespersonRow>> select = database.from(SalespersonRow.class).where(SalespersonRow::firstName);
    // noinspection Convert2MethodRef
    calling(() -> select.isNotIn(new String[0])).shouldThrow(IllegalArgumentException.class);
}
Also used : InWhereExpectingAnd(com.cadenzauk.siesta.grammar.select.InWhereExpectingAnd) AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) Database(com.cadenzauk.siesta.Database) SalespersonRow(com.cadenzauk.siesta.model.SalespersonRow) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MockitoTest(com.cadenzauk.core.MockitoTest)

Example 4 with InWhereExpectingAnd

use of com.cadenzauk.siesta.grammar.select.InWhereExpectingAnd in project siesta by cadenzauk.

the class ExpressionBuilderTest method isInWithNoValuesShouldThrow.

@Test
void isInWithNoValuesShouldThrow() {
    Database database = testDatabase(new AnsiDialect());
    ExpressionBuilder<String, InWhereExpectingAnd<SalespersonRow>> select = database.from(SalespersonRow.class).where(SalespersonRow::firstName);
    // noinspection Convert2MethodRef
    calling(() -> select.isIn(new String[0])).shouldThrow(IllegalArgumentException.class);
}
Also used : InWhereExpectingAnd(com.cadenzauk.siesta.grammar.select.InWhereExpectingAnd) AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) Database(com.cadenzauk.siesta.Database) SalespersonRow(com.cadenzauk.siesta.model.SalespersonRow) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MockitoTest(com.cadenzauk.core.MockitoTest)

Aggregations

Database (com.cadenzauk.siesta.Database)4 AnsiDialect (com.cadenzauk.siesta.dialect.AnsiDialect)4 InWhereExpectingAnd (com.cadenzauk.siesta.grammar.select.InWhereExpectingAnd)4 SalespersonRow (com.cadenzauk.siesta.model.SalespersonRow)4 TestDatabase.testDatabase (com.cadenzauk.siesta.model.TestDatabase.testDatabase)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 MockitoTest (com.cadenzauk.core.MockitoTest)2 Test (org.junit.jupiter.api.Test)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2