Search in sources :

Example 6 with SalesAreaRow

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

the class ExceptionIntegrationTest method foreignKeyViolationOnDelete.

@Test
void foreignKeyViolationOnDelete() {
    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.delete(SalespersonRow.class).where(SalespersonRow::salespersonId).isEqualTo(salespersonRow.salespersonId()).execute()).shouldThrow(RuntimeSqlException.class).with(subclass(ReferentialIntegrityException.class)).withMessage(startsWith("Foreign key constraint violated while executing 'delete "));
}
Also used : TestDatabase(com.cadenzauk.siesta.model.TestDatabase) SalespersonRow(com.cadenzauk.siesta.model.SalespersonRow) IncorrectSalesAreaRow(com.cadenzauk.siesta.model.IncorrectSalesAreaRow) SalesAreaRow(com.cadenzauk.siesta.model.SalesAreaRow) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with SalesAreaRow

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

the class ExceptionIntegrationTest method numericOverflowOnUpdate.

@Test
void numericOverflowOnUpdate() {
    Database database = TestDatabase.testDatabase(dataSource);
    SalesAreaRow salesArea = SalesAreaRow.newBuilder().salesAreaId(newId()).salesAreaName("NZ").build();
    database.insert(salesArea);
    calling(() -> database.update(SalesAreaRow.class).set(SalesAreaRow::salesCount).to(Integer.MAX_VALUE + 1L).where(SalesAreaRow::salesAreaId).isEqualTo(salesArea.salesAreaId()).execute()).shouldThrow(RuntimeSqlException.class).with(subclass(InvalidValueException.class)).withMessage(startsWith("Incorrect data value for data type while executing 'update "));
}
Also used : TestDatabase(com.cadenzauk.siesta.model.TestDatabase) IncorrectSalesAreaRow(com.cadenzauk.siesta.model.IncorrectSalesAreaRow) SalesAreaRow(com.cadenzauk.siesta.model.SalesAreaRow) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with SalesAreaRow

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

the class ExceptionIntegrationTest method foreignKeyViolationOnInsert.

@Test
void foreignKeyViolationOnInsert() {
    Database database = TestDatabase.testDatabase(dataSource);
    SalesAreaRow salesArea = SalesAreaRow.newBuilder().salesAreaId(newId()).salesAreaName("Far East").salespersonId(Optional.of(newId())).build();
    calling(() -> database.insert(salesArea)).shouldThrow(RuntimeSqlException.class).with(subclass(ReferentialIntegrityException.class)).withMessage(startsWith("Foreign key constraint violated while executing 'insert into "));
}
Also used : TestDatabase(com.cadenzauk.siesta.model.TestDatabase) IncorrectSalesAreaRow(com.cadenzauk.siesta.model.IncorrectSalesAreaRow) SalesAreaRow(com.cadenzauk.siesta.model.SalesAreaRow) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with SalesAreaRow

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

the class ExceptionIntegrationTest method nullNotAllowedOnUpdate.

@Test
void nullNotAllowedOnUpdate() {
    Database database = TestDatabase.testDatabase(dataSource);
    SalesAreaRow salesArea = SalesAreaRow.newBuilder().salesAreaId(newId()).salesAreaName("Oceania").build();
    database.insert(salesArea);
    calling(() -> database.update(SalesAreaRow.class).set(SalesAreaRow::salesAreaName).toNull().where(SalesAreaRow::salesAreaId).isEqualTo(salesArea.salesAreaId()).execute()).shouldThrow(RuntimeSqlException.class).with(subclass(IllegalNullException.class)).withMessage(startsWith("Null value is not allowed while executing 'update "));
}
Also used : TestDatabase(com.cadenzauk.siesta.model.TestDatabase) IncorrectSalesAreaRow(com.cadenzauk.siesta.model.IncorrectSalesAreaRow) SalesAreaRow(com.cadenzauk.siesta.model.SalesAreaRow) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with SalesAreaRow

use of com.cadenzauk.siesta.model.SalesAreaRow 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 "));
}
Also used : TestDatabase(com.cadenzauk.siesta.model.TestDatabase) SalespersonRow(com.cadenzauk.siesta.model.SalespersonRow) IncorrectSalesAreaRow(com.cadenzauk.siesta.model.IncorrectSalesAreaRow) SalesAreaRow(com.cadenzauk.siesta.model.SalesAreaRow) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

IncorrectSalesAreaRow (com.cadenzauk.siesta.model.IncorrectSalesAreaRow)12 SalesAreaRow (com.cadenzauk.siesta.model.SalesAreaRow)12 TestDatabase (com.cadenzauk.siesta.model.TestDatabase)12 Test (org.junit.jupiter.api.Test)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 CompositeAutoCloseable (com.cadenzauk.core.lang.CompositeAutoCloseable)3 SalespersonRow (com.cadenzauk.siesta.model.SalespersonRow)2