Search in sources :

Example 1 with MockCallbackPreferringTransactionManager

use of cn.taketoday.transaction.MockCallbackPreferringTransactionManager in project today-infrastructure by TAKETODAY.

the class AbstractTransactionAspectTests method transactionExceptionPropagatedWithCallbackPreference.

@Test
public void transactionExceptionPropagatedWithCallbackPreference() throws Throwable {
    TransactionAttribute txatt = new DefaultTransactionAttribute();
    MapTransactionAttributeSource tas = new MapTransactionAttributeSource();
    tas.register(exceptionalMethod, txatt);
    MockCallbackPreferringTransactionManager ptm = new MockCallbackPreferringTransactionManager();
    TestBean tb = new TestBean();
    ITestBean itb = (ITestBean) advised(tb, ptm, tas);
    checkTransactionStatus(false);
    assertThatExceptionOfType(OptimisticLockingFailureException.class).isThrownBy(() -> itb.exceptional(new OptimisticLockingFailureException("")));
    checkTransactionStatus(false);
    assertThat(ptm.getDefinition()).isSameAs(txatt);
    assertThat(ptm.getStatus().isRollbackOnly()).isFalse();
}
Also used : ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) OptimisticLockingFailureException(cn.taketoday.dao.OptimisticLockingFailureException) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) MockCallbackPreferringTransactionManager(cn.taketoday.transaction.MockCallbackPreferringTransactionManager) Test(org.junit.jupiter.api.Test)

Example 2 with MockCallbackPreferringTransactionManager

use of cn.taketoday.transaction.MockCallbackPreferringTransactionManager in project today-framework by TAKETODAY.

the class AbstractTransactionAspectTests method transactionShouldSucceedWithCallbackPreference.

/**
 * Check that a transaction is created and committed using
 * CallbackPreferringPlatformTransactionManager.
 */
@Test
public void transactionShouldSucceedWithCallbackPreference() throws Exception {
    TransactionAttribute txatt = new DefaultTransactionAttribute();
    MapTransactionAttributeSource tas = new MapTransactionAttributeSource();
    tas.register(getNameMethod, txatt);
    MockCallbackPreferringTransactionManager ptm = new MockCallbackPreferringTransactionManager();
    TestBean tb = new TestBean();
    ITestBean itb = (ITestBean) advised(tb, ptm, tas);
    checkTransactionStatus(false);
    itb.getName();
    checkTransactionStatus(false);
    assertThat(ptm.getDefinition()).isSameAs(txatt);
    assertThat(ptm.getStatus().isRollbackOnly()).isFalse();
}
Also used : ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) MockCallbackPreferringTransactionManager(cn.taketoday.transaction.MockCallbackPreferringTransactionManager) Test(org.junit.jupiter.api.Test)

Example 3 with MockCallbackPreferringTransactionManager

use of cn.taketoday.transaction.MockCallbackPreferringTransactionManager in project today-framework by TAKETODAY.

the class AbstractTransactionAspectTests method transactionExceptionPropagatedWithCallbackPreference.

@Test
public void transactionExceptionPropagatedWithCallbackPreference() throws Throwable {
    TransactionAttribute txatt = new DefaultTransactionAttribute();
    MapTransactionAttributeSource tas = new MapTransactionAttributeSource();
    tas.register(exceptionalMethod, txatt);
    MockCallbackPreferringTransactionManager ptm = new MockCallbackPreferringTransactionManager();
    TestBean tb = new TestBean();
    ITestBean itb = (ITestBean) advised(tb, ptm, tas);
    checkTransactionStatus(false);
    assertThatExceptionOfType(OptimisticLockingFailureException.class).isThrownBy(() -> itb.exceptional(new OptimisticLockingFailureException("")));
    checkTransactionStatus(false);
    assertThat(ptm.getDefinition()).isSameAs(txatt);
    assertThat(ptm.getStatus().isRollbackOnly()).isFalse();
}
Also used : ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) OptimisticLockingFailureException(cn.taketoday.dao.OptimisticLockingFailureException) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) MockCallbackPreferringTransactionManager(cn.taketoday.transaction.MockCallbackPreferringTransactionManager) Test(org.junit.jupiter.api.Test)

Example 4 with MockCallbackPreferringTransactionManager

use of cn.taketoday.transaction.MockCallbackPreferringTransactionManager in project today-infrastructure by TAKETODAY.

the class AbstractTransactionAspectTests method transactionShouldSucceedWithCallbackPreference.

/**
 * Check that a transaction is created and committed using
 * CallbackPreferringPlatformTransactionManager.
 */
@Test
public void transactionShouldSucceedWithCallbackPreference() throws Exception {
    TransactionAttribute txatt = new DefaultTransactionAttribute();
    MapTransactionAttributeSource tas = new MapTransactionAttributeSource();
    tas.register(getNameMethod, txatt);
    MockCallbackPreferringTransactionManager ptm = new MockCallbackPreferringTransactionManager();
    TestBean tb = new TestBean();
    ITestBean itb = (ITestBean) advised(tb, ptm, tas);
    checkTransactionStatus(false);
    itb.getName();
    checkTransactionStatus(false);
    assertThat(ptm.getDefinition()).isSameAs(txatt);
    assertThat(ptm.getStatus().isRollbackOnly()).isFalse();
}
Also used : ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) MockCallbackPreferringTransactionManager(cn.taketoday.transaction.MockCallbackPreferringTransactionManager) Test(org.junit.jupiter.api.Test)

Aggregations

ITestBean (cn.taketoday.beans.testfixture.beans.ITestBean)4 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)4 MockCallbackPreferringTransactionManager (cn.taketoday.transaction.MockCallbackPreferringTransactionManager)4 Test (org.junit.jupiter.api.Test)4 OptimisticLockingFailureException (cn.taketoday.dao.OptimisticLockingFailureException)2