1
1
/*
2
- * Copyright 2002-2018 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.
48
48
import org .springframework .transaction .support .TransactionSynchronizationManager ;
49
49
import org .springframework .transaction .support .TransactionTemplate ;
50
50
51
- import static org .junit .Assert .*;
52
- import static org .mockito .BDDMockito .*;
51
+ import static org .junit .Assert .assertEquals ;
52
+ import static org .junit .Assert .assertFalse ;
53
+ import static org .junit .Assert .assertNull ;
54
+ import static org .junit .Assert .assertSame ;
55
+ import static org .junit .Assert .assertTrue ;
56
+ import static org .junit .Assert .fail ;
57
+ import static org .mockito .BDDMockito .given ;
58
+ import static org .mockito .BDDMockito .inOrder ;
59
+ import static org .mockito .BDDMockito .mock ;
60
+ import static org .mockito .BDDMockito .times ;
61
+ import static org .mockito .BDDMockito .verify ;
62
+ import static org .mockito .BDDMockito .willThrow ;
53
63
54
64
/**
55
65
* @author Juergen Hoeller
@@ -117,6 +127,7 @@ private void doTestTransactionCommitRestoringAutoCommit(
117
127
if (lazyConnection ) {
118
128
given (con .getAutoCommit ()).willReturn (autoCommit );
119
129
given (con .getTransactionIsolation ()).willReturn (Connection .TRANSACTION_READ_COMMITTED );
130
+ given (con .getWarnings ()).willThrow (new SQLException ());
120
131
}
121
132
122
133
if (!lazyConnection || createStatement ) {
@@ -142,6 +153,10 @@ protected void doInTransactionWithoutResult(TransactionStatus status) throws Run
142
153
if (createStatement ) {
143
154
tCon .createStatement ();
144
155
}
156
+ else {
157
+ tCon .getWarnings ();
158
+ tCon .clearWarnings ();
159
+ }
145
160
}
146
161
catch (SQLException ex ) {
147
162
throw new UncategorizedSQLException ("" , "" , ex );
@@ -669,7 +684,6 @@ public void testPropagationRequiresNewWithExistingTransactionAndUnrelatedFailing
669
684
SQLException failure = new SQLException ();
670
685
given (ds2 .getConnection ()).willThrow (failure );
671
686
672
-
673
687
final TransactionTemplate tt = new TransactionTemplate (tm );
674
688
tt .setPropagationBehavior (TransactionDefinition .PROPAGATION_REQUIRES_NEW );
675
689
@@ -974,12 +988,12 @@ protected void doInTransactionWithoutResult(TransactionStatus status) {
974
988
ordered .verify (con ).setAutoCommit (false );
975
989
ordered .verify (con ).setAutoCommit (true );
976
990
verify (con ).close ();
977
-
978
991
}
979
992
980
993
@ Test
981
994
public void testTransactionAwareDataSourceProxy () throws Exception {
982
995
given (con .getAutoCommit ()).willReturn (true );
996
+ given (con .getWarnings ()).willThrow (new SQLException ());
983
997
984
998
TransactionTemplate tt = new TransactionTemplate (tm );
985
999
assertTrue ("Hasn't thread connection" , !TransactionSynchronizationManager .hasResource (ds ));
@@ -990,6 +1004,9 @@ protected void doInTransactionWithoutResult(TransactionStatus status) {
990
1004
assertEquals (con , DataSourceUtils .getConnection (ds ));
991
1005
TransactionAwareDataSourceProxy dsProxy = new TransactionAwareDataSourceProxy (ds );
992
1006
try {
1007
+ Connection tCon = dsProxy .getConnection ();
1008
+ tCon .getWarnings ();
1009
+ tCon .clearWarnings ();
993
1010
assertEquals (con , ((ConnectionProxy ) dsProxy .getConnection ()).getTargetConnection ());
994
1011
// should be ignored
995
1012
dsProxy .getConnection ().close ();
0 commit comments