use of org.mule.runtime.core.api.transaction.MuleTransactionConfig in project mule by mulesoft.
the class TransactionalExecutionTemplateTestCase method testActionNoneAndTxForRollback.
@Test
public void testActionNoneAndTxForRollback() throws Exception {
when(mockTransaction.isRollbackOnly()).thenReturn(true);
TransactionCoordination.getInstance().bindTransaction(mockTransaction);
MuleTransactionConfig config = new MuleTransactionConfig(TransactionConfig.ACTION_NONE);
ExecutionTemplate executionTemplate = createExecutionTemplate(config);
Object result = executionTemplate.execute(getEmptyTransactionCallback());
assertThat(result, is(RETURN_VALUE));
verify(mockTransaction, never()).commit();
verify(mockTransaction, never()).rollback();
}
use of org.mule.runtime.core.api.transaction.MuleTransactionConfig in project mule by mulesoft.
the class TransactionalExecutionTemplateTestCase method testActionNoneAndWithExternalTransactionWithTx.
@Test
public void testActionNoneAndWithExternalTransactionWithTx() throws Exception {
TransactionCoordination.getInstance().bindTransaction(mockTransaction);
MuleTransactionConfig config = new MuleTransactionConfig(TransactionConfig.ACTION_NONE);
config.setInteractWithExternal(true);
mockExternalTransactionFactory = mock(ExternalTransactionAwareTransactionFactory.class);
config.setFactory(mockExternalTransactionFactory);
Transaction externalTransaction = mock(Transaction.class);
when(mockExternalTransactionFactory.joinExternalTransaction(mockMuleContext)).thenReturn(externalTransaction);
ExecutionTemplate executionTemplate = createExecutionTemplate(config);
Object result = executionTemplate.execute(getEmptyTransactionCallback());
assertThat(result, is(RETURN_VALUE));
verify(mockTransaction, never()).rollback();
verify(mockTransaction, never()).commit();
assertThat(TransactionCoordination.getInstance().getTransaction(), IsNull.<Object>notNullValue());
}
use of org.mule.runtime.core.api.transaction.MuleTransactionConfig in project mule by mulesoft.
the class TransactionalExecutionTemplateTestCase method testActionAlwaysBeginAndCommitTxAndCommitNewTx.
@Test
public void testActionAlwaysBeginAndCommitTxAndCommitNewTx() throws Exception {
expectedException.expect(IllegalTransactionStateException.class);
TransactionCoordination.getInstance().bindTransaction(mockTransaction);
MuleTransactionConfig config = new MuleTransactionConfig(TransactionConfig.ACTION_ALWAYS_BEGIN);
ExecutionTemplate executionTemplate = createExecutionTemplate(config);
config.setFactory(new TestTransactionFactory(mockNewTransaction));
executionTemplate.execute(getEmptyTransactionCallback());
}
use of org.mule.runtime.core.api.transaction.MuleTransactionConfig in project mule by mulesoft.
the class TransactionalExecutionTemplateTestCase method testActionNeverAndTx.
@Test(expected = IllegalTransactionStateException.class)
public void testActionNeverAndTx() throws Exception {
TransactionCoordination.getInstance().bindTransaction(mockTransaction);
MuleTransactionConfig config = new MuleTransactionConfig(TransactionConfig.ACTION_NEVER);
ExecutionTemplate executionTemplate = createExecutionTemplate(config);
executionTemplate.execute(getEmptyTransactionCallback());
}
use of org.mule.runtime.core.api.transaction.MuleTransactionConfig in project mule by mulesoft.
the class TransactionalExecutionTemplateTestCase method testActionNoneAndXaTx.
@Test
public void testActionNoneAndXaTx() throws Exception {
mockTransaction.setXA(true);
TransactionCoordination.getInstance().bindTransaction(mockTransaction);
MuleTransactionConfig config = new MuleTransactionConfig(TransactionConfig.ACTION_NONE);
ExecutionTemplate executionTemplate = createExecutionTemplate(config);
Object result = executionTemplate.execute(getEmptyTransactionCallback());
assertThat(result, is(RETURN_VALUE));
verify(mockTransaction).suspend();
verify(mockTransaction).resume();
verify(mockTransaction, never()).commit();
verify(mockTransaction, never()).rollback();
}
Aggregations