Skip to content

Commit a5b2778

Browse files
committed
Document how to use DataNeo4jTest with reactive access
Closes gh-23630
1 parent 27af908 commit a5b2778

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7605,6 +7605,9 @@ If that is not what you want, you can disable transaction management for a test
76057605
}
76067606
----
76077607

7608+
NOTE: Transactional tests are not supported with reactive access.
7609+
If you are using this style, you must configure `@DataNeo4jTest` tests as described above.
7610+
76087611

76097612

76107613
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-redis-test]]

spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
* configuration relevant to Neo4j tests.
4646
* <p>
4747
* By default, tests annotated with {@code @DataNeo4jTest} are transactional with the
48-
* usual test-related semantics (i.e. rollback by default).
48+
* usual test-related semantics (i.e. rollback by default). This feature is not supported
49+
* with reactive access so this should be disabled by annotating the test class with
50+
* {@code @Transactional(propagation = Propagation.NOT_SUPPORTED)}.
4951
* <p>
5052
* When using JUnit 4, this annotation should be used in combination with
5153
* {@code @RunWith(SpringRunner.class)}.

spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestReactiveIntegrationTests.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,25 @@
3131
import org.springframework.boot.test.context.TestConfiguration;
3232
import org.springframework.context.ApplicationContext;
3333
import org.springframework.context.annotation.Bean;
34-
import org.springframework.data.neo4j.core.DatabaseSelectionProvider;
34+
import org.springframework.data.neo4j.core.ReactiveDatabaseSelectionProvider;
3535
import org.springframework.data.neo4j.core.ReactiveNeo4jTemplate;
36-
import org.springframework.data.neo4j.core.transaction.Neo4jTransactionManager;
37-
import org.springframework.data.neo4j.repository.config.ReactiveNeo4jRepositoryConfigurationExtension;
36+
import org.springframework.data.neo4j.core.transaction.ReactiveNeo4jTransactionManager;
3837
import org.springframework.test.context.DynamicPropertyRegistry;
3938
import org.springframework.test.context.DynamicPropertySource;
39+
import org.springframework.transaction.annotation.Propagation;
40+
import org.springframework.transaction.annotation.Transactional;
4041

4142
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
4243

4344
/**
44-
* Integration tests for the reactive SDN/RX Neo4j test slice.
45+
* Integration tests for {@link DataNeo4jTest @DataNeo4jTest} with reactive style.
4546
*
4647
* @author Michael J. Simons
4748
* @author Scott Frederick
4849
* @since 2.4.0
4950
*/
5051
@DataNeo4jTest
52+
@Transactional(propagation = Propagation.NOT_SUPPORTED)
5153
@Testcontainers(disabledWithoutDocker = true)
5254
class DataNeo4jTestReactiveIntegrationTests {
5355

@@ -82,18 +84,13 @@ void didNotInjectExampleService() {
8284
.isThrownBy(() -> this.applicationContext.getBean(ExampleService.class));
8385
}
8486

85-
// Providing this bean fulfills a requirement that a @Transactional test has a
86-
// PlatformTransactionManager in the app context (enforced by
87-
// org.springframework.test.context.transaction.TransactionalTestExecutionListener).
88-
// Providing a ReactiveNeo4jTransactionManager would be more appropriate, but won't
89-
// allow the test to succeed.
9087
@TestConfiguration(proxyBeanMethods = false)
9188
static class ReactiveTransactionManagerConfiguration {
9289

93-
@Bean(ReactiveNeo4jRepositoryConfigurationExtension.DEFAULT_TRANSACTION_MANAGER_BEAN_NAME)
94-
Neo4jTransactionManager reactiveTransactionManager(Driver driver,
95-
DatabaseSelectionProvider databaseNameProvider) {
96-
return new Neo4jTransactionManager(driver, databaseNameProvider);
90+
@Bean
91+
ReactiveNeo4jTransactionManager reactiveTransactionManager(Driver driver,
92+
ReactiveDatabaseSelectionProvider databaseNameProvider) {
93+
return new ReactiveNeo4jTransactionManager(driver, databaseNameProvider);
9794
}
9895

9996
}

0 commit comments

Comments
 (0)