Search in sources :

Example 36 with SalespersonRow

use of com.cadenzauk.siesta.model.SalespersonRow 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)

Example 37 with SalespersonRow

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

the class DatabaseIntegrationTestH2 method ormUpdate.

@Test
void ormUpdate() {
    Database database = testDatabase(dataSource);
    SalespersonRow salespersonRow = aRandomSalesperson();
    SalespersonRow updated = SalespersonRow.newBuilder(salespersonRow).numberOfSales(salespersonRow.numberOfSales() + 10).build();
    database.insert(salespersonRow);
    database.update(updated);
    Integer valueInDatabase = database.from(SalespersonRow.class).select(SalespersonRow::numberOfSales).where(SalespersonRow::salespersonId).isEqualTo(salespersonRow.salespersonId()).single();
    assertThat(valueInDatabase, is(updated.numberOfSales()));
}
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 38 with SalespersonRow

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

the class DatabaseTest method deleteTransaction.

@Test
void deleteTransaction() {
    Database database = Database.newBuilder().build();
    SalespersonRow salesperson = IntegrationTest.aRandomSalesperson();
    database.delete(transaction, salesperson);
    verify(transaction).update(sqlCaptor.capture(), argCaptor.capture());
    assertThat(sqlCaptor.getValue(), is("delete from SIESTA.SALESPERSON " + "where SIESTA.SALESPERSON.SALESPERSON_ID = ?"));
    assertThat(argCaptor.getValue(), arrayContaining(salesperson.salespersonId()));
}
Also used : SalespersonRow(com.cadenzauk.siesta.model.SalespersonRow) Test(org.junit.jupiter.api.Test) MockitoTest(com.cadenzauk.core.MockitoTest)

Example 39 with SalespersonRow

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

the class DatabaseTest method updateTransaction.

@Test
void updateTransaction() {
    Database database = Database.newBuilder().build();
    SalespersonRow salesperson = IntegrationTest.aRandomSalesperson();
    database.update(transaction, salesperson);
    verify(transaction).update(sqlCaptor.capture(), argCaptor.capture());
    assertThat(sqlCaptor.getValue(), is("update SIESTA.SALESPERSON " + "set FIRST_NAME = ?, MIDDLE_NAMES = ?, SURNAME = ?, NUMBER_OF_SALES = ?, COMMISSION = ? " + "where SIESTA.SALESPERSON.SALESPERSON_ID = ?"));
    assertThat(argCaptor.getValue(), arrayContaining(salesperson.firstName(), salesperson.middleNames().orElse(null), salesperson.surname(), salesperson.numberOfSales(), salesperson.commission().orElse(null), salesperson.salespersonId()));
}
Also used : SalespersonRow(com.cadenzauk.siesta.model.SalespersonRow) Test(org.junit.jupiter.api.Test) MockitoTest(com.cadenzauk.core.MockitoTest)

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