Search in sources :

Example 1 with XAConnectionWrapper

use of org.apache.aries.tx.control.jdbc.xa.connection.impl.XAConnectionWrapper in project aries by apache.

the class XATxContextBindingEntityManagerTest method testActiveTransactionWrappedXAConnection.

@Test
public void testActiveTransactionWrappedXAConnection() throws SQLException {
    XAConnection con = Mockito.mock(XAConnection.class);
    Connection raw = Mockito.mock(Connection.class);
    Mockito.when(con.getXAResource()).thenReturn(xaResource);
    Mockito.when(con.getConnection()).thenReturn(raw);
    XAConnectionWrapper value = new XAConnectionWrapper(con);
    Mockito.when(rawEm.unwrap(Connection.class)).thenReturn(value);
    setupActiveTransaction();
    em.isOpen();
    em.isOpen();
    Mockito.verify(rawEm, times(2)).isOpen();
    Mockito.verify(rawEm).joinTransaction();
    checkPostCompletion(null);
}
Also used : XAConnectionWrapper(org.apache.aries.tx.control.jdbc.xa.connection.impl.XAConnectionWrapper) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) XAConnection(javax.sql.XAConnection) Test(org.junit.Test)

Example 2 with XAConnectionWrapper

use of org.apache.aries.tx.control.jdbc.xa.connection.impl.XAConnectionWrapper in project aries by apache.

the class XATxContextBindingEntityManagerTest method testActiveTransactionUnwrappableXAConnectionWrapper.

@Test
public void testActiveTransactionUnwrappableXAConnectionWrapper() throws SQLException {
    XAConnection xaCon = Mockito.mock(XAConnection.class);
    Mockito.when(xaCon.getXAResource()).thenReturn(xaResource);
    Connection con = Mockito.mock(Connection.class);
    XAConnectionWrapper toReturn = new XAConnectionWrapper(xaCon);
    Mockito.when(con.unwrap(XAConnectionWrapper.class)).thenReturn(toReturn);
    Mockito.when(con.isWrapperFor(XAConnectionWrapper.class)).thenReturn(true);
    Mockito.when(rawEm.unwrap(Connection.class)).thenReturn(con);
    setupActiveTransaction();
    em.isOpen();
    em.isOpen();
    Mockito.verify(rawEm, times(2)).isOpen();
    Mockito.verify(rawEm).joinTransaction();
    checkPostCompletion(null);
}
Also used : XAConnectionWrapper(org.apache.aries.tx.control.jdbc.xa.connection.impl.XAConnectionWrapper) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) XAConnection(javax.sql.XAConnection) Test(org.junit.Test)

Aggregations

Connection (java.sql.Connection)2 XAConnection (javax.sql.XAConnection)2 XAConnectionWrapper (org.apache.aries.tx.control.jdbc.xa.connection.impl.XAConnectionWrapper)2 Test (org.junit.Test)2