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