Search in sources :

Example 6 with ExecutionContextAdapter

use of org.mule.runtime.module.extension.api.runtime.privileged.ExecutionContextAdapter in project mule by mulesoft.

the class ExtensionConnectionSupplierTestCase method xaTransaction.

@Test
public void xaTransaction() throws Exception {
    muleContext.setTransactionManager(mock(TransactionManager.class, RETURNS_DEEP_STUBS));
    XaTransaction transaction = spy(new XaTransaction(muleContext));
    XATransactionalConnection connection = mock(XATransactionalConnection.class, RETURNS_DEEP_STUBS);
    Object config = new Object();
    ExecutionContextAdapter operationContext = mock(ExecutionContextAdapter.class, RETURNS_DEEP_STUBS);
    ConnectionProvider connectionProvider = mock(ConnectionProvider.class);
    ConfigurationInstance configurationInstance = mock(ConfigurationInstance.class);
    when(configurationInstance.getConnectionProvider()).thenReturn(of(connectionProvider));
    when(operationContext.getConfiguration()).thenReturn(of(configurationInstance));
    when(configurationInstance.getValue()).thenReturn(config);
    when(connectionProvider.connect()).thenReturn(connection);
    TransactionConfig transactionConfig = mock(TransactionConfig.class);
    when(transactionConfig.getAction()).thenReturn(ACTION_ALWAYS_JOIN);
    when(transactionConfig.isTransacted()).thenReturn(true);
    when(operationContext.getTransactionConfig()).thenReturn(of(transactionConfig));
    connectionManager.bind(config, connectionProvider);
    TransactionCoordination.getInstance().bindTransaction(transaction);
    adapter.getConnection(operationContext);
    verify(transaction).bindResource(any(), any(XAExtensionTransactionalResource.class));
}
Also used : XaTransaction(org.mule.runtime.core.privileged.transaction.XaTransaction) XAExtensionTransactionalResource(org.mule.runtime.module.extension.internal.runtime.transaction.XAExtensionTransactionalResource) TransactionManager(javax.transaction.TransactionManager) TransactionConfig(org.mule.runtime.core.api.transaction.TransactionConfig) XATransactionalConnection(org.mule.runtime.extension.api.connectivity.XATransactionalConnection) ExecutionContextAdapter(org.mule.runtime.module.extension.api.runtime.privileged.ExecutionContextAdapter) ConnectionProvider(org.mule.runtime.api.connection.ConnectionProvider) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance) Test(org.junit.Test)

Aggregations

ExecutionContextAdapter (org.mule.runtime.module.extension.api.runtime.privileged.ExecutionContextAdapter)6 LazyValue (org.mule.runtime.api.util.LazyValue)3 Test (org.junit.Test)2 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)2 HashMap (java.util.HashMap)1 TransactionManager (javax.transaction.TransactionManager)1 ConnectionException (org.mule.runtime.api.connection.ConnectionException)1 ConnectionHandler (org.mule.runtime.api.connection.ConnectionHandler)1 ConnectionProvider (org.mule.runtime.api.connection.ConnectionProvider)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 Cursor (org.mule.runtime.api.streaming.Cursor)1 TransactionConfig (org.mule.runtime.core.api.transaction.TransactionConfig)1 XaTransaction (org.mule.runtime.core.privileged.transaction.XaTransaction)1 XATransactionalConnection (org.mule.runtime.extension.api.connectivity.XATransactionalConnection)1 ConfigurationInstance (org.mule.runtime.extension.api.runtime.config.ConfigurationInstance)1 CompletionCallback (org.mule.runtime.extension.api.runtime.process.CompletionCallback)1 VoidCompletionCallback (org.mule.runtime.extension.api.runtime.process.VoidCompletionCallback)1 BackPressureAction (org.mule.runtime.extension.api.runtime.source.BackPressureAction)1 ImmutableBackPressureContext (org.mule.runtime.module.extension.internal.runtime.source.ImmutableBackPressureContext)1 XAExtensionTransactionalResource (org.mule.runtime.module.extension.internal.runtime.transaction.XAExtensionTransactionalResource)1