Search in sources :

Example 1 with SalesAreaRow

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

the class ExceptionIntegrationTest method lockTimeoutOnDelete.

@Test
void lockTimeoutOnDelete() {
    assumeTrue(dialect.supportsLockTimeout(), "Database does not support lock timeouts.");
    Database database = TestDatabase.testDatabase(dataSource);
    SalesAreaRow salesArea = SalesAreaRow.newBuilder().salesAreaId(newId()).salesAreaName("NZ").build();
    database.insert(salesArea);
    try (CompositeAutoCloseable closer = new CompositeAutoCloseable()) {
        Transaction transaction1 = closer.add(database.beginTransaction());
        database.update(SalesAreaRow.class).set(SalesAreaRow::salesCount).to(10L).where(SalesAreaRow::salesAreaId).isEqualTo(salesArea.salesAreaId()).execute(transaction1);
        Transaction transaction2 = closer.add(database.beginTransaction());
        closer.add(database.withLockTimeout(transaction2, 0, TimeUnit.MILLISECONDS));
        calling(() -> database.delete(SalesAreaRow.class).where(SalesAreaRow::salesAreaId).isEqualTo(salesArea.salesAreaId()).execute(transaction2)).shouldThrow(RuntimeSqlException.class).with(subclass(LockingException.class)).withMessage(startsWith("Locking failure while executing 'delete "));
        transaction2.rollback();
    }
}
Also used : CompositeAutoCloseable(com.cadenzauk.core.lang.CompositeAutoCloseable) 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 2 with SalesAreaRow

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

the class ExceptionIntegrationTest method stringValueTooLongOnUpdate.

@Test
void stringValueTooLongOnUpdate() {
    Database database = TestDatabase.testDatabase(dataSource);
    SalesAreaRow salesArea = SalesAreaRow.newBuilder().salesAreaId(newId()).salesAreaName("NZ").build();
    database.insert(salesArea);
    calling(() -> database.update(SalesAreaRow.class).set(SalesAreaRow::salesAreaName).to("Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu").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 3 with SalesAreaRow

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

the class ExceptionIntegrationTest method lockTimeoutOnUpdate.

@Test
void lockTimeoutOnUpdate() {
    assumeTrue(dialect.supportsLockTimeout(), "Database does not support lock timeouts.");
    Database database = TestDatabase.testDatabase(dataSource);
    SalesAreaRow salesArea = SalesAreaRow.newBuilder().salesAreaId(newId()).salesAreaName("NZ").build();
    database.insert(salesArea);
    try (CompositeAutoCloseable closer = new CompositeAutoCloseable()) {
        Transaction transaction1 = closer.add(database.beginTransaction());
        database.update(SalesAreaRow.class).set(SalesAreaRow::salesCount).to(10L).where(SalesAreaRow::salesAreaId).isEqualTo(salesArea.salesAreaId()).execute(transaction1);
        Transaction transaction2 = closer.add(database.beginTransaction());
        closer.add(database.withLockTimeout(transaction2, 0, TimeUnit.MILLISECONDS));
        calling(() -> database.update(SalesAreaRow.class).set(SalesAreaRow::salesCount).to(1L).where(SalesAreaRow::salesAreaId).isEqualTo(salesArea.salesAreaId()).execute(transaction2)).shouldThrow(RuntimeSqlException.class).with(subclass(LockingException.class)).withMessage(startsWith("Locking failure while executing 'update "));
        transaction2.rollback();
    }
}
Also used : CompositeAutoCloseable(com.cadenzauk.core.lang.CompositeAutoCloseable) 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 4 with SalesAreaRow

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

the class ExceptionIntegrationTest method nullNotAllowedOnInsert.

@Test
void nullNotAllowedOnInsert() {
    Database database = TestDatabase.testDatabase(dataSource);
    SalesAreaRow salesArea = SalesAreaRow.newBuilder().salesAreaId(newId()).build();
    calling(() -> database.insert(salesArea)).shouldThrow(RuntimeSqlException.class).with(subclass(IllegalNullException.class)).withMessage(startsWith("Null value is not allowed 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 5 with SalesAreaRow

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

the class ExceptionIntegrationTest method stringValueTooLongOnInsert.

@Test
void stringValueTooLongOnInsert() {
    Database database = TestDatabase.testDatabase(dataSource);
    SalesAreaRow salesArea = SalesAreaRow.newBuilder().salesAreaId(newId()).salesAreaName("Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu").build();
    calling(() -> database.insert(salesArea)).shouldThrow(RuntimeSqlException.class).with(subclass(InvalidValueException.class)).withMessage(startsWith("Incorrect data value for data type 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)

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