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));
}
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());
}
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));
}
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());
}
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());
}
Aggregations