15
15
*/
16
16
package org .springframework .data .neo4j .core .transaction ;
17
17
18
+ import static org .assertj .core .api .Assertions .assertThat ;
19
+
20
+ import java .time .Duration ;
21
+
18
22
import org .assertj .core .api .Assertions ;
19
23
import org .junit .jupiter .api .Nested ;
24
+ import org .junit .jupiter .api .Test ;
20
25
import org .junit .jupiter .api .extension .ExtendWith ;
21
26
import org .junit .jupiter .params .ParameterizedTest ;
22
27
import org .junit .jupiter .params .provider .CsvSource ;
28
+ import org .junit .jupiter .params .provider .ValueSource ;
23
29
import org .mockito .junit .jupiter .MockitoExtension ;
24
30
import org .mockito .junit .jupiter .MockitoSettings ;
25
31
import org .mockito .quality .Strictness ;
32
+ import org .neo4j .driver .TransactionConfig ;
33
+ import org .springframework .transaction .support .DefaultTransactionDefinition ;
26
34
27
35
/**
28
36
* @author Michael J. Simons
@@ -49,4 +57,32 @@ void nameComparisionShouldWorkForNamesTargetingOther(String name1, String name2)
49
57
}
50
58
}
51
59
60
+ @ ParameterizedTest // GH-2463
61
+ @ ValueSource (ints = { Integer .MIN_VALUE , -1 , 0 , DefaultTransactionDefinition .TIMEOUT_DEFAULT })
62
+ void shouldNotApplyNegativeOrZeroTimeOuts (int value ) {
63
+
64
+ DefaultTransactionDefinition springDef = new DefaultTransactionDefinition ();
65
+ springDef .setTimeout (DefaultTransactionDefinition .TIMEOUT_DEFAULT );
66
+ TransactionConfig driverConfig = Neo4jTransactionUtils .createTransactionConfigFrom (springDef , value );
67
+ assertThat (driverConfig .timeout ()).isNull ();
68
+ }
69
+
70
+ @ ParameterizedTest // GH-2463
71
+ @ ValueSource (ints = { Integer .MIN_VALUE , -1 , 0 })
72
+ void shouldPreferTxDef (int value ) {
73
+
74
+ DefaultTransactionDefinition springDef = new DefaultTransactionDefinition ();
75
+ springDef .setTimeout (2 );
76
+ TransactionConfig driverConfig = Neo4jTransactionUtils .createTransactionConfigFrom (springDef , value );
77
+ assertThat (driverConfig .timeout ()).isEqualTo (Duration .ofSeconds (2 ));
78
+ }
79
+
80
+ @ Test // GH-2463
81
+ void shouldFallbackToTxManagerDefault () {
82
+
83
+ DefaultTransactionDefinition springDef = new DefaultTransactionDefinition ();
84
+ springDef .setTimeout (DefaultTransactionDefinition .TIMEOUT_DEFAULT );
85
+ TransactionConfig driverConfig = Neo4jTransactionUtils .createTransactionConfigFrom (springDef , 3 );
86
+ assertThat (driverConfig .timeout ()).isEqualTo (Duration .ofSeconds (3 ));
87
+ }
52
88
}
0 commit comments