Remove deprecated code
Closes gh-29290
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
* Copyright 2012-2022 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.
|
||||
@@ -56,13 +56,10 @@ import org.springframework.boot.jdbc.DataSourceBuilder;
|
||||
import org.springframework.boot.jdbc.init.DataSourceScriptDatabaseInitializer;
|
||||
import org.springframework.boot.sql.init.DatabaseInitializationMode;
|
||||
import org.springframework.boot.sql.init.DatabaseInitializationSettings;
|
||||
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.boot.test.context.runner.ContextConsumer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.jdbc.BadSqlGrammarException;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
@@ -187,28 +184,15 @@ class BatchAutoConfigurationTests {
|
||||
this.contextRunner.withUserConfiguration(TestConfiguration.class, EmbeddedDataSourceConfiguration.class)
|
||||
.withPropertyValues("spring.datasource.generate-unique-name=true",
|
||||
"spring.batch.jdbc.initialize-schema:never")
|
||||
.run(assertDatasourceIsNotInitialized());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void testDisableSchemaLoaderWithDeprecatedProperty() {
|
||||
this.contextRunner.withUserConfiguration(TestConfiguration.class, EmbeddedDataSourceConfiguration.class)
|
||||
.withPropertyValues("spring.datasource.generate-unique-name=true",
|
||||
"spring.batch.initialize-schema:never")
|
||||
.run(assertDatasourceIsNotInitialized());
|
||||
}
|
||||
|
||||
private ContextConsumer<AssertableApplicationContext> assertDatasourceIsNotInitialized() {
|
||||
return (context) -> {
|
||||
assertThat(context).hasSingleBean(JobLauncher.class);
|
||||
assertThat(context.getBean(BatchProperties.class).getJdbc().getInitializeSchema())
|
||||
.isEqualTo(DatabaseInitializationMode.NEVER);
|
||||
assertThat(context).doesNotHaveBean(BatchDataSourceScriptDatabaseInitializer.class);
|
||||
assertThatExceptionOfType(BadSqlGrammarException.class)
|
||||
.isThrownBy(() -> new JdbcTemplate(context.getBean(DataSource.class))
|
||||
.queryForList("select * from BATCH_JOB_EXECUTION"));
|
||||
};
|
||||
.run((context) -> {
|
||||
assertThat(context).hasSingleBean(JobLauncher.class);
|
||||
assertThat(context.getBean(BatchProperties.class).getJdbc().getInitializeSchema())
|
||||
.isEqualTo(DatabaseInitializationMode.NEVER);
|
||||
assertThat(context).doesNotHaveBean(BatchDataSourceScriptDatabaseInitializer.class);
|
||||
assertThatExceptionOfType(BadSqlGrammarException.class)
|
||||
.isThrownBy(() -> new JdbcTemplate(context.getBean(DataSource.class))
|
||||
.queryForList("select * from BATCH_JOB_EXECUTION"));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -235,33 +219,17 @@ class BatchAutoConfigurationTests {
|
||||
.withPropertyValues("spring.datasource.generate-unique-name=true",
|
||||
"spring.batch.jdbc.schema:classpath:batch/custom-schema-hsql.sql",
|
||||
"spring.batch.jdbc.tablePrefix:PREFIX_")
|
||||
.run(assertCustomTablePrefix());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void testRenamePrefixWithDeprecatedProperty() {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(TestConfiguration.class, EmbeddedDataSourceConfiguration.class,
|
||||
HibernateJpaAutoConfiguration.class)
|
||||
.withPropertyValues("spring.datasource.generate-unique-name=true",
|
||||
"spring.batch.schema:classpath:batch/custom-schema-hsql.sql",
|
||||
"spring.batch.tablePrefix:PREFIX_")
|
||||
.run(assertCustomTablePrefix());
|
||||
}
|
||||
|
||||
private ContextConsumer<AssertableApplicationContext> assertCustomTablePrefix() {
|
||||
return (context) -> {
|
||||
assertThat(context).hasSingleBean(JobLauncher.class);
|
||||
assertThat(context.getBean(BatchProperties.class).getJdbc().getInitializeSchema())
|
||||
.isEqualTo(DatabaseInitializationMode.EMBEDDED);
|
||||
assertThat(new JdbcTemplate(context.getBean(DataSource.class))
|
||||
.queryForList("select * from PREFIX_JOB_EXECUTION")).isEmpty();
|
||||
JobExplorer jobExplorer = context.getBean(JobExplorer.class);
|
||||
assertThat(jobExplorer.findRunningJobExecutions("test")).isEmpty();
|
||||
JobRepository jobRepository = context.getBean(JobRepository.class);
|
||||
assertThat(jobRepository.getLastJobExecution("test", new JobParameters())).isNull();
|
||||
};
|
||||
.run((context) -> {
|
||||
assertThat(context).hasSingleBean(JobLauncher.class);
|
||||
assertThat(context.getBean(BatchProperties.class).getJdbc().getInitializeSchema())
|
||||
.isEqualTo(DatabaseInitializationMode.EMBEDDED);
|
||||
assertThat(new JdbcTemplate(context.getBean(DataSource.class))
|
||||
.queryForList("select * from PREFIX_JOB_EXECUTION")).isEmpty();
|
||||
JobExplorer jobExplorer = context.getBean(JobExplorer.class);
|
||||
assertThat(jobExplorer.findRunningJobExecutions("test")).isEmpty();
|
||||
JobRepository jobRepository = context.getBean(JobRepository.class);
|
||||
assertThat(jobRepository.getLastJobExecution("test", new JobParameters())).isNull();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -362,18 +330,6 @@ class BatchAutoConfigurationTests {
|
||||
.doesNotHaveBean("batchDataSourceScriptDatabaseInitializer").hasBean("customInitializer"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
@SuppressWarnings("deprecation")
|
||||
void whenTheUserDefinesTheirOwnBatchDataSourceInitializerThenTheAutoConfiguredInitializerBacksOff() {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(TestConfiguration.class, CustomBatchDataSourceInitializerConfiguration.class)
|
||||
.withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class,
|
||||
DataSourceTransactionManagerAutoConfiguration.class))
|
||||
.run((context) -> assertThat(context).doesNotHaveBean(BatchDataSourceScriptDatabaseInitializer.class)
|
||||
.hasSingleBean(BatchDataSourceInitializer.class).hasBean("customInitializer"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenTheUserDefinesTheirOwnDatabaseInitializerThenTheAutoConfiguredBatchInitializerRemains() {
|
||||
this.contextRunner.withUserConfiguration(TestConfiguration.class, CustomDatabaseInitializerConfiguration.class)
|
||||
@@ -547,16 +503,4 @@ class BatchAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class CustomBatchDataSourceInitializerConfiguration {
|
||||
|
||||
@Bean
|
||||
BatchDataSourceInitializer customInitializer(DataSource dataSource, ResourceLoader resourceLoader,
|
||||
BatchProperties properties) {
|
||||
return new BatchDataSourceInitializer(dataSource, resourceLoader, properties);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,9 +31,7 @@ import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfigurati
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.test.City;
|
||||
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration;
|
||||
import org.springframework.boot.sql.init.DatabaseInitializationMode;
|
||||
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.boot.test.context.runner.ContextConsumer;
|
||||
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
@@ -77,26 +75,13 @@ class BatchAutoConfigurationWithoutJpaTests {
|
||||
.withPropertyValues("spring.datasource.generate-unique-name=true",
|
||||
"spring.batch.jdbc.schema:classpath:batch/custom-schema-hsql.sql",
|
||||
"spring.batch.jdbc.tablePrefix:PREFIX_")
|
||||
.run(assertCustomPrefix());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void jdbcWithCustomPrefixWithDeprecatedProperties() {
|
||||
this.contextRunner.withUserConfiguration(DefaultConfiguration.class, EmbeddedDataSourceConfiguration.class)
|
||||
.withPropertyValues("spring.datasource.generate-unique-name=true",
|
||||
"spring.batch.schema:classpath:batch/custom-schema-hsql.sql",
|
||||
"spring.batch.tablePrefix:PREFIX_")
|
||||
.run(assertCustomPrefix());
|
||||
}
|
||||
|
||||
private ContextConsumer<AssertableApplicationContext> assertCustomPrefix() {
|
||||
return (context) -> {
|
||||
assertThat(new JdbcTemplate(context.getBean(DataSource.class))
|
||||
.queryForList("select * from PREFIX_JOB_EXECUTION")).isEmpty();
|
||||
assertThat(context.getBean(JobExplorer.class).findRunningJobExecutions("test")).isEmpty();
|
||||
assertThat(context.getBean(JobRepository.class).getLastJobExecution("test", new JobParameters())).isNull();
|
||||
};
|
||||
.run((context) -> {
|
||||
assertThat(new JdbcTemplate(context.getBean(DataSource.class))
|
||||
.queryForList("select * from PREFIX_JOB_EXECUTION")).isEmpty();
|
||||
assertThat(context.getBean(JobExplorer.class).findRunningJobExecutions("test")).isEmpty();
|
||||
assertThat(context.getBean(JobRepository.class).getLastJobExecution("test", new JobParameters()))
|
||||
.isNull();
|
||||
});
|
||||
}
|
||||
|
||||
@EnableBatchProcessing
|
||||
|
||||
@@ -291,53 +291,18 @@ class FlywayAutoConfigurationTests {
|
||||
@Test
|
||||
void changeLogDoesNotExist() {
|
||||
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
|
||||
.withPropertyValues("spring.flyway.locations:filesystem:no-such-dir").run((context) -> {
|
||||
assertThat(context).hasFailed();
|
||||
assertThat(context).getFailure().isInstanceOf(BeanCreationException.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void checkLocationsAllMissing() {
|
||||
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
|
||||
.withPropertyValues("spring.flyway.locations:classpath:db/missing1,classpath:db/migration2")
|
||||
.withPropertyValues("spring.flyway.fail-on-missing-locations=true",
|
||||
"spring.flyway.locations:filesystem:no-such-dir")
|
||||
.run((context) -> {
|
||||
assertThat(context).hasFailed();
|
||||
assertThat(context).getFailure().isInstanceOf(BeanCreationException.class);
|
||||
assertThat(context).getFailure().hasMessageContaining("Cannot find migration scripts in");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void checkLocationsAllExist() {
|
||||
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
|
||||
.withPropertyValues("spring.flyway.locations:classpath:db/changelog,classpath:db/migration")
|
||||
.run((context) -> assertThat(context).hasNotFailed());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void checkLocationsAllExistWithImplicitClasspathPrefix() {
|
||||
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
|
||||
.withPropertyValues("spring.flyway.locations:db/changelog,db/migration")
|
||||
.run((context) -> assertThat(context).hasNotFailed());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void checkLocationsAllExistWithFilesystemPrefix() {
|
||||
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
|
||||
.withPropertyValues("spring.flyway.locations:filesystem:src/test/resources/db/migration")
|
||||
.run((context) -> assertThat(context).hasNotFailed());
|
||||
}
|
||||
|
||||
@Test
|
||||
void failOnMissingLocationsAllMissing() {
|
||||
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
|
||||
.withPropertyValues("spring.flyway.check-location=false",
|
||||
"spring.flyway.fail-on-missing-locations=true")
|
||||
.withPropertyValues("spring.flyway.fail-on-missing-locations=true")
|
||||
.withPropertyValues("spring.flyway.locations:classpath:db/missing1,classpath:db/migration2")
|
||||
.run((context) -> {
|
||||
assertThat(context).hasFailed();
|
||||
@@ -349,8 +314,7 @@ class FlywayAutoConfigurationTests {
|
||||
@Test
|
||||
void failOnMissingLocationsAllExist() {
|
||||
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
|
||||
.withPropertyValues("spring.flyway.check-location=false",
|
||||
"spring.flyway.fail-on-missing-locations=true")
|
||||
.withPropertyValues("spring.flyway.fail-on-missing-locations=true")
|
||||
.withPropertyValues("spring.flyway.locations:classpath:db/changelog,classpath:db/migration")
|
||||
.run((context) -> assertThat(context).hasNotFailed());
|
||||
}
|
||||
@@ -358,8 +322,7 @@ class FlywayAutoConfigurationTests {
|
||||
@Test
|
||||
void failOnMissingLocationsAllExistWithImplicitClasspathPrefix() {
|
||||
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
|
||||
.withPropertyValues("spring.flyway.check-location=false",
|
||||
"spring.flyway.fail-on-missing-locations=true")
|
||||
.withPropertyValues("spring.flyway.fail-on-missing-locations=true")
|
||||
.withPropertyValues("spring.flyway.locations:db/changelog,db/migration")
|
||||
.run((context) -> assertThat(context).hasNotFailed());
|
||||
}
|
||||
@@ -367,8 +330,7 @@ class FlywayAutoConfigurationTests {
|
||||
@Test
|
||||
void failOnMissingLocationsAllExistWithFilesystemPrefix() {
|
||||
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class)
|
||||
.withPropertyValues("spring.flyway.check-location=false",
|
||||
"spring.flyway.fail-on-missing-locations=true")
|
||||
.withPropertyValues("spring.flyway.fail-on-missing-locations=true")
|
||||
.withPropertyValues("spring.flyway.locations:filesystem:src/test/resources/db/migration")
|
||||
.run((context) -> assertThat(context).hasNotFailed());
|
||||
}
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2021 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.flyway;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.diagnostics.FailureAnalysis;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link FlywayMigrationScriptMissingFailureAnalyzer}.
|
||||
*
|
||||
* @author Anand Shastri
|
||||
* @deprecated since 2.5.0 for removal in 2.7.0 as location checking is deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
class FlywayMigrationScriptMissingFailureAnalyzerTests {
|
||||
|
||||
@Test
|
||||
void analysisForMissingScriptLocation() {
|
||||
FailureAnalysis failureAnalysis = performAnalysis();
|
||||
assertThat(failureAnalysis.getDescription()).contains("no migration scripts location is configured");
|
||||
assertThat(failureAnalysis.getAction()).contains("Check your Flyway configuration");
|
||||
}
|
||||
|
||||
@Test
|
||||
void analysisForScriptLocationsNotFound() {
|
||||
FailureAnalysis failureAnalysis = performAnalysis("classpath:db/migration");
|
||||
assertThat(failureAnalysis.getDescription())
|
||||
.contains("none of the following migration scripts locations could be found")
|
||||
.contains("classpath:db/migration");
|
||||
assertThat(failureAnalysis.getAction())
|
||||
.contains("Review the locations above or check your Flyway configuration");
|
||||
}
|
||||
|
||||
private FailureAnalysis performAnalysis(String... locations) {
|
||||
FlywayMigrationScriptMissingException exception = new FlywayMigrationScriptMissingException(
|
||||
Arrays.asList(locations));
|
||||
return new FlywayMigrationScriptMissingFailureAnalyzer().analyze(exception);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2022 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.
|
||||
@@ -131,26 +131,6 @@ class ArtemisAutoConfigurationTests {
|
||||
getActiveMQConnectionFactory(getConnectionFactory(context)), "192.168.1.144", 9876));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void nativeConnectionFactoryCustomHost() {
|
||||
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||
.withPropertyValues("spring.artemis.mode:native", "spring.artemis.host:192.168.1.144",
|
||||
"spring.artemis.port:9876")
|
||||
.run((context) -> assertNettyConnectionFactory(
|
||||
getActiveMQConnectionFactory(getConnectionFactory(context)), "192.168.1.144", 9876));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void nativeConnectionFactoryCustomBrokerUrlAndHost() {
|
||||
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||
.withPropertyValues("spring.artemis.mode:native", "spring.artemis.host:192.168.1.144",
|
||||
"spring.artemis.port:9876", "spring.artemis.broker-url=tcp://192.168.1.221:6543")
|
||||
.run((context) -> assertNettyConnectionFactory(
|
||||
getActiveMQConnectionFactory(getConnectionFactory(context)), "192.168.1.221", 6543));
|
||||
}
|
||||
|
||||
@Test
|
||||
void nativeConnectionFactoryCredentials() {
|
||||
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||
|
||||
@@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@DirtiesContext
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.NONE, properties = { "env.FOO=There", "foo=World" })
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.NONE)
|
||||
class MustacheStandaloneIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
@@ -49,22 +49,6 @@ class MustacheStandaloneIntegrationTests {
|
||||
.isEqualTo("Hello: World");
|
||||
}
|
||||
|
||||
@Test
|
||||
void environmentCollectorCompoundKey() {
|
||||
assertThat(this.compiler.compile("Hello: {{env.foo}}").execute(new Object())).isEqualTo("Hello: There");
|
||||
}
|
||||
|
||||
@Test
|
||||
void environmentCollectorCompoundKeyStandard() {
|
||||
assertThat(this.compiler.standardsMode(true).compile("Hello: {{env.foo}}").execute(new Object()))
|
||||
.isEqualTo("Hello: There");
|
||||
}
|
||||
|
||||
@Test
|
||||
void environmentCollectorSimpleKey() {
|
||||
assertThat(this.compiler.compile("Hello: {{foo}}").execute(new Object())).isEqualTo("Hello: World");
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@Import({ MustacheAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class })
|
||||
static class Application {
|
||||
|
||||
@@ -1,214 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2021 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.r2dbc;
|
||||
|
||||
import io.r2dbc.spi.ConnectionFactoryOptions;
|
||||
import io.r2dbc.spi.Option;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.r2dbc.ConnectionFactoryOptionsInitializer.ConnectionFactoryBeanCreationException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Tests for {@link ConnectionFactoryBuilder}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Tadaya Tsuyukubo
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@Deprecated
|
||||
class ConnectionFactoryBuilderTests {
|
||||
|
||||
@Test
|
||||
void propertiesWithoutUrlAndNoAvailableEmbeddedConnectionShouldFail() {
|
||||
R2dbcProperties properties = new R2dbcProperties();
|
||||
assertThatThrownBy(() -> ConnectionFactoryBuilder.of(properties, () -> EmbeddedDatabaseConnection.NONE))
|
||||
.isInstanceOf(ConnectionFactoryBeanCreationException.class)
|
||||
.hasMessage("Failed to determine a suitable R2DBC Connection URL");
|
||||
}
|
||||
|
||||
@Test
|
||||
void connectionFactoryBeanCreationProvidesConnectionAndProperties() {
|
||||
R2dbcProperties properties = new R2dbcProperties();
|
||||
try {
|
||||
ConnectionFactoryBuilder.of(properties, () -> EmbeddedDatabaseConnection.NONE);
|
||||
fail("Should have thrown a " + ConnectionFactoryBeanCreationException.class.getName());
|
||||
}
|
||||
catch (ConnectionFactoryBeanCreationException ex) {
|
||||
assertThat(ex.getEmbeddedDatabaseConnection())
|
||||
.isEqualTo(org.springframework.boot.r2dbc.EmbeddedDatabaseConnection.NONE);
|
||||
assertThat(ex.getProperties()).isSameAs(properties);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void regularConnectionIsConfiguredAutomaticallyWithUrl() {
|
||||
R2dbcProperties properties = new R2dbcProperties();
|
||||
properties.setUrl("r2dbc:simple://:pool:");
|
||||
ConnectionFactoryOptions options = ConnectionFactoryBuilder
|
||||
.of(properties, () -> EmbeddedDatabaseConnection.NONE).buildOptions();
|
||||
assertThat(options.hasOption(ConnectionFactoryOptions.USER)).isFalse();
|
||||
assertThat(options.hasOption(ConnectionFactoryOptions.PASSWORD)).isFalse();
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DRIVER)).isEqualTo("simple");
|
||||
}
|
||||
|
||||
@Test
|
||||
void regularConnectionShouldInitializeUrlOptions() {
|
||||
R2dbcProperties properties = new R2dbcProperties();
|
||||
properties.setUrl("r2dbc:simple:proto://user:password@myhost:4711/mydatabase");
|
||||
ConnectionFactoryOptions options = buildOptions(properties);
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DRIVER)).isEqualTo("simple");
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.PROTOCOL)).isEqualTo("proto");
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.USER)).isEqualTo("user");
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.PASSWORD)).isEqualTo("password");
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.HOST)).isEqualTo("myhost");
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.PORT)).isEqualTo(4711);
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DATABASE)).isEqualTo("mydatabase");
|
||||
}
|
||||
|
||||
@Test
|
||||
void regularConnectionShouldUseUrlOptionsOverProperties() {
|
||||
R2dbcProperties properties = new R2dbcProperties();
|
||||
properties.setUrl("r2dbc:simple://user:password@myhost/mydatabase");
|
||||
properties.setUsername("another-user");
|
||||
properties.setPassword("another-password");
|
||||
properties.setName("another-database");
|
||||
ConnectionFactoryOptions options = buildOptions(properties);
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.USER)).isEqualTo("user");
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.PASSWORD)).isEqualTo("password");
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DATABASE)).isEqualTo("mydatabase");
|
||||
}
|
||||
|
||||
@Test
|
||||
void regularConnectionShouldUseDatabaseNameOverRandomName() {
|
||||
R2dbcProperties properties = new R2dbcProperties();
|
||||
properties.setUrl("r2dbc:simple://user:password@myhost/mydatabase");
|
||||
properties.setGenerateUniqueName(true);
|
||||
ConnectionFactoryOptions options = buildOptions(properties);
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DATABASE)).isEqualTo("mydatabase");
|
||||
}
|
||||
|
||||
@Test
|
||||
void regularConnectionWithRandomNameShouldIgnoreNameFromProperties() {
|
||||
R2dbcProperties properties = new R2dbcProperties();
|
||||
properties.setUrl("r2dbc:h2://host");
|
||||
properties.setName("test-database");
|
||||
properties.setGenerateUniqueName(true);
|
||||
ConnectionFactoryOptions options = buildOptions(properties);
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DATABASE)).isNotEqualTo("test-database")
|
||||
.isNotEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void regularConnectionShouldSetCustomDriverProperties() {
|
||||
R2dbcProperties properties = new R2dbcProperties();
|
||||
properties.setUrl("r2dbc:simple://user:password@myhost");
|
||||
properties.getProperties().put("simpleOne", "one");
|
||||
properties.getProperties().put("simpleTwo", "two");
|
||||
ConnectionFactoryOptions options = buildOptions(properties);
|
||||
assertThat(options.getRequiredValue(Option.<String>valueOf("simpleOne"))).isEqualTo("one");
|
||||
assertThat(options.getRequiredValue(Option.<String>valueOf("simpleTwo"))).isEqualTo("two");
|
||||
}
|
||||
|
||||
@Test
|
||||
void regularConnectionShouldUseBuilderValuesOverProperties() {
|
||||
R2dbcProperties properties = new R2dbcProperties();
|
||||
properties.setUrl("r2dbc:simple://user:password@myhost:47111/mydatabase");
|
||||
properties.setUsername("user");
|
||||
properties.setPassword("password");
|
||||
ConnectionFactoryOptions options = ConnectionFactoryBuilder
|
||||
.of(properties, () -> EmbeddedDatabaseConnection.NONE).username("another-user")
|
||||
.password("another-password").hostname("another-host").port(1234).database("another-database")
|
||||
.buildOptions();
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.USER)).isEqualTo("another-user");
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.PASSWORD)).isEqualTo("another-password");
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.HOST)).isEqualTo("another-host");
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.PORT)).isEqualTo(1234);
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DATABASE)).isEqualTo("another-database");
|
||||
}
|
||||
|
||||
@Test
|
||||
void embeddedConnectionIsConfiguredAutomaticallyWithoutUrl() {
|
||||
ConnectionFactoryOptions options = ConnectionFactoryBuilder
|
||||
.of(new R2dbcProperties(), () -> EmbeddedDatabaseConnection.H2).buildOptions();
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.USER)).isEqualTo("sa");
|
||||
assertThat(options.hasOption(ConnectionFactoryOptions.PASSWORD)).isFalse();
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DRIVER)).isEqualTo("h2");
|
||||
}
|
||||
|
||||
@Test
|
||||
void embeddedConnectionWithUsernameAndPassword() {
|
||||
R2dbcProperties properties = new R2dbcProperties();
|
||||
properties.setUsername("embedded");
|
||||
properties.setPassword("secret");
|
||||
ConnectionFactoryOptions options = ConnectionFactoryBuilder.of(properties, () -> EmbeddedDatabaseConnection.H2)
|
||||
.buildOptions();
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.USER)).isEqualTo("embedded");
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.PASSWORD)).isEqualTo("secret");
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DRIVER)).isEqualTo("h2");
|
||||
}
|
||||
|
||||
@Test
|
||||
void embeddedConnectionUseDefaultDatabaseName() {
|
||||
ConnectionFactoryOptions options = ConnectionFactoryBuilder
|
||||
.of(new R2dbcProperties(), () -> EmbeddedDatabaseConnection.H2).buildOptions();
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DATABASE)).isEqualTo("testdb");
|
||||
}
|
||||
|
||||
@Test
|
||||
void embeddedConnectionUseNameIfSet() {
|
||||
R2dbcProperties properties = new R2dbcProperties();
|
||||
properties.setName("test-database");
|
||||
ConnectionFactoryOptions options = buildOptions(properties);
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DATABASE)).isEqualTo("test-database");
|
||||
}
|
||||
|
||||
@Test
|
||||
void embeddedConnectionCanGenerateUniqueDatabaseName() {
|
||||
R2dbcProperties firstProperties = new R2dbcProperties();
|
||||
firstProperties.setGenerateUniqueName(true);
|
||||
ConnectionFactoryOptions options11 = buildOptions(firstProperties);
|
||||
ConnectionFactoryOptions options12 = buildOptions(firstProperties);
|
||||
assertThat(options11.getRequiredValue(ConnectionFactoryOptions.DATABASE))
|
||||
.isEqualTo(options12.getRequiredValue(ConnectionFactoryOptions.DATABASE));
|
||||
R2dbcProperties secondProperties = new R2dbcProperties();
|
||||
firstProperties.setGenerateUniqueName(true);
|
||||
ConnectionFactoryOptions options21 = buildOptions(secondProperties);
|
||||
ConnectionFactoryOptions options22 = buildOptions(secondProperties);
|
||||
assertThat(options21.getRequiredValue(ConnectionFactoryOptions.DATABASE))
|
||||
.isEqualTo(options22.getRequiredValue(ConnectionFactoryOptions.DATABASE));
|
||||
assertThat(options11.getRequiredValue(ConnectionFactoryOptions.DATABASE))
|
||||
.isNotEqualTo(options21.getRequiredValue(ConnectionFactoryOptions.DATABASE));
|
||||
}
|
||||
|
||||
@Test
|
||||
void embeddedConnectionShouldIgnoreNameIfRandomNameIsRequired() {
|
||||
R2dbcProperties properties = new R2dbcProperties();
|
||||
properties.setGenerateUniqueName(true);
|
||||
properties.setName("test-database");
|
||||
ConnectionFactoryOptions options = buildOptions(properties);
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DATABASE)).isNotEqualTo("test-database");
|
||||
}
|
||||
|
||||
private ConnectionFactoryOptions buildOptions(R2dbcProperties properties) {
|
||||
return ConnectionFactoryBuilder.of(properties, () -> EmbeddedDatabaseConnection.H2).buildOptions();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user