Improve error message for non-options-capable ConnectionFactory

Fixes gh-26977
This commit is contained in:
Andy Wilkinson 2021-07-08 09:17:55 +01:00
parent de260148b8
commit 283b4a6ed2
2 changed files with 6 additions and 2 deletions

View File

@ -101,7 +101,9 @@ public enum EmbeddedDatabaseConnection {
OptionsCapableConnectionFactory optionsCapable = OptionsCapableConnectionFactory.unwrapFrom(connectionFactory); OptionsCapableConnectionFactory optionsCapable = OptionsCapableConnectionFactory.unwrapFrom(connectionFactory);
if (optionsCapable == null) { if (optionsCapable == null) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Cannot determine database's type as ConnectionFactory is not options-capable"); "Cannot determine database's type as ConnectionFactory is not options-capable. To be "
+ "options-capable, a ConnectionFactory should be created with "
+ ConnectionFactoryBuilder.class.getName());
} }
ConnectionFactoryOptions options = optionsCapable.getOptions(); ConnectionFactoryOptions options = optionsCapable.getOptions();
for (EmbeddedDatabaseConnection candidate : values()) { for (EmbeddedDatabaseConnection candidate : values()) {

View File

@ -89,7 +89,9 @@ class EmbeddedDatabaseConnectionTests {
assertThatIllegalArgumentException() assertThatIllegalArgumentException()
.isThrownBy(() -> EmbeddedDatabaseConnection .isThrownBy(() -> EmbeddedDatabaseConnection
.isEmbedded(ConnectionFactories.get("r2dbc:pool:h2:mem:///" + UUID.randomUUID()))) .isEmbedded(ConnectionFactories.get("r2dbc:pool:h2:mem:///" + UUID.randomUUID())))
.withMessage("Cannot determine database's type as ConnectionFactory is not options-capable"); .withMessage("Cannot determine database's type as ConnectionFactory is not options-capable. To be "
+ "options-capable, a ConnectionFactory should be created with "
+ "org.springframework.boot.r2dbc.ConnectionFactoryBuilder");
} }
static Stream<Arguments> urlParameters() { static Stream<Arguments> urlParameters() {