Search in sources :

Example 1 with Transaction

use of com.cadenzauk.siesta.Transaction in project siesta by cadenzauk.

the class UpdateTest method update.

@Test
void update() {
    Database database = Database.newBuilder().defaultSchema("SIESTA").table(WidgetRow.class, t -> t.builder(WidgetRow.Builder::build)).build();
    database.update(WidgetRow.class, "w").set(WidgetRow::name).to("Fred").set(WidgetRow::description).to(Optional.of("Bob")).where(WidgetRow::widgetId).isEqualTo(1L).and(column(WidgetRow::description).isBetween("A").and("w", WidgetRow::name).or(column(WidgetRow::description).isNull())).execute(transaction);
    verify(transaction).update(sql.capture(), args.capture());
    assertThat(sql.getValue(), is("update SIESTA.WIDGET w " + "set NAME = ?, " + "DESCRIPTION = ? " + "where w.WIDGET_ID = ? " + "and (" + "w.DESCRIPTION between ? and w.NAME " + "or w.DESCRIPTION is null" + ")"));
    assertThat(args.getValue(), is(toArray("Fred", "Bob", 1L, "A")));
}
Also used : Mock(org.mockito.Mock) Captor(org.mockito.Captor) TypedExpression.column(com.cadenzauk.siesta.grammar.expression.TypedExpression.column) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) ArgumentCaptor(org.mockito.ArgumentCaptor) ArrayUtils.toArray(org.apache.commons.lang3.ArrayUtils.toArray) MockitoTest(com.cadenzauk.core.MockitoTest) Transaction(com.cadenzauk.siesta.Transaction) WidgetRow(com.cadenzauk.siesta.model.WidgetRow) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Database(com.cadenzauk.siesta.Database) WidgetRow(com.cadenzauk.siesta.model.WidgetRow) Database(com.cadenzauk.siesta.Database) Test(org.junit.jupiter.api.Test) MockitoTest(com.cadenzauk.core.MockitoTest)

Aggregations

MockitoTest (com.cadenzauk.core.MockitoTest)1 Database (com.cadenzauk.siesta.Database)1 Transaction (com.cadenzauk.siesta.Transaction)1 TypedExpression.column (com.cadenzauk.siesta.grammar.expression.TypedExpression.column)1 WidgetRow (com.cadenzauk.siesta.model.WidgetRow)1 Optional (java.util.Optional)1 ArrayUtils.toArray (org.apache.commons.lang3.ArrayUtils.toArray)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Matchers.is (org.hamcrest.Matchers.is)1 Test (org.junit.jupiter.api.Test)1 ArgumentCaptor (org.mockito.ArgumentCaptor)1 Captor (org.mockito.Captor)1 Mock (org.mockito.Mock)1 Mockito.verify (org.mockito.Mockito.verify)1