Skip to content

Commit facbc7b

Browse files
committed
Merge branch '2.6.x' into 2.7.x
Closes gh-30795
2 parents 56690a7 + bf94ea2 commit facbc7b

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchDataSourceScriptDatabaseInitializerTests.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,29 @@
1616

1717
package org.springframework.boot.autoconfigure.batch;
1818

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+
1927
import javax.sql.DataSource;
2028

2129
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;
2233

34+
import org.springframework.boot.jdbc.DatabaseDriver;
2335
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;
2439

2540
import static org.assertj.core.api.Assertions.assertThat;
41+
import static org.mockito.BDDMockito.given;
2642
import static org.mockito.BDDMockito.then;
2743
import static org.mockito.Mockito.mock;
2844

@@ -45,4 +61,36 @@ void getSettingsWithPlatformDoesNotTouchDataSource() {
4561
then(dataSource).shouldHaveNoInteractions();
4662
}
4763

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+
4896
}

0 commit comments

Comments
 (0)