16
16
17
17
package org .springframework .boot .autoconfigure .batch ;
18
18
19
+ import java .io .IOException ;
20
+ import java .sql .Connection ;
21
+ import java .sql .DatabaseMetaData ;
22
+ import java .sql .SQLException ;
23
+ import java .util .List ;
24
+ import java .util .stream .Collectors ;
25
+ import java .util .stream .Stream ;
26
+
19
27
import javax .sql .DataSource ;
20
28
29
+ import org .junit .Assume ;
21
30
import org .junit .jupiter .api .Test ;
31
+ import org .junit .jupiter .params .ParameterizedTest ;
32
+ import org .junit .jupiter .params .provider .EnumSource ;
33
+ import org .junit .jupiter .params .provider .EnumSource .Mode ;
22
34
35
+ import org .springframework .boot .jdbc .DatabaseDriver ;
23
36
import org .springframework .boot .sql .init .DatabaseInitializationSettings ;
37
+ import org .springframework .core .io .DefaultResourceLoader ;
38
+ import org .springframework .core .io .support .PathMatchingResourcePatternResolver ;
39
+ import org .springframework .test .util .ReflectionTestUtils ;
24
40
25
41
import static org .assertj .core .api .Assertions .assertThat ;
42
+ import static org .mockito .BDDMockito .given ;
26
43
import static org .mockito .BDDMockito .then ;
27
44
import static org .mockito .Mockito .mock ;
28
45
@@ -45,4 +62,37 @@ void getSettingsWithPlatformDoesNotTouchDataSource() {
45
62
then (dataSource ).shouldHaveNoInteractions ();
46
63
}
47
64
65
+ @ ParameterizedTest
66
+ @ EnumSource (value = DatabaseDriver .class , mode = Mode .EXCLUDE ,
67
+ names = { "FIREBIRD" , "INFORMIX" , "JTDS" , "PHOENIX" , "REDSHIFT" , "TERADATA" , "TESTCONTAINERS" , "UNKNOWN" })
68
+ void batchSchemaCanBeLocated (DatabaseDriver driver ) throws IOException , SQLException {
69
+ Assume .assumeFalse ("gh-30564" , driver == DatabaseDriver .ORACLE );
70
+ DefaultResourceLoader resourceLoader = new DefaultResourceLoader ();
71
+ BatchProperties properties = new BatchProperties ();
72
+ DataSource dataSource = mock (DataSource .class );
73
+ Connection connection = mock (Connection .class );
74
+ given (dataSource .getConnection ()).willReturn (connection );
75
+ DatabaseMetaData metadata = mock (DatabaseMetaData .class );
76
+ given (connection .getMetaData ()).willReturn (metadata );
77
+ String productName = (String ) ReflectionTestUtils .getField (driver , "productName" );
78
+ given (metadata .getDatabaseProductName ()).willReturn (productName );
79
+ DatabaseInitializationSettings settings = BatchDataSourceScriptDatabaseInitializer .getSettings (dataSource ,
80
+ properties .getJdbc ());
81
+ List <String > schemaLocations = settings .getSchemaLocations ();
82
+ assertThat (schemaLocations )
83
+ .allSatisfy ((location ) -> assertThat (resourceLoader .getResource (location ).exists ()).isTrue ());
84
+ }
85
+
86
+ @ Test
87
+ void batchHasExpectedBuiltInSchemas () throws IOException {
88
+ PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver ();
89
+ List <String > schemaNames = Stream
90
+ .of (resolver .getResources ("classpath:org/springframework/batch/core/schema-*.sql" ))
91
+ .map ((resource ) -> resource .getFilename ()).filter ((resourceName ) -> !resourceName .contains ("-drop-" ))
92
+ .collect (Collectors .toList ());
93
+ assertThat (schemaNames ).containsExactlyInAnyOrder ("schema-derby.sql" , "schema-sqlserver.sql" ,
94
+ "schema-mysql.sql" , "schema-sqlite.sql" , "schema-postgresql.sql" , "schema-hana.sql" ,
95
+ "schema-oracle.sql" , "schema-db2.sql" , "schema-hsqldb.sql" , "schema-sybase.sql" , "schema-h2.sql" );
96
+ }
97
+
48
98
}
0 commit comments