Search in sources :

Example 1 with NotSupportedException

use of jakarta.transaction.NotSupportedException in project spring-framework by spring-projects.

the class JtaTransactionManagerTests method jtaTransactionManagerWithNotSupportedExceptionOnNestedBegin.

@Test
public void jtaTransactionManagerWithNotSupportedExceptionOnNestedBegin() throws Exception {
    UserTransaction ut = mock(UserTransaction.class);
    given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
    willThrow(new NotSupportedException("not supported")).given(ut).begin();
    assertThatExceptionOfType(NestedTransactionNotSupportedException.class).isThrownBy(() -> {
        JtaTransactionManager ptm = newJtaTransactionManager(ut);
        TransactionTemplate tt = new TransactionTemplate(ptm);
        tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_NESTED);
        tt.execute(new TransactionCallbackWithoutResult() {

            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
            // something transactional
            }
        });
    });
}
Also used : UserTransaction(jakarta.transaction.UserTransaction) JtaTransactionManager(org.springframework.transaction.jta.JtaTransactionManager) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) NotSupportedException(jakarta.transaction.NotSupportedException) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Test(org.junit.jupiter.api.Test)

Aggregations

NotSupportedException (jakarta.transaction.NotSupportedException)1 UserTransaction (jakarta.transaction.UserTransaction)1 Test (org.junit.jupiter.api.Test)1 JtaTransactionManager (org.springframework.transaction.jta.JtaTransactionManager)1 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)1 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)1