You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 1, 2023. It is now read-only.
The current Spring Boot starter you get on https://start.spring.io/#!type=maven-project&language=java&platformVersion=2.2.5.RELEASE&packaging=jar&jvmVersion=1.8&groupId=com.example&artifactId=demo&name=demo&description=Demo%20project%20for%20Spring%20Boot&packageName=com.example.demo&dependencies=data-neo4j[start.spring.io] recognizes the driver bean created by this starter here.
4
+
The current Spring Boot starter you get on https://start.spring.io/#!type=maven-project&language=java&platformVersion=2.2.6.RELEASE&packaging=jar&jvmVersion=1.8&groupId=com.example&artifactId=demo&name=demo&description=Demo%20project%20for%20Spring%20Boot&packageName=com.example.demo&dependencies=data-neo4j[start.spring.io] recognizes the driver bean created by this starter here.
5
5
That means you can add this starter via `{groupId}:{artifactId}:{neo4j-java-driver-spring-boot-starter_version}` and use the properties under `{config_prefix}` to configure the connection.
6
6
Thus you don't have to work your way into Neo4j-OGM to manipulate the encapsulated driver but inject a correctly configured driver bean into the Neo4j-OGM session factory.
<.> Disable the autoconfiguration (only needed if you have `neo4j-java-driver-test-harness-spring-boot-autoconfigure` on the classpath)
206
136
<.> Use a JUnit `BeforeAll` to boot Neo4j
207
137
<.> The driver uses only the Bolt port, not the http port, so we don't need the embedded webserver (that option is only available in Neo4j Harness 4.0+)
208
138
<.> Close it in an `AfterAll`
209
-
<.> This the essential part: Apply the new configuration values
139
+
<.> This the essential part: Apply the new configuration values.
140
+
This uses an `ApplicationContextInitializer` which can inject `TestPropertyValues` into the context before the context starts.
210
141
211
142
This is a good solution It works well with both Community and enterprise edition and decouples the creation of the server from configuring the client.
212
143
The downside of it: You have to configure a lot of stuff manually and your mileage may vary.
213
144
145
+
Since Spring Boot 2.2.6 you have an additional option:
146
+
As of Spring Framework 5.2.5, the TestContext framework provides support for dynamic property sources via the `@DynamicPropertySource` annotation.
147
+
This annotation can be used in integration tests that need to add properties with dynamic values.
148
+
For more information, have a look at the https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/testing.html#testcontext-ctx-management-dynamic-property-sources[Spring Framework reference].
149
+
150
+
<<test-harness-example-option4>> is conceptionally the same variant as <<test-harness-example-option3>> but much more concise:
Copy file name to clipboardExpand all lines: examples/testing-with-neo4j-harness/src/test/java/org/neo4j/doc/driver/springframework/boot/simple/MoviesServiceAlt1Test.java
* this is just one of them. With `neo4j-java-driver-spring-boot-test-harness-4x-support` on the class path, the automatic configuration will pick this up.
34
35
* <p>If you already have the harness support on the classpath, this would actually be the recommended version of doing things.
35
36
*/
37
+
// tag::test-harness-example-option1[]
36
38
@SpringBootTest
37
39
classMoviesServiceAlt1Test {
38
40
39
-
@TestConfiguration
41
+
@TestConfiguration// <.>
40
42
staticclassTestHarnessConfig {
41
43
42
-
@Bean
44
+
@Bean// <.>
43
45
publicNeo4jneo4j() {
44
46
returnNeo4jBuilders.newInProcessBuilder()
45
47
.withDisabledServer() // No need for http
@@ -49,17 +51,27 @@ public Neo4j neo4j() {
49
51
+ "CREATE (TheMatrixRevolutions:Movie {title:'The Matrix Revolutions', released:2003, tagline:'Everything that has a beginning has an end'})\n"
Copy file name to clipboardExpand all lines: examples/testing-with-neo4j-harness/src/test/java/org/neo4j/doc/driver/springframework/boot/simple/MoviesServiceAlt2Test.java
0 commit comments