1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.transaction.jdbc;
17
18 import static org.junit.Assert.assertFalse;
19 import static org.junit.Assert.assertTrue;
20 import static org.mockito.Mockito.mock;
21 import static org.mockito.Mockito.when;
22
23 import java.util.Properties;
24
25 import javax.sql.DataSource;
26
27 import org.apache.ibatis.session.TransactionIsolationLevel;
28 import org.apache.ibatis.transaction.Transaction;
29 import org.junit.jupiter.api.Test;
30
31 class JdbcTransactionFactoryTest {
32
33 @Test
34 void testNullProperties() throws Exception {
35 TestConnection connection = new TestConnection(false);
36 JdbcTransactionFactory factory = new JdbcTransactionFactory();
37 factory.setProperties(null);
38 Transaction transaction = factory.newTransaction(connection);
39 transaction.getConnection();
40 transaction.close();
41 assertTrue(connection.getAutoCommit());
42 }
43
44 @Test
45 void testSkipSetAutoCommitOnClose() throws Exception {
46 TestConnection connection = new TestConnection(false);
47 DataSource ds = mock(DataSource.class);
48 when(ds.getConnection()).thenReturn(connection);
49
50 JdbcTransactionFactory factory = new JdbcTransactionFactory();
51 Properties properties = new Properties();
52 properties.setProperty("skipSetAutoCommitOnClose", "true");
53 factory.setProperties(properties);
54 Transaction transaction = factory.newTransaction(ds, TransactionIsolationLevel.NONE, false);
55 transaction.getConnection();
56 transaction.close();
57 assertFalse(connection.getAutoCommit());
58 }
59
60 }