use of com.cadenzauk.siesta.Database 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()));
}
use of com.cadenzauk.siesta.Database in project siesta by cadenzauk.
the class DatabaseIntegrationTestH2 method embeddedInsertedAndReadBack.
@Test
void embeddedInsertedAndReadBack() {
Database database = testDatabase(dataSource);
long partId = newId();
MoneyAmount purchasePrice = new MoneyAmount(RandomValues.randomBigDecimal(10, 2), "USD");
MoneyAmount retailPrice = new MoneyAmount(RandomValues.randomBigDecimal(10, 2), "NZD");
database.insert(PartRow.newBuilder().partId(partId).description("ABC").widgetId(3L).purchasePrice(purchasePrice).retailPrice(Optional.of(retailPrice)).build());
Tuple5<PartRow, MoneyAmount, MoneyAmount, String, String> result = database.from(PartRow.class).select(PartRow.class).comma(PartRow::purchasePrice, "pp").comma(PartRow::retailPrice, "rp").comma(column(PartRow::purchasePrice).dot(MoneyAmount::currency), "pc").comma(column(PartRow::retailPrice).dot(MoneyAmount::currency), "rc").where(PartRow::partId).isEqualTo(partId).single();
assertThat(result.item1().purchasePrice(), is(purchasePrice));
assertThat(result.item1().retailPrice(), is(Optional.of(retailPrice)));
assertThat(result.item2(), is(purchasePrice));
assertThat(result.item3(), is(retailPrice));
assertThat(result.item4(), is("USD"));
assertThat(result.item5(), is("NZD"));
}
Aggregations