Document how to use DataNeo4jTest with reactive access
Closes gh-23630
This commit is contained in:
parent
27af908b99
commit
a5b27789c0
|
|
@ -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]]
|
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-redis-test]]
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,9 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
* configuration relevant to Neo4j tests.
|
* configuration relevant to Neo4j tests.
|
||||||
* <p>
|
* <p>
|
||||||
* By default, tests annotated with {@code @DataNeo4jTest} are transactional with the
|
* 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)}.
|
||||||
* <p>
|
* <p>
|
||||||
* When using JUnit 4, this annotation should be used in combination with
|
* When using JUnit 4, this annotation should be used in combination with
|
||||||
* {@code @RunWith(SpringRunner.class)}.
|
* {@code @RunWith(SpringRunner.class)}.
|
||||||
|
|
|
||||||
|
|
@ -31,23 +31,25 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.TestConfiguration;
|
import org.springframework.boot.test.context.TestConfiguration;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
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.ReactiveNeo4jTemplate;
|
||||||
import org.springframework.data.neo4j.core.transaction.Neo4jTransactionManager;
|
import org.springframework.data.neo4j.core.transaction.ReactiveNeo4jTransactionManager;
|
||||||
import org.springframework.data.neo4j.repository.config.ReactiveNeo4jRepositoryConfigurationExtension;
|
|
||||||
import org.springframework.test.context.DynamicPropertyRegistry;
|
import org.springframework.test.context.DynamicPropertyRegistry;
|
||||||
import org.springframework.test.context.DynamicPropertySource;
|
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;
|
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 Michael J. Simons
|
||||||
* @author Scott Frederick
|
* @author Scott Frederick
|
||||||
* @since 2.4.0
|
* @since 2.4.0
|
||||||
*/
|
*/
|
||||||
@DataNeo4jTest
|
@DataNeo4jTest
|
||||||
|
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||||
@Testcontainers(disabledWithoutDocker = true)
|
@Testcontainers(disabledWithoutDocker = true)
|
||||||
class DataNeo4jTestReactiveIntegrationTests {
|
class DataNeo4jTestReactiveIntegrationTests {
|
||||||
|
|
||||||
|
|
@ -82,18 +84,13 @@ class DataNeo4jTestReactiveIntegrationTests {
|
||||||
.isThrownBy(() -> this.applicationContext.getBean(ExampleService.class));
|
.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)
|
@TestConfiguration(proxyBeanMethods = false)
|
||||||
static class ReactiveTransactionManagerConfiguration {
|
static class ReactiveTransactionManagerConfiguration {
|
||||||
|
|
||||||
@Bean(ReactiveNeo4jRepositoryConfigurationExtension.DEFAULT_TRANSACTION_MANAGER_BEAN_NAME)
|
@Bean
|
||||||
Neo4jTransactionManager reactiveTransactionManager(Driver driver,
|
ReactiveNeo4jTransactionManager reactiveTransactionManager(Driver driver,
|
||||||
DatabaseSelectionProvider databaseNameProvider) {
|
ReactiveDatabaseSelectionProvider databaseNameProvider) {
|
||||||
return new Neo4jTransactionManager(driver, databaseNameProvider);
|
return new ReactiveNeo4jTransactionManager(driver, databaseNameProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue