From a5b27789c0bcc7ee65e798be68dbb44ba0e2d05b Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 14 Oct 2020 14:04:58 +0200 Subject: [PATCH] Document how to use DataNeo4jTest with reactive access Closes gh-23630 --- .../docs/asciidoc/spring-boot-features.adoc | 3 +++ .../data/neo4j/DataNeo4jTest.java | 4 +++- ...DataNeo4jTestReactiveIntegrationTests.java | 23 ++++++++----------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc index a716d8d388f..20a807dcdfc 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc @@ -7605,6 +7605,9 @@ If that is not what you want, you can disable transaction management for a test } ---- +NOTE: Transactional tests are not supported with reactive access. +If you are using this style, you must configure `@DataNeo4jTest` tests as described above. + [[boot-features-testing-spring-boot-applications-testing-autoconfigured-redis-test]] diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTest.java index 051a1eb1197..15bc29bf6a5 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTest.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTest.java @@ -45,7 +45,9 @@ import org.springframework.transaction.annotation.Transactional; * configuration relevant to Neo4j tests. *

* By default, tests annotated with {@code @DataNeo4jTest} are transactional with the - * usual test-related semantics (i.e. rollback by default). + * usual test-related semantics (i.e. rollback by default). This feature is not supported + * with reactive access so this should be disabled by annotating the test class with + * {@code @Transactional(propagation = Propagation.NOT_SUPPORTED)}. *

* When using JUnit 4, this annotation should be used in combination with * {@code @RunWith(SpringRunner.class)}. diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestReactiveIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestReactiveIntegrationTests.java index 0a9e47f9018..5f5f12eb4b4 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestReactiveIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestReactiveIntegrationTests.java @@ -31,23 +31,25 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; -import org.springframework.data.neo4j.core.DatabaseSelectionProvider; +import org.springframework.data.neo4j.core.ReactiveDatabaseSelectionProvider; import org.springframework.data.neo4j.core.ReactiveNeo4jTemplate; -import org.springframework.data.neo4j.core.transaction.Neo4jTransactionManager; -import org.springframework.data.neo4j.repository.config.ReactiveNeo4jRepositoryConfigurationExtension; +import org.springframework.data.neo4j.core.transaction.ReactiveNeo4jTransactionManager; import org.springframework.test.context.DynamicPropertyRegistry; import org.springframework.test.context.DynamicPropertySource; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** - * Integration tests for the reactive SDN/RX Neo4j test slice. + * Integration tests for {@link DataNeo4jTest @DataNeo4jTest} with reactive style. * * @author Michael J. Simons * @author Scott Frederick * @since 2.4.0 */ @DataNeo4jTest +@Transactional(propagation = Propagation.NOT_SUPPORTED) @Testcontainers(disabledWithoutDocker = true) class DataNeo4jTestReactiveIntegrationTests { @@ -82,18 +84,13 @@ class DataNeo4jTestReactiveIntegrationTests { .isThrownBy(() -> this.applicationContext.getBean(ExampleService.class)); } - // Providing this bean fulfills a requirement that a @Transactional test has a - // PlatformTransactionManager in the app context (enforced by - // org.springframework.test.context.transaction.TransactionalTestExecutionListener). - // Providing a ReactiveNeo4jTransactionManager would be more appropriate, but won't - // allow the test to succeed. @TestConfiguration(proxyBeanMethods = false) static class ReactiveTransactionManagerConfiguration { - @Bean(ReactiveNeo4jRepositoryConfigurationExtension.DEFAULT_TRANSACTION_MANAGER_BEAN_NAME) - Neo4jTransactionManager reactiveTransactionManager(Driver driver, - DatabaseSelectionProvider databaseNameProvider) { - return new Neo4jTransactionManager(driver, databaseNameProvider); + @Bean + ReactiveNeo4jTransactionManager reactiveTransactionManager(Driver driver, + ReactiveDatabaseSelectionProvider databaseNameProvider) { + return new ReactiveNeo4jTransactionManager(driver, databaseNameProvider); } }