Search in sources :

Example 1 with TestTransactionFactory

use of org.mule.tck.testmodels.mule.TestTransactionFactory in project mule by mulesoft.

the class TransactionalExecutionTemplateTestCase method testActionAlwaysBeginAndSuspendXaTxAndCommitNewTx.

@Test
public void testActionAlwaysBeginAndSuspendXaTxAndCommitNewTx() throws Exception {
    TransactionCoordination.getInstance().bindTransaction(mockTransaction);
    mockTransaction.setXA(true);
    MuleTransactionConfig config = new MuleTransactionConfig(TransactionConfig.ACTION_ALWAYS_BEGIN);
    ExecutionTemplate executionTemplate = createExecutionTemplate(config);
    config.setFactory(new TestTransactionFactory(mockNewTransaction));
    Object result = executionTemplate.execute(getEmptyTransactionCallback());
    assertThat(result, is(RETURN_VALUE));
    verify(mockNewTransaction).commit();
    verify(mockNewTransaction, never()).rollback();
    verify(mockTransaction).suspend();
    verify(mockTransaction).resume();
    verify(mockTransaction, never()).commit();
    verify(mockTransaction, never()).rollback();
    assertThat((TestTransaction) TransactionCoordination.getInstance().getTransaction(), is(mockTransaction));
}
Also used : TestTransactionFactory(org.mule.tck.testmodels.mule.TestTransactionFactory) MuleTransactionConfig(org.mule.runtime.core.api.transaction.MuleTransactionConfig) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 2 with TestTransactionFactory

use of org.mule.tck.testmodels.mule.TestTransactionFactory in project mule by mulesoft.

the class TransactionalExecutionTemplateTestCase method testActionAlwaysBeginAndRollbackTxAndCommitNewTx.

@Test(expected = IllegalTransactionStateException.class)
public void testActionAlwaysBeginAndRollbackTxAndCommitNewTx() throws Exception {
    TransactionCoordination.getInstance().bindTransaction(mockTransaction);
    when(mockTransaction.isRollbackOnly()).thenReturn(true);
    MuleTransactionConfig config = new MuleTransactionConfig(TransactionConfig.ACTION_ALWAYS_BEGIN);
    ExecutionTemplate executionTemplate = createExecutionTemplate(config);
    config.setFactory(new TestTransactionFactory(mockNewTransaction));
    Object result = executionTemplate.execute(getEmptyTransactionCallback());
    assertThat(result, is(RETURN_VALUE));
    verify(mockTransaction).rollback();
    verify(mockNewTransaction).commit();
    verify(mockTransaction, never()).commit();
    verify(mockNewTransaction, never()).rollback();
    assertThat(TransactionCoordination.getInstance().getTransaction(), IsNull.<Object>nullValue());
}
Also used : TestTransactionFactory(org.mule.tck.testmodels.mule.TestTransactionFactory) MuleTransactionConfig(org.mule.runtime.core.api.transaction.MuleTransactionConfig) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 3 with TestTransactionFactory

use of org.mule.tck.testmodels.mule.TestTransactionFactory in project mule by mulesoft.

the class TransactionalExecutionTemplateTestCase method testActionAlwaysBeginAndSuspendXaTxAndRollbackNewTx.

@Test
public void testActionAlwaysBeginAndSuspendXaTxAndRollbackNewTx() throws Exception {
    TransactionCoordination.getInstance().bindTransaction(mockTransaction);
    mockTransaction.setXA(true);
    when(mockTransaction.isRollbackOnly()).thenReturn(true);
    MuleTransactionConfig config = new MuleTransactionConfig(TransactionConfig.ACTION_ALWAYS_BEGIN);
    ExecutionTemplate executionTemplate = createExecutionTemplate(config);
    config.setFactory(new TestTransactionFactory(mockNewTransaction));
    Object result = executionTemplate.execute(getRollbackTransactionCallback());
    assertThat(result, is(RETURN_VALUE));
    verify(mockNewTransaction).rollback();
    verify(mockNewTransaction, never()).commit();
    verify(mockTransaction).suspend();
    verify(mockTransaction).resume();
    verify(mockTransaction, never()).commit();
    verify(mockTransaction, never()).rollback();
    assertThat((TestTransaction) TransactionCoordination.getInstance().getTransaction(), is(mockTransaction));
}
Also used : TestTransactionFactory(org.mule.tck.testmodels.mule.TestTransactionFactory) MuleTransactionConfig(org.mule.runtime.core.api.transaction.MuleTransactionConfig) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 4 with TestTransactionFactory

use of org.mule.tck.testmodels.mule.TestTransactionFactory in project mule by mulesoft.

the class TransactionalExecutionTemplateTestCase method testActionAlwaysBeginAndRollbackTxAndRollbackNewTx.

@Test(expected = IllegalTransactionStateException.class)
public void testActionAlwaysBeginAndRollbackTxAndRollbackNewTx() throws Exception {
    TransactionCoordination.getInstance().bindTransaction(mockTransaction);
    when(mockTransaction.isRollbackOnly()).thenReturn(true);
    MuleTransactionConfig config = new MuleTransactionConfig(TransactionConfig.ACTION_ALWAYS_BEGIN);
    ExecutionTemplate executionTemplate = createExecutionTemplate(config);
    config.setFactory(new TestTransactionFactory(mockNewTransaction));
    Object result = executionTemplate.execute(getRollbackTransactionCallback());
    assertThat(result, is(RETURN_VALUE));
    verify(mockTransaction).rollback();
    verify(mockNewTransaction).rollback();
    verify(mockTransaction, never()).commit();
    verify(mockNewTransaction, never()).commit();
    assertThat(TransactionCoordination.getInstance().getTransaction(), IsNull.<Object>nullValue());
}
Also used : TestTransactionFactory(org.mule.tck.testmodels.mule.TestTransactionFactory) MuleTransactionConfig(org.mule.runtime.core.api.transaction.MuleTransactionConfig) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 5 with TestTransactionFactory

use of org.mule.tck.testmodels.mule.TestTransactionFactory in project mule by mulesoft.

the class MuleTransactionConfigTestCase method testTransactionJoinIfPossible.

@Test
public void testTransactionJoinIfPossible() throws TransactionException {
    MuleTransactionConfig txConfig = new MuleTransactionConfig(TransactionConfig.ACTION_JOIN_IF_POSSIBLE);
    txConfig.setMuleContext(muleContext);
    txConfig.setFactory(new TestTransactionFactory());
    assertFalse(txConfig.isTransacted());
}
Also used : TestTransactionFactory(org.mule.tck.testmodels.mule.TestTransactionFactory) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 TestTransactionFactory (org.mule.tck.testmodels.mule.TestTransactionFactory)8 MuleTransactionConfig (org.mule.runtime.core.api.transaction.MuleTransactionConfig)7 SmallTest (org.mule.tck.size.SmallTest)7