Search in sources :

Example 6 with TestTransactionFactory

use of org.mule.tck.testmodels.mule.TestTransactionFactory 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());
}
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 7 with TestTransactionFactory

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

the class TransactionalExecutionTemplateTestCase method testActionBeginOrJoinAndTx.

@Test
public void testActionBeginOrJoinAndTx() throws Exception {
    TransactionCoordination.getInstance().bindTransaction(mockTransaction);
    MuleTransactionConfig config = new MuleTransactionConfig(TransactionConfig.ACTION_BEGIN_OR_JOIN);
    ExecutionTemplate executionTemplate = createExecutionTemplate(config);
    config.setFactory(new TestTransactionFactory(mockTransaction));
    Object result = executionTemplate.execute(getEmptyTransactionCallback());
    assertThat(result, is(RETURN_VALUE));
    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 8 with TestTransactionFactory

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

the class TransactionalExecutionTemplateTestCase method testActionBeginOrJoinAndNoTx.

@Test
public void testActionBeginOrJoinAndNoTx() throws Exception {
    MuleTransactionConfig config = new MuleTransactionConfig(TransactionConfig.ACTION_BEGIN_OR_JOIN);
    ExecutionTemplate executionTemplate = createExecutionTemplate(config);
    config.setFactory(new TestTransactionFactory(mockTransaction));
    Object result = executionTemplate.execute(getEmptyTransactionCallback());
    assertThat(result, is(RETURN_VALUE));
    verify(mockTransaction).commit();
    verify(mockTransaction, 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)

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