From dcc0ca0df988164370d2090384a223f1fe2b7c1e Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 18 Jan 2021 10:58:43 +0100 Subject: [PATCH] Polish contribution See gh-24862 --- .../jooq/JooqAutoConfiguration.java | 4 +- .../jooq/JooqAutoConfigurationTests.java | 41 +++++++++++++++---- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfiguration.java index d9f080c03e..91e4bc5de0 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfiguration.java @@ -95,7 +95,7 @@ public class JooqAutoConfiguration { @Bean @ConditionalOnMissingBean(org.jooq.Configuration.class) public DefaultConfiguration jooqConfiguration(JooqProperties properties, ConnectionProvider connectionProvider, - ObjectProvider executeListenerProviders, DataSource dataSource, + DataSource dataSource, ObjectProvider executeListenerProviders, ObjectProvider configurationCustomizers) { DefaultConfiguration configuration = new DefaultConfiguration(); configuration.set(properties.determineSqlDialect(dataSource)); @@ -107,7 +107,7 @@ public class JooqAutoConfiguration { @Bean @Deprecated - public DefaultConfigurationCustomizer jooQProviderDefaultConfigurationCustomizer( + public DefaultConfigurationCustomizer jooqProvidersDefaultConfigurationCustomizer( ObjectProvider transactionProvider, ObjectProvider recordMapperProvider, ObjectProvider recordUnmapperProvider, ObjectProvider settings, diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfigurationTests.java index 767990ba10..938327660e 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfigurationTests.java @@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.jooq; import javax.sql.DataSource; import org.jooq.CharsetProvider; +import org.jooq.ConnectionProvider; import org.jooq.ConverterProvider; import org.jooq.DSLContext; import org.jooq.ExecuteListener; @@ -31,6 +32,7 @@ import org.jooq.SQLDialect; import org.jooq.TransactionListenerProvider; import org.jooq.TransactionalRunnable; import org.jooq.VisitListenerProvider; +import org.jooq.impl.DataSourceConnectionProvider; import org.jooq.impl.DefaultExecuteListenerProvider; import org.junit.jupiter.api.Test; @@ -42,6 +44,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.Order; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy; import org.springframework.transaction.PlatformTransactionManager; import static org.assertj.core.api.Assertions.assertThat; @@ -101,7 +104,37 @@ class JooqAutoConfigurationTests { "insert into jooqtest (name) values ('foo');"))); dsl.transaction(new AssertFetch(dsl, "select count(*) as total from jooqtest_tx;", "1")); }); + } + + @Test + void jooqWithDefaultConnectionProvider() { + this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class).run((context) -> { + DSLContext dsl = context.getBean(DSLContext.class); + ConnectionProvider connectionProvider = dsl.configuration().connectionProvider(); + assertThat(connectionProvider).isInstanceOf(DataSourceConnectionProvider.class); + DataSource connectionProviderDataSource = ((DataSourceConnectionProvider) connectionProvider).dataSource(); + assertThat(connectionProviderDataSource).isInstanceOf(TransactionAwareDataSourceProxy.class); + }); + } + + @Test + void jooqWithDefaultExecuteListenerProvider() { + this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class).run((context) -> { + DSLContext dsl = context.getBean(DSLContext.class); + assertThat(dsl.configuration().executeListenerProviders()).hasSize(1); + }); + } + @Test + void jooqWithSeveralExecuteListenerProviders() { + this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class, TestExecuteListenerProvider.class) + .run((context) -> { + DSLContext dsl = context.getBean(DSLContext.class); + ExecuteListenerProvider[] executeListenerProviders = dsl.configuration().executeListenerProviders(); + assertThat(executeListenerProviders).hasSize(2); + assertThat(executeListenerProviders[0]).isInstanceOf(DefaultExecuteListenerProvider.class); + assertThat(executeListenerProviders[1]).isInstanceOf(TestExecuteListenerProvider.class); + }); } @Test @@ -129,9 +162,7 @@ class JooqAutoConfigurationTests { VisitListenerProvider visitListenerProvider = mock(VisitListenerProvider.class); TransactionListenerProvider transactionListenerProvider = mock(TransactionListenerProvider.class); ExecutorProvider executorProvider = mock(ExecutorProvider.class); - this.contextRunner - .withUserConfiguration(JooqDataSourceConfiguration.class, TxManagerConfiguration.class, - TestExecuteListenerProvider.class) + this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class, TxManagerConfiguration.class) .withBean(RecordMapperProvider.class, () -> recordMapperProvider) .withBean(RecordUnmapperProvider.class, () -> recordUnmapperProvider) .withBean(RecordListenerProvider.class, () -> recordListenerProvider) @@ -143,10 +174,6 @@ class JooqAutoConfigurationTests { assertThat(dsl.configuration().recordUnmapperProvider()).isSameAs(recordUnmapperProvider); assertThat(dsl.configuration().executorProvider()).isSameAs(executorProvider); assertThat(dsl.configuration().recordListenerProviders()).containsExactly(recordListenerProvider); - ExecuteListenerProvider[] executeListenerProviders = dsl.configuration().executeListenerProviders(); - assertThat(executeListenerProviders).hasSize(2); - assertThat(executeListenerProviders[0]).isInstanceOf(DefaultExecuteListenerProvider.class); - assertThat(executeListenerProviders[1]).isInstanceOf(TestExecuteListenerProvider.class); assertThat(dsl.configuration().visitListenerProviders()).containsExactly(visitListenerProvider); assertThat(dsl.configuration().transactionListenerProviders()) .containsExactly(transactionListenerProvider);