Switch Neo4j example to use Testcontainers as the Neo4j server isn't Java 16-ready.

See #606.
This commit is contained in:
Mark Paluch
2021-04-29 12:14:03 +02:00
parent 6913f7ec5f
commit 430643bb47
4 changed files with 29 additions and 28 deletions

View File

@@ -20,13 +20,6 @@
<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>
<dependency>
<groupId>org.neo4j.test</groupId>
<artifactId>neo4j-harness</artifactId>
<version>3.5.18</version> <!-- We can switch this to 4.x when the examples are build with JDK 11. -->
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@@ -44,7 +44,7 @@ public class Actor {
public void actedIn(Movie movie, List<String> roleNames) {
Roles movieRoles = new Roles(roleNames);
var movieRoles = new Roles(roleNames);
movieRoles.setMovie(movie);
this.roles.add(movieRoles);

View File

@@ -20,43 +20,43 @@ import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
import java.util.Collections;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.neo4j.harness.ServerControls;
import org.neo4j.harness.TestServerBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.testcontainers.containers.Neo4jContainer;
/**
* Simple integration test demonstrating the use of the ActorRepository
*
* @author Luanne Misquitta
* @author Oliver Gierke
* @author Michael J. Simons
* @author Mark Paluch
*/
@SpringBootTest
class ActorRepositoryIntegrationTest {
private static final ServerControls neo4j = TestServerBuilders
.newInProcessBuilder().newServer();
private static Neo4jContainer container;
@AfterAll
@BeforeAll
static void stopNeo4j() {
if (neo4j != null) {
neo4j.close();
}
container = new Neo4jContainer("neo4j:4.2.5");
container.start();
}
@DynamicPropertySource
static void neo4jProperties(DynamicPropertyRegistry registry) {
registry.add("spring.neo4j.uri", neo4j::boltURI);
registry.add("spring.neo4j.uri", container::getBoltUrl);
registry.add("spring.neo4j.authentication.username", () -> "neo4j");
registry.add("spring.neo4j.authentication.password", () -> "password");
registry.add("spring.neo4j.authentication.password", container::getAdminPassword);
}
@SpringBootApplication
@@ -68,9 +68,9 @@ class ActorRepositoryIntegrationTest {
@Test // #131
void shouldBeAbleToSaveAndLoadActor() {
Movie goblet = new Movie("Harry Potter and the Goblet of Fire");
var goblet = new Movie("Harry Potter and the Goblet of Fire");
Actor daniel = new Actor("Daniel Radcliffe");
var daniel = new Actor("Daniel Radcliffe");
daniel.actedIn(goblet, Collections.singletonList("Harry Potter"));
actorRepository.save(daniel); // saves the actor and the movie
@@ -87,16 +87,16 @@ class ActorRepositoryIntegrationTest {
@Test // #386
void shouldBeAbleToHandleNestedProperties() {
Movie theParentTrap = new Movie("The Parent Trap");
Movie iKnowWhoKilledMe = new Movie("I Know Who Killed Me");
var theParentTrap = new Movie("The Parent Trap");
var iKnowWhoKilledMe = new Movie("I Know Who Killed Me");
Actor lindsayLohan = new Actor("Lindsay Lohan");
var lindsayLohan = new Actor("Lindsay Lohan");
lindsayLohan.actedIn(theParentTrap, Arrays.asList("Hallie Parker","Annie James"));
lindsayLohan.actedIn(iKnowWhoKilledMe, Arrays.asList("Aubrey Fleming", "Dakota Moss"));
actorRepository.save(lindsayLohan);
Actor nealMcDonough = new Actor("Neal McDonough");
var nealMcDonough = new Actor("Neal McDonough");
nealMcDonough.actedIn(iKnowWhoKilledMe, Collections.singletonList("Daniel Fleming"));
actorRepository.save(nealMcDonough);

View File

@@ -1,6 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
@@ -23,4 +21,14 @@
<module>example</module>
</modules>
</project>
<dependencies>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>neo4j</artifactId>
</dependency>
</dependencies>
</project>