1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -66,7 +66,7 @@ public class DataSourceTransactionManagerTests {
66
66
67
67
68
68
@ Before
69
- public void setUp () throws Exception {
69
+ public void setup () throws Exception {
70
70
ds = mock (DataSource .class );
71
71
con = mock (Connection .class );
72
72
given (ds .getConnection ()).willReturn (con );
@@ -118,6 +118,7 @@ private void doTestTransactionCommitRestoringAutoCommit(
118
118
if (lazyConnection ) {
119
119
given (con .getAutoCommit ()).willReturn (autoCommit );
120
120
given (con .getTransactionIsolation ()).willReturn (Connection .TRANSACTION_READ_COMMITTED );
121
+ given (con .getWarnings ()).willThrow (new SQLException ());
121
122
}
122
123
123
124
if (!lazyConnection || createStatement ) {
@@ -144,6 +145,10 @@ protected void doInTransactionWithoutResult(TransactionStatus status) throws Run
144
145
tCon .createStatement ();
145
146
assertEquals (con , new SimpleNativeJdbcExtractor ().getNativeConnection (tCon ));
146
147
}
148
+ else {
149
+ tCon .getWarnings ();
150
+ tCon .clearWarnings ();
151
+ }
147
152
}
148
153
catch (SQLException ex ) {
149
154
throw new UncategorizedSQLException ("" , "" , ex );
@@ -211,7 +216,7 @@ private void doTestTransactionRollbackRestoringAutoCommit(
211
216
}
212
217
213
218
final DataSource dsToUse = (lazyConnection ? new LazyConnectionDataSourceProxy (ds ) : ds );
214
- tm = new DataSourceTransactionManager (dsToUse );
219
+ tm = new DataSourceTransactionManager (dsToUse );
215
220
TransactionTemplate tt = new TransactionTemplate (tm );
216
221
assertTrue ("Hasn't thread connection" , !TransactionSynchronizationManager .hasResource (dsToUse ));
217
222
assertTrue ("Synchronization not active" , !TransactionSynchronizationManager .isSynchronizationActive ());
@@ -671,7 +676,6 @@ public void testPropagationRequiresNewWithExistingTransactionAndUnrelatedFailing
671
676
SQLException failure = new SQLException ();
672
677
given (ds2 .getConnection ()).willThrow (failure );
673
678
674
-
675
679
final TransactionTemplate tt = new TransactionTemplate (tm );
676
680
tt .setPropagationBehavior (TransactionDefinition .PROPAGATION_REQUIRES_NEW );
677
681
@@ -976,12 +980,12 @@ protected void doInTransactionWithoutResult(TransactionStatus status) {
976
980
ordered .verify (con ).setAutoCommit (false );
977
981
ordered .verify (con ).setAutoCommit (true );
978
982
verify (con ).close ();
979
-
980
983
}
981
984
982
985
@ Test
983
986
public void testTransactionAwareDataSourceProxy () throws Exception {
984
987
given (con .getAutoCommit ()).willReturn (true );
988
+ given (con .getWarnings ()).willThrow (new SQLException ());
985
989
986
990
TransactionTemplate tt = new TransactionTemplate (tm );
987
991
assertTrue ("Hasn't thread connection" , !TransactionSynchronizationManager .hasResource (ds ));
@@ -992,6 +996,9 @@ protected void doInTransactionWithoutResult(TransactionStatus status) {
992
996
assertEquals (con , DataSourceUtils .getConnection (ds ));
993
997
TransactionAwareDataSourceProxy dsProxy = new TransactionAwareDataSourceProxy (ds );
994
998
try {
999
+ Connection tCon = dsProxy .getConnection ();
1000
+ tCon .getWarnings ();
1001
+ tCon .clearWarnings ();
995
1002
assertEquals (con , ((ConnectionProxy ) dsProxy .getConnection ()).getTargetConnection ());
996
1003
assertEquals (con , new SimpleNativeJdbcExtractor ().getNativeConnection (dsProxy .getConnection ()));
997
1004
// should be ignored
@@ -1249,7 +1256,8 @@ protected void doInTransactionWithoutResult(TransactionStatus status) throws Run
1249
1256
assertTrue ("Hasn't thread connection" , !TransactionSynchronizationManager .hasResource (ds ));
1250
1257
}
1251
1258
1252
- @ Test public void testTransactionWithPropagationNotSupported () throws Exception {
1259
+ @ Test
1260
+ public void testTransactionWithPropagationNotSupported () throws Exception {
1253
1261
TransactionTemplate tt = new TransactionTemplate (tm );
1254
1262
tt .setPropagationBehavior (TransactionDefinition .PROPAGATION_NOT_SUPPORTED );
1255
1263
assertTrue ("Hasn't thread connection" , !TransactionSynchronizationManager .hasResource (ds ));
0 commit comments