Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Jan 6, 2024
1 parent a51c22b commit 87b35e7
Show file tree
Hide file tree
Showing 58 changed files with 651 additions and 679 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,20 +36,20 @@
/**
* @author Dave Syer
*/
public class InitializeDatabaseIntegrationTests {
class InitializeDatabaseIntegrationTests {

private String enabled;

private ClassPathXmlApplicationContext context;


@BeforeEach
public void init() {
void init() {
enabled = System.setProperty("ENABLED", "true");
}

@AfterEach
public void after() {
void after() {
if (enabled != null) {
System.setProperty("ENABLED", enabled);
}
Expand All @@ -63,27 +63,27 @@ public void after() {


@Test
public void testCreateEmbeddedDatabase() throws Exception {
void testCreateEmbeddedDatabase() {
context = new ClassPathXmlApplicationContext("org/springframework/jdbc/config/jdbc-initialize-config.xml");
assertCorrectSetup(context.getBean("dataSource", DataSource.class));
}

@Test
public void testDisableCreateEmbeddedDatabase() throws Exception {
void testDisableCreateEmbeddedDatabase() {
System.setProperty("ENABLED", "false");
context = new ClassPathXmlApplicationContext("org/springframework/jdbc/config/jdbc-initialize-config.xml");
assertThatExceptionOfType(BadSqlGrammarException.class).isThrownBy(() ->
assertCorrectSetup(context.getBean("dataSource", DataSource.class)));
}

@Test
public void testIgnoreFailedDrops() throws Exception {
void testIgnoreFailedDrops() {
context = new ClassPathXmlApplicationContext("org/springframework/jdbc/config/jdbc-initialize-fail-config.xml");
assertCorrectSetup(context.getBean("dataSource", DataSource.class));
}

@Test
public void testScriptNameWithPattern() throws Exception {
void testScriptNameWithPattern() {
context = new ClassPathXmlApplicationContext("org/springframework/jdbc/config/jdbc-initialize-pattern-config.xml");
DataSource dataSource = context.getBean("dataSource", DataSource.class);
assertCorrectSetup(dataSource);
Expand All @@ -92,21 +92,21 @@ public void testScriptNameWithPattern() throws Exception {
}

@Test
public void testScriptNameWithPlaceholder() throws Exception {
void testScriptNameWithPlaceholder() {
context = new ClassPathXmlApplicationContext("org/springframework/jdbc/config/jdbc-initialize-placeholder-config.xml");
DataSource dataSource = context.getBean("dataSource", DataSource.class);
assertCorrectSetup(dataSource);
}

@Test
public void testScriptNameWithExpressions() throws Exception {
void testScriptNameWithExpressions() {
context = new ClassPathXmlApplicationContext("org/springframework/jdbc/config/jdbc-initialize-expression-config.xml");
DataSource dataSource = context.getBean("dataSource", DataSource.class);
assertCorrectSetup(dataSource);
}

@Test
public void testCacheInitialization() throws Exception {
void testCacheInitialization() {
context = new ClassPathXmlApplicationContext("org/springframework/jdbc/config/jdbc-initialize-cache-config.xml");
assertCorrectSetup(context.getBean("dataSource", DataSource.class));
CacheData cache = context.getBean(CacheData.class);
Expand Down Expand Up @@ -134,7 +134,7 @@ public List<Map<String,Object>> getCachedData() {
}

@Override
public void afterPropertiesSet() throws Exception {
public void afterPropertiesSet() {
cache = jdbcTemplate.queryForList("SELECT * FROM T_TEST");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -52,58 +52,58 @@ class JdbcNamespaceIntegrationTests {

@Test
@EnabledForTestGroups(LONG_RUNNING)
void createEmbeddedDatabase() throws Exception {
void createEmbeddedDatabase() {
assertCorrectSetup("jdbc-config.xml", "dataSource", "h2DataSource", "derbyDataSource");
}

@Test
@EnabledForTestGroups(LONG_RUNNING)
void createEmbeddedDatabaseAgain() throws Exception {
void createEmbeddedDatabaseAgain() {
// If Derby isn't cleaned up properly this will fail...
assertCorrectSetup("jdbc-config.xml", "derbyDataSource");
}

@Test
void createWithResourcePattern() throws Exception {
void createWithResourcePattern() {
assertCorrectSetup("jdbc-config-pattern.xml", "dataSource");
}

@Test
void createWithAnonymousDataSourceAndDefaultDatabaseName() throws Exception {
void createWithAnonymousDataSourceAndDefaultDatabaseName() {
assertCorrectSetupForSingleDataSource("jdbc-config-db-name-default-and-anonymous-datasource.xml",
url -> url.endsWith(DEFAULT_DATABASE_NAME));
}

@Test
void createWithImplicitDatabaseName() throws Exception {
void createWithImplicitDatabaseName() {
assertCorrectSetupForSingleDataSource("jdbc-config-db-name-implicit.xml", url -> url.endsWith("dataSource"));
}

@Test
void createWithExplicitDatabaseName() throws Exception {
void createWithExplicitDatabaseName() {
assertCorrectSetupForSingleDataSource("jdbc-config-db-name-explicit.xml", url -> url.endsWith("customDbName"));
}

@Test
void createWithGeneratedDatabaseName() throws Exception {
void createWithGeneratedDatabaseName() {
Predicate<String> urlPredicate = url -> url.startsWith("jdbc:hsqldb:mem:");
urlPredicate.and(url -> !url.endsWith("dataSource"));
urlPredicate.and(url -> !url.endsWith("shouldBeOverriddenByGeneratedName"));
assertCorrectSetupForSingleDataSource("jdbc-config-db-name-generated.xml", urlPredicate);
}

@Test
void createWithEndings() throws Exception {
void createWithEndings() {
assertCorrectSetupAndCloseContext("jdbc-initialize-endings-config.xml", 2, "dataSource");
}

@Test
void createWithEndingsNested() throws Exception {
void createWithEndingsNested() {
assertCorrectSetupAndCloseContext("jdbc-initialize-endings-nested-config.xml", 2, "dataSource");
}

@Test
void createAndDestroy() throws Exception {
void createAndDestroy() {
try (ClassPathXmlApplicationContext context = context("jdbc-destroy-config.xml")) {
DataSource dataSource = context.getBean(DataSource.class);
JdbcTemplate template = new JdbcTemplate(dataSource);
Expand All @@ -116,7 +116,7 @@ void createAndDestroy() throws Exception {
}

@Test
void createAndDestroyNestedWithHsql() throws Exception {
void createAndDestroyNestedWithHsql() {
try (ClassPathXmlApplicationContext context = context("jdbc-destroy-nested-config.xml")) {
DataSource dataSource = context.getBean(DataSource.class);
JdbcTemplate template = new JdbcTemplate(dataSource);
Expand All @@ -129,7 +129,7 @@ void createAndDestroyNestedWithHsql() throws Exception {
}

@Test
void createAndDestroyNestedWithH2() throws Exception {
void createAndDestroyNestedWithH2() {
try (ClassPathXmlApplicationContext context = context("jdbc-destroy-nested-config-h2.xml")) {
DataSource dataSource = context.getBean(DataSource.class);
JdbcTemplate template = new JdbcTemplate(dataSource);
Expand All @@ -142,7 +142,7 @@ void createAndDestroyNestedWithH2() throws Exception {
}

@Test
void multipleDataSourcesHaveDifferentDatabaseNames() throws Exception {
void multipleDataSourcesHaveDifferentDatabaseNames() {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(new ClassPathResource(
"jdbc-config-multiple-datasources.xml", getClass()));
Expand All @@ -151,12 +151,12 @@ void multipleDataSourcesHaveDifferentDatabaseNames() throws Exception {
}

@Test
void initializeWithCustomSeparator() throws Exception {
void initializeWithCustomSeparator() {
assertCorrectSetupAndCloseContext("jdbc-initialize-custom-separator.xml", 2, "dataSource");
}

@Test
void embeddedWithCustomSeparator() throws Exception {
void embeddedWithCustomSeparator() {
assertCorrectSetupAndCloseContext("jdbc-config-custom-separator.xml", 2, "dataSource");
}

Expand Down
Loading

0 comments on commit 87b35e7

Please sign in to comment.