20
20
21
21
import javax .sql .DataSource ;
22
22
23
+ import org .h2 .engine .Mode .ModeEnum ;
23
24
import org .junit .jupiter .api .Test ;
24
25
import org .junit .jupiter .params .ParameterizedTest ;
25
- import org .junit .jupiter .params .provider .ValueSource ;
26
+ import org .junit .jupiter .params .provider .EnumSource ;
26
27
27
28
import org .springframework .jdbc .core .JdbcTemplate ;
28
- import org .springframework .jdbc .datasource .DataSourceTransactionManager ;
29
29
import org .springframework .jdbc .datasource .SimpleDriverDataSource ;
30
30
import org .springframework .jdbc .datasource .embedded .EmbeddedDatabase ;
31
31
import org .springframework .jdbc .datasource .embedded .EmbeddedDatabaseBuilder ;
32
32
import org .springframework .jdbc .datasource .embedded .EmbeddedDatabaseType ;
33
- import org .springframework .transaction .PlatformTransactionManager ;
34
- import org .springframework .transaction .support .TransactionTemplate ;
35
33
36
34
import static org .assertj .core .api .Assertions .assertThat ;
37
35
@@ -60,12 +58,7 @@ void incrementsSequenceUsingH2EmbeddedDatabaseConfigurer() {
60
58
.addScript ("classpath:/org/springframework/jdbc/support/incrementer/schema.sql" )
61
59
.build ();
62
60
63
- JdbcTemplate jdbcTemplate = new JdbcTemplate (database );
64
- assertThat (jdbcTemplate .queryForObject ("values next value for SEQ" , int .class )).isEqualTo (1 );
65
-
66
- H2SequenceMaxValueIncrementer incrementer = new H2SequenceMaxValueIncrementer (database , "SEQ" );
67
- assertThat (incrementer .nextIntValue ()).isEqualTo (2 );
68
- assertThat (incrementer .nextStringValue ()).isEqualTo ("3" );
61
+ assertIncrements (database );
69
62
70
63
database .shutdown ();
71
64
}
@@ -74,24 +67,24 @@ void incrementsSequenceUsingH2EmbeddedDatabaseConfigurer() {
74
67
* Tests that the incrementer works when using all supported H2 <em>compatibility modes</em>.
75
68
*/
76
69
@ ParameterizedTest
77
- @ ValueSource ( strings = { "STRICT" , "LEGACY" , "DB2" , "Derby" , "HSQLDB" , "MariaDB" , "MSSQLServer" , "MySQL" , "Oracle" , "PostgreSQL" } )
78
- void incrementsSequenceWithExplicitH2CompatibilityMode (String compatibilityMode ) {
79
- String connectionUrl = String .format ("jdbc:h2:mem:%s;MODE=%s" , UUID .randomUUID ().toString (), compatibilityMode );
70
+ @ EnumSource ( ModeEnum . class )
71
+ void incrementsSequenceWithExplicitH2CompatibilityMode (ModeEnum mode ) {
72
+ String connectionUrl = String .format ("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false; MODE=%s" , UUID .randomUUID ().toString (), mode );
80
73
DataSource dataSource = new SimpleDriverDataSource (new org .h2 .Driver (), connectionUrl , "sa" , "" );
81
74
JdbcTemplate jdbcTemplate = new JdbcTemplate (dataSource );
82
- PlatformTransactionManager transactionManager = new DataSourceTransactionManager (dataSource );
83
- TransactionTemplate transactionTemplate = new TransactionTemplate (transactionManager );
75
+ jdbcTemplate .execute ("CREATE SEQUENCE SEQ" );
84
76
85
- transactionTemplate .executeWithoutResult (status -> {
86
- jdbcTemplate .execute ("CREATE SEQUENCE SEQ" );
87
- assertThat (jdbcTemplate .queryForObject ("values next value for SEQ" , int .class )).isEqualTo (1 );
88
-
89
- H2SequenceMaxValueIncrementer incrementer = new H2SequenceMaxValueIncrementer (dataSource , "SEQ" );
90
- assertThat (incrementer .nextIntValue ()).isEqualTo (2 );
91
- assertThat (incrementer .nextStringValue ()).isEqualTo ("3" );
92
- });
77
+ assertIncrements (dataSource );
93
78
94
79
jdbcTemplate .execute ("SHUTDOWN" );
95
80
}
96
81
82
+ private void assertIncrements (DataSource dataSource ) {
83
+ assertThat (new JdbcTemplate (dataSource ).queryForObject ("values next value for SEQ" , int .class )).isEqualTo (1 );
84
+
85
+ H2SequenceMaxValueIncrementer incrementer = new H2SequenceMaxValueIncrementer (dataSource , "SEQ" );
86
+ assertThat (incrementer .nextIntValue ()).isEqualTo (2 );
87
+ assertThat (incrementer .nextStringValue ()).isEqualTo ("3" );
88
+ }
89
+
97
90
}
0 commit comments