use of com.cadenzauk.siesta.model.SalespersonRow in project siesta by cadenzauk.
the class ExceptionIntegrationTest method foreignKeyViolationOnUpdate.
@Test
void foreignKeyViolationOnUpdate() {
Database database = TestDatabase.testDatabase(dataSource);
SalespersonRow salespersonRow = aRandomSalesperson();
database.insert(salespersonRow);
SalesAreaRow salesArea = SalesAreaRow.newBuilder().salesAreaId(newId()).salesAreaName("Far East").salespersonId(Optional.of(salespersonRow.salespersonId())).build();
database.insert(salesArea);
calling(() -> database.update(SalesAreaRow.class).set(SalesAreaRow::salespersonId).to(newId()).where(SalesAreaRow::salesAreaId).isEqualTo(salesArea.salesAreaId()).execute()).shouldThrow(RuntimeSqlException.class).with(subclass(ReferentialIntegrityException.class)).withMessage(startsWith("Foreign key constraint violated while executing 'update "));
}
use of com.cadenzauk.siesta.model.SalespersonRow in project siesta by cadenzauk.
the class ExceptionIntegrationTest method uniqueConstraintViolationOnInsert.
@Test
void uniqueConstraintViolationOnInsert() {
Database database = TestDatabase.testDatabase(dataSource);
SalespersonRow salespersonRow = aRandomSalesperson();
calling(() -> database.insert(salespersonRow, salespersonRow)).shouldThrow(RuntimeSqlException.class).with(subclass(DuplicateKeyException.class)).withMessage(startsWith("Unique constraint violated while executing 'insert into "));
}
use of com.cadenzauk.siesta.model.SalespersonRow in project siesta by cadenzauk.
the class TransactionIntegrationTest method whenUncommittedThenVisibleWithinTransaction.
@Test
void whenUncommittedThenVisibleWithinTransaction() {
Database database = testDatabase(dataSource, dialect);
SalespersonRow salesperson = aRandomSalesperson();
try (Transaction transaction = database.beginTransaction()) {
database.insert(transaction, salesperson);
Integer count = database.from(SalespersonRow.class).select(count()).where(SalespersonRow::salespersonId).isEqualTo(salesperson.salespersonId()).fetchFirst(1).withIsolation(IsolationLevel.UNCOMMITTED_READ).singleAsync(transaction).join();
assertThat(count, is(1));
}
}
use of com.cadenzauk.siesta.model.SalespersonRow in project siesta by cadenzauk.
the class BetweenBuilderTest method and.
@ParameterizedTest
@MethodSource("argsForAnd")
void and(BiFunction<BetweenBuilder<String, InWhereExpectingAnd<String>>, Alias<SalespersonRow>, InWhereExpectingAnd<String>> method, String expectedSql, Object[] expectedArgs) {
MockitoAnnotations.initMocks(this);
Database database = testDatabase(new AnsiDialect());
Alias<SalespersonRow> alias = database.table(SalespersonRow.class).as("s");
BetweenBuilder<String, InWhereExpectingAnd<String>> between = database.from(alias).select(SalespersonRow::firstName, "name").where(SalespersonRow::firstName).isBetween(SalespersonRow::middleNames);
method.apply(between, alias).list(transaction);
verify(transaction).query(sql.capture(), args.capture(), rowMapper.capture());
assertThat(sql.getValue(), is("select s.FIRST_NAME as name from SIESTA.SALESPERSON s where s.FIRST_NAME between s.MIDDLE_NAMES and " + expectedSql));
assertThat(args.getValue(), is(expectedArgs));
}
use of com.cadenzauk.siesta.model.SalespersonRow in project siesta by cadenzauk.
the class ExpressionBuilderTest method isNotInWithNoValuesShouldThrow.
@Test
void isNotInWithNoValuesShouldThrow() {
Database database = testDatabase(new AnsiDialect());
ExpressionBuilder<String, InWhereExpectingAnd<SalespersonRow>> select = database.from(SalespersonRow.class).where(SalespersonRow::firstName);
// noinspection Convert2MethodRef
calling(() -> select.isNotIn(new String[0])).shouldThrow(IllegalArgumentException.class);
}
Aggregations