1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.transaction.managed;
17
18 import static org.junit.jupiter.api.Assertions.assertEquals;
19 import static org.mockito.Mockito.verify;
20 import static org.mockito.Mockito.verifyNoMoreInteractions;
21
22 import java.sql.Connection;
23 import java.util.Properties;
24
25 import org.apache.ibatis.BaseDataTest;
26 import org.apache.ibatis.transaction.Transaction;
27 import org.apache.ibatis.transaction.TransactionFactory;
28 import org.junit.jupiter.api.Test;
29 import org.junit.jupiter.api.extension.ExtendWith;
30 import org.mockito.Mock;
31 import org.mockito.junit.jupiter.MockitoExtension;
32
33 @ExtendWith(MockitoExtension.class)
34 class ManagedTransactionFactoryTest extends BaseDataTest {
35
36 @Mock
37 private Connection conn;
38
39 @Test
40 void shouldEnsureThatCallsToManagedTransactionAPIDoNotForwardToManagedConnections() throws Exception {
41 TransactionFactory tf = new ManagedTransactionFactory();
42 tf.setProperties(new Properties());
43 Transaction tx = tf.newTransaction(conn);
44 assertEquals(conn, tx.getConnection());
45 tx.commit();
46 tx.rollback();
47 tx.close();
48 verify(conn).close();
49 }
50
51 @Test
52 void shouldEnsureThatCallsToManagedTransactionAPIDoNotForwardToManagedConnectionsAndDoesNotCloseConnection()
53 throws Exception {
54 TransactionFactory tf = new ManagedTransactionFactory();
55 Properties props = new Properties();
56 props.setProperty("closeConnection", "false");
57 tf.setProperties(props);
58 Transaction tx = tf.newTransaction(conn);
59 assertEquals(conn, tx.getConnection());
60 tx.commit();
61 tx.rollback();
62 tx.close();
63 verifyNoMoreInteractions(conn);
64 }
65
66 }