Search in sources :

Example 1 with SalespersonRow

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

the class DatabaseTest method update.

@Test
void update() {
    Database database = Database.newBuilder().defaultSqlExecutor(sqlExecutor).build();
    SalespersonRow salesperson = IntegrationTest.aRandomSalesperson();
    database.update(salesperson);
    verify(sqlExecutor).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)

Example 2 with SalespersonRow

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

the class DatabaseTest method updateSqlExecutor.

@Test
void updateSqlExecutor() {
    Database database = Database.newBuilder().build();
    SalespersonRow salesperson = IntegrationTest.aRandomSalesperson();
    database.update(sqlExecutor, salesperson);
    verify(sqlExecutor).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)

Example 3 with SalespersonRow

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

the class DatabaseTest method delete.

@Test
void delete() {
    Database database = Database.newBuilder().defaultSqlExecutor(sqlExecutor).build();
    SalespersonRow salesperson = IntegrationTest.aRandomSalesperson();
    database.delete(salesperson);
    verify(sqlExecutor).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 4 with SalespersonRow

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

the class DatabaseTest method deleteSqlExecutor.

@Test
void deleteSqlExecutor() {
    Database database = Database.newBuilder().build();
    SalespersonRow salesperson = IntegrationTest.aRandomSalesperson();
    database.delete(sqlExecutor, salesperson);
    verify(sqlExecutor).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 5 with SalespersonRow

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

the class DatabaseIntegrationTest method olapWithoutPartitionOrOrder.

@Test
void olapWithoutPartitionOrOrder() {
    assumeFalse(dialect.requiresOrderByInRowNumber(), dialect.getClass().getSimpleName() + " does not support row_number() without ORDER BY.");
    Database database = testDatabase(dataSource, dialect);
    Tuple2<Long, Long> inserted = insertSalespeople(database, 5);
    List<Tuple2<Long, Integer>> result = database.from(SalespersonRow.class).select(SalespersonRow::salespersonId).comma(Olap.rowNumber()).where(SalespersonRow::salespersonId).isBetween(inserted.item1()).and(inserted.item2()).orderBy(SalespersonRow::salespersonId).list();
    assertThat(result, hasSize(5));
    assertThat(result.get(0), is(Tuple.of(inserted.item1(), 1)));
    assertThat(result.get(4), is(Tuple.of(inserted.item2(), 5)));
}
Also used : Tuple2(com.cadenzauk.core.tuple.Tuple2) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) SalespersonRow(com.cadenzauk.siesta.model.SalespersonRow) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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