Search in sources :

Example 16 with SalespersonRow

use of com.cadenzauk.siesta.model.SalespersonRow in project siesta by cadenzauk.

the class ExpectingSelectTest method testSelect.

@ParameterizedTest
@MethodSource("argsForSelect")
void testSelect(BiFunction<ExpectingSelect<SalespersonRow>, Alias<SalespersonRow>, Select<?>> method, String expectedSql) {
    MockitoAnnotations.initMocks(this);
    Database database = testDatabase(new AnsiDialect());
    Alias<SalespersonRow> alias = database.table(SalespersonRow.class).as("s");
    method.apply(database.from(alias), alias).list(transaction);
    verify(transaction).query(sql.capture(), args.capture(), rowMapper.capture());
    assertThat(sql.getValue(), is("select " + expectedSql + " from SIESTA.SALESPERSON s"));
    assertThat(args.getValue(), arrayWithSize(0));
}
Also used : 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 17 with SalespersonRow

use of com.cadenzauk.siesta.model.SalespersonRow in project siesta by cadenzauk.

the class InProjectionExpectingCommaTest method testComma.

@ParameterizedTest
@MethodSource("argsForComma")
void testComma(BiFunction<InProjectionExpectingComma1<String>, Alias<SalespersonRow>, Select<?>> method, String expectedSql, Object[] expectedArgs) {
    MockitoAnnotations.initMocks(this);
    Database database = testDatabase(new AnsiDialect());
    Alias<SalespersonRow> alias = database.table(SalespersonRow.class).as("s");
    InProjectionExpectingComma1<String> sut = database.from(alias).select(SalespersonRow::firstName, "name");
    method.apply(sut, alias).list(transaction);
    verify(transaction).query(sql.capture(), args.capture(), rowMapper.capture());
    Pattern pattern = Pattern.compile("select s.FIRST_NAME as name, " + expectedSql + " from SIESTA.SALESPERSON s");
    assertThat(pattern.matcher(sql.getValue()).matches(), is(true));
    assertThat(args.getValue(), is(expectedArgs));
}
Also used : Pattern(java.util.regex.Pattern) 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 18 with SalespersonRow

use of com.cadenzauk.siesta.model.SalespersonRow in project siesta by cadenzauk.

the class DatabaseIntegrationTestH2 method ormDelete.

@Test
void ormDelete() {
    Database database = testDatabase(dataSource);
    SalespersonRow salespersonRow = aRandomSalesperson();
    database.insert(salespersonRow);
    int count = countOf(database, salespersonRow);
    assertThat(count, is(1));
    database.delete(salespersonRow);
    count = countOf(database, salespersonRow);
    assertThat(count, is(0));
}
Also used : TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) Database(com.cadenzauk.siesta.Database) SalespersonRow(com.cadenzauk.siesta.model.SalespersonRow) DatabaseIntegrationTest(com.cadenzauk.siesta.DatabaseIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 19 with SalespersonRow

use of com.cadenzauk.siesta.model.SalespersonRow in project siesta by cadenzauk.

the class BooleanExpressionTest method testAnd.

@ParameterizedTest
@MethodSource("argsForAnd")
void testAnd(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).appendAnd(appendArg.capture());
    assertThat(appendArg.getValue().sql(scope), is(expectedSql));
}
Also used : AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) Scope(com.cadenzauk.siesta.Scope) 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 20 with SalespersonRow

use of com.cadenzauk.siesta.model.SalespersonRow 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));
}
Also used : AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) Scope(com.cadenzauk.siesta.Scope) 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)

Aggregations

SalespersonRow (com.cadenzauk.siesta.model.SalespersonRow)39 Test (org.junit.jupiter.api.Test)31 TestDatabase.testDatabase (com.cadenzauk.siesta.model.TestDatabase.testDatabase)27 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 Database (com.cadenzauk.siesta.Database)12 AnsiDialect (com.cadenzauk.siesta.dialect.AnsiDialect)10 MockitoTest (com.cadenzauk.core.MockitoTest)8 MethodSource (org.junit.jupiter.params.provider.MethodSource)8 TestDatabase (com.cadenzauk.siesta.model.TestDatabase)6 InWhereExpectingAnd (com.cadenzauk.siesta.grammar.select.InWhereExpectingAnd)4 Tuple3 (com.cadenzauk.core.tuple.Tuple3)3 Scope (com.cadenzauk.siesta.Scope)3 DatabaseIntegrationTest (com.cadenzauk.siesta.DatabaseIntegrationTest)2 IncorrectSalesAreaRow (com.cadenzauk.siesta.model.IncorrectSalesAreaRow)2 SalesAreaRow (com.cadenzauk.siesta.model.SalesAreaRow)2 LockingException (com.cadenzauk.core.sql.exception.LockingException)1 Tuple2 (com.cadenzauk.core.tuple.Tuple2)1 H2Dialect (com.cadenzauk.siesta.dialect.H2Dialect)1 Objects (java.util.Objects)1 CompletableFuture (java.util.concurrent.CompletableFuture)1