Skip to content

Commit ce553e4

Browse files
committed
Add TestContainers
This will allow the tests to run in the CI and locally Signed-off-by: Josh Cummings <[email protected]>
1 parent c20a072 commit ce553e4

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

README.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ that the new account password be changed. To do so, run the following command:
6969

7070
====
7171
----
72-
$ curl -v -u neo4j:neo4j POST localhost:7474/user/neo4j/password -H "Content-type:application/json" -d "{\"password\":\"secret\"}"
72+
$ curl -v -u neo4j:neo4j POST localhost:7474/user/neo4j/password -H "Content-type:application/json" -d "{\"password\":\"a_strong_password\"}"
7373
----
7474
====
7575

76-
This changes the password from `neo4j` to `secret` (something to NOT DO in production!)
76+
This changes the password from `neo4j` to `a_strong_password` (certainly use a real password!)
7777
With that completed, you should be ready to run this guide.
7878

7979
== Starting with Spring Initializr
@@ -107,7 +107,7 @@ include::complete/src/main/resources/application.properties[]
107107
----
108108
====
109109

110-
This includes the default username (`neo4j`) and the newly set password (`secret`) that
110+
This includes the default username (`neo4j`) and the newly set password (`a_strong_password`) that
111111
you set earlier.
112112

113113
WARNING: Do NOT store real credentials in your source repository. Instead, configure them

complete/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ dependencies {
1717
implementation 'org.springframework.boot:spring-boot-starter-data-neo4j'
1818
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
1919
testImplementation 'org.springframework.boot:spring-boot-starter-test'
20+
testImplementation 'org.springframework.boot:spring-boot-testcontainers'
21+
testImplementation 'org.testcontainers:junit-jupiter'
22+
testImplementation 'org.testcontainers:neo4j'
2023
}
2124

2225
test {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
spring.neo4j.uri=bolt://localhost:7687
22
spring.neo4j.authentication.username=neo4j
3-
spring.neo4j.authentication.password=secret
3+
spring.neo4j.authentication.password=a_strong_password

complete/src/test/java/com/example/accessingneo4jdatarest/AccessingNeo4jDataRestApplicationTests.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,39 @@
1818

1919
import org.junit.jupiter.api.BeforeEach;
2020
import org.junit.jupiter.api.Test;
21+
import org.testcontainers.containers.Neo4jContainer;
22+
import org.testcontainers.junit.jupiter.Container;
23+
import org.testcontainers.junit.jupiter.Testcontainers;
24+
import org.testcontainers.utility.DockerImageName;
2125

2226
import org.springframework.beans.factory.annotation.Autowired;
23-
import org.springframework.boot.autoconfigure.data.neo4j.Neo4jDataAutoConfiguration;
2427
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
2528
import org.springframework.boot.test.context.SpringBootTest;
26-
import org.springframework.context.annotation.Import;
29+
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
2730
import org.springframework.test.web.servlet.MockMvc;
2831
import org.springframework.test.web.servlet.MvcResult;
2932

30-
import static org.hamcrest.Matchers.*;
31-
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
32-
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*;
33-
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
34-
33+
import static org.hamcrest.Matchers.containsString;
34+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
35+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
36+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
37+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
38+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
39+
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
40+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
41+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
42+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
43+
44+
@Testcontainers
3545
@SpringBootTest
3646
@AutoConfigureMockMvc
3747
public class AccessingNeo4jDataRestApplicationTests {
3848

49+
@Container
50+
@ServiceConnection
51+
static Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>(DockerImageName.parse("neo4j:latest"))
52+
.withAdminPassword("a_strong_password");
53+
3954
@Autowired
4055
private MockMvc mockMvc;
4156

0 commit comments

Comments
 (0)