Skip to content
This repository was archived by the owner on Sep 1, 2023. It is now read-only.

Commit 2d526ed

Browse files
GH-24 - Update to Spring Boot 2.2.6.RELEASE.
1 parent 0e46a80 commit 2d526ed

File tree

15 files changed

+178
-105
lines changed

15 files changed

+178
-105
lines changed

README.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
:groupId: org.neo4j.driver
55
:artifactId: neo4j-java-driver-spring-boot-starter
66
:neo4j-java-driver-spring-boot-starter_version: 4.0-SNAPSHOT
7-
:spring-boot_version: 2.2.5.RELEASE
7+
:spring-boot_version: 2.2.6.RELEASE
88
:neo4j_version: 4.0.1
99
:config_prefix: org.neo4j.driver
1010
:gh_base: https://github.com/neo4j/neo4j-java-driver-spring-boot-starter

examples/dedicated-routing-driver/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<artifactId>spring-boot-starter-parent</artifactId>
66
<groupId>org.springframework.boot</groupId>
7-
<version>2.2.5.RELEASE</version>
7+
<version>2.2.6.RELEASE</version>
88
<relativePath></relativePath>
99
</parent>
1010

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[[neo4j-ogm-integration]]
22
= Neo4j-OGM Integration
33

4-
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.
55
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.
66
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.

examples/ogm-integration/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<artifactId>spring-boot-starter-parent</artifactId>
66
<groupId>org.springframework.boot</groupId>
7-
<version>2.2.5.RELEASE</version>
7+
<version>2.2.6.RELEASE</version>
88
<relativePath></relativePath>
99
</parent>
1010

examples/reactive-web/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<artifactId>spring-boot-starter-parent</artifactId>
66
<groupId>org.springframework.boot</groupId>
7-
<version>2.2.5.RELEASE</version>
7+
<version>2.2.6.RELEASE</version>
88
<relativePath></relativePath>
99
</parent>
1010

examples/simple/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<artifactId>spring-boot-starter-parent</artifactId>
66
<groupId>org.springframework.boot</groupId>
7-
<version>2.2.5.RELEASE</version>
7+
<version>2.2.6.RELEASE</version>
88
<relativePath></relativePath>
99
</parent>
1010

examples/testing-with-neo4j-harness/README.adoc

Lines changed: 24 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -88,34 +88,11 @@ The main question is always: *How to make Spring Boot aware that it should use d
8888

8989
The recommended approach is shown in `MoviesServiceAlt1Test`:
9090

91-
[source,java]
91+
[source,java,tabsize=4]
9292
[[test-harness-example-option1]]
9393
.MoviesServiceAlt1Test.java
9494
----
95-
@SpringBootTest
96-
class MoviesServiceAlt1Test {
97-
98-
@TestConfiguration // <.>
99-
static class TestHarnessConfig {
100-
101-
@Bean // <.>
102-
public Neo4j neo4j() {
103-
return Neo4jBuilders.newInProcessBuilder()
104-
.withDisabledServer() // No need for http
105-
.withFixture("CREATE (TheMatrixReloaded:Movie {title:'The Matrix Reloaded', released:2003, tagline:'Free your mind'})")
106-
.build();
107-
108-
// For enterprise use
109-
// return com.neo4j.harness.EnterpriseNeo4jBuilders.newInProcessBuilder()
110-
// .newInProcessBuilder()
111-
// .build();
112-
}
113-
}
114-
115-
@Test
116-
void testSomethingWithTheDriver(@Autowired Driver driver) {
117-
}
118-
}
95+
include::src/test/java/org/neo4j/doc/driver/springframework/boot/simple/MoviesServiceAlt1Test.java[tags=test-harness-example-option1]
11996
----
12097
<.> This is a test configuration only applicable for this test
12198
<.> This turns the embedded instance into a Spring Bean, bound to Springs lifecycle
@@ -128,24 +105,11 @@ This would be the recommended way of doing things.
128105

129106
`MoviesServiceAlt2Test.java` demonstrates the fully automatic configuration of test harness and driver:
130107

131-
[source,java]
108+
[source,java,tabsize=4]
132109
[[test-harness-example-option2]]
133110
.MoviesServiceAlt2Test.java
134111
----
135-
@SpringBootTest
136-
public class MoviesServiceAlt2Test {
137-
138-
@BeforeEach
139-
void prepareDatabase(@Autowired Neo4j neo4j) { // <.>
140-
neo4j.defaultDatabaseService().executeTransactionally(
141-
"CREATE (TheMatrix:Movie {title:'The Matrix', released:1999, tagline:'Welcome to the Real World'})"
142-
);
143-
}
144-
145-
@Test
146-
void testSomethingWithTheDriver(@Autowired Driver driver) {
147-
}
148-
}
112+
include::src/test/java/org/neo4j/doc/driver/springframework/boot/simple/MoviesServiceAlt2Test.java[tags=test-harness-example-option2]
149113
----
150114
<.> As you don't have access to the builder, you have to provide your fixtures through the embedded database service.
151115

@@ -162,55 +126,38 @@ NOTE: You don't actually need `neo4j-java-driver-test-harness-spring-boot-autoco
162126
Test harness - either 3.5.x or 4.0.x or Community or enterprise edition on the classpath.
163127
If you have the test harness autoconfiguration support on the classpath, you have to explicitly disable it.
164128

165-
[source,java]
129+
[source,java,tabsize=4]
166130
[[test-harness-example-option3]]
167131
.MoviesServiceAlt3Test.java
168132
----
169-
@SpringBootTest
170-
@EnableAutoConfiguration(exclude = { Neo4jTestHarnessAutoConfiguration.class }) // <.>
171-
@ContextConfiguration(initializers = { MoviesServiceTest.Initializer.class })
172-
class MoviesServiceAlt3Test {
173-
174-
private static Neo4j embeddedDatabaseServer;
175-
176-
@BeforeAll
177-
static void initializeNeo4j() { // <.>
178-
embeddedDatabaseServer = TestServerBuilders
179-
.newInProcessBuilder()
180-
.withDisabledServer() // <.>
181-
.withFixture("CREATE (TheMatrix:Movie {title:'The Matrix', released:1999, tagline:'Welcome to the Real World'})")
182-
.newServer();
183-
}
184-
185-
@AfterAll
186-
static void closeNeo4j() { // <.>
187-
embeddedDatabaseServer.close();
188-
}
189-
190-
static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
191-
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
192-
193-
TestPropertyValues.of( // <.>
194-
"org.neo4j.driver.uri=" + embeddedDatabaseServer.boltURI().toString(),
195-
"org.neo4j.driver.authentication.password="
196-
).applyTo(configurableApplicationContext.getEnvironment());
197-
}
198-
}
199-
200-
@Test
201-
void testSomethingWithTheDriver(@Autowired Driver driver) {
202-
}
203-
}
133+
include::src/test/java/org/neo4j/doc/driver/springframework/boot/simple/MoviesServiceAlt3Test.java[tags=test-harness-example-option3]
204134
----
205135
<.> Disable the autoconfiguration (only needed if you have `neo4j-java-driver-test-harness-spring-boot-autoconfigure` on the classpath)
206136
<.> Use a JUnit `BeforeAll` to boot Neo4j
207137
<.> 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+)
208138
<.> 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.
210141

211142
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.
212143
The downside of it: You have to configure a lot of stuff manually and your mileage may vary.
213144

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:
151+
152+
[source,java,tabsize=4]
153+
[[test-harness-example-option4]]
154+
.MoviesServiceAlt4Test.java
155+
----
156+
include::src/test/java/org/neo4j/doc/driver/springframework/boot/simple/MoviesServiceAlt4Test.java[tags=test-harness-example-option4]
157+
----
158+
159+
160+
214161
=== Running your own driver bean
215162

216163
You can always fall back to create your own driver bean, but that actually disables the starter for the driver.

examples/testing-with-neo4j-harness/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<artifactId>spring-boot-starter-parent</artifactId>
66
<groupId>org.springframework.boot</groupId>
7-
<version>2.2.5.RELEASE</version>
7+
<version>2.2.6.RELEASE</version>
88
<relativePath></relativePath>
99
</parent>
1010

examples/testing-with-neo4j-harness/src/test/java/org/neo4j/doc/driver/springframework/boot/simple/MoviesServiceAlt1Test.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.assertj.core.api.Assertions.*;
2222

2323
import org.junit.jupiter.api.Test;
24+
import org.neo4j.driver.Driver;
2425
import org.neo4j.harness.Neo4j;
2526
import org.neo4j.harness.Neo4jBuilders;
2627
import org.springframework.beans.factory.annotation.Autowired;
@@ -33,13 +34,14 @@
3334
* 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.
3435
* <p>If you already have the harness support on the classpath, this would actually be the recommended version of doing things.
3536
*/
37+
// tag::test-harness-example-option1[]
3638
@SpringBootTest
3739
class MoviesServiceAlt1Test {
3840

39-
@TestConfiguration
41+
@TestConfiguration // <.>
4042
static class TestHarnessConfig {
4143

42-
@Bean
44+
@Bean // <.>
4345
public Neo4j neo4j() {
4446
return Neo4jBuilders.newInProcessBuilder()
4547
.withDisabledServer() // No need for http
@@ -49,17 +51,27 @@ public Neo4j neo4j() {
4951
+ "CREATE (TheMatrixRevolutions:Movie {title:'The Matrix Revolutions', released:2003, tagline:'Everything that has a beginning has an end'})\n"
5052
)
5153
.build();
54+
55+
// For enterprise use
56+
// return com.neo4j.harness.EnterpriseNeo4jBuilders.newInProcessBuilder()
57+
// .newInProcessBuilder()
58+
// .build();
5259
}
5360
}
5461

55-
@Autowired
56-
private MoviesService moviesService;
62+
@Test
63+
void testSomethingWithTheDriver(@Autowired Driver driver) {
64+
}
65+
// end::test-harness-example-option1[]
5766

5867
@Test
59-
void shouldRetrieveMovieTitles() {
68+
void shouldRetrieveMovieTitles(@Autowired MoviesService moviesService) {
6069

6170
assertThat(moviesService.getMovieTitles())
6271
.hasSize(3)
6372
.contains("The Matrix");
6473
}
74+
75+
// tag::test-harness-example-option1[]
6576
}
77+
// end::test-harness-example-option1[]

examples/testing-with-neo4j-harness/src/test/java/org/neo4j/doc/driver/springframework/boot/simple/MoviesServiceAlt2Test.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
import org.junit.jupiter.api.BeforeEach;
2424
import org.junit.jupiter.api.Test;
25+
import org.neo4j.driver.Driver;
26+
import org.neo4j.graphdb.Transaction;
2527
import org.neo4j.harness.Neo4j;
2628
import org.springframework.beans.factory.annotation.Autowired;
2729
import org.springframework.boot.test.context.SpringBootTest;
@@ -31,26 +33,38 @@
3133
*
3234
* @author Michael J. Simons
3335
*/
36+
// tag::test-harness-example-option2[]
3437
@SpringBootTest
3538
public class MoviesServiceAlt2Test {
3639

3740
@Autowired
3841
private MoviesService moviesService;
3942

4043
@BeforeEach
41-
void prepareDatabase(@Autowired Neo4j neo4j) {
42-
neo4j.defaultDatabaseService().executeTransactionally(""
43-
+ "CREATE (TheMatrix:Movie {title:'The Matrix', released:1999, tagline:'Welcome to the Real World'})\n"
44-
+ "CREATE (TheMatrixReloaded:Movie {title:'The Matrix Reloaded', released:2003, tagline:'Free your mind'})\n"
45-
+ "CREATE (TheMatrixRevolutions:Movie {title:'The Matrix Revolutions', released:2003, tagline:'Everything that has a beginning has an end'})\n"
46-
);
44+
void prepareDatabase(@Autowired Neo4j neo4j) { // <.>
45+
try(Transaction transaction = neo4j.defaultDatabaseService().beginTx()) {
46+
transaction.execute("MATCH (n) DETACH DELETE n");
47+
transaction.execute(""
48+
+ "CREATE (TheMatrix:Movie {title:'The Matrix', released:1999, tagline:'Welcome to the Real World'})\n"
49+
+ "CREATE (TheMatrixReloaded:Movie {title:'The Matrix Reloaded', released:2003, tagline:'Free your mind'})\n"
50+
+ "CREATE (TheMatrixRevolutions:Movie {title:'The Matrix Revolutions', released:2003, tagline:'Everything that has a beginning has an end'})\n"
51+
);
52+
transaction.commit();
53+
}
4754
}
4855

56+
@Test
57+
void testSomethingWithTheDriver(@Autowired Driver driver) {
58+
}
59+
// end::test-harness-example-option2[]
60+
4961
@Test
5062
void shouldRetrieveMovieTitles() {
5163

5264
assertThat(moviesService.getMovieTitles())
5365
.hasSize(3)
5466
.contains("The Matrix");
5567
}
68+
// tag::test-harness-example-option2[]
5669
}
70+
// end::test-harness-example-option2[]

0 commit comments

Comments
 (0)