#582 - Fix Neo4j builds.
This commit is contained in:
committed by
Mark Paluch
parent
60aa63ee65
commit
fd2dfc8a96
@@ -16,8 +16,8 @@
|
||||
|
||||
package example.springdata.neo4j;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.neo4j.core.schema.GeneratedValue;
|
||||
import org.springframework.data.neo4j.core.schema.Id;
|
||||
@@ -36,17 +36,18 @@ public class Actor {
|
||||
|
||||
private @Id @GeneratedValue Long id;
|
||||
private final String name;
|
||||
private @Relationship(type = "ACTED_IN") Map<Movie, Roles> roles = new HashMap<>();
|
||||
private @Relationship(type = "ACTED_IN") List<Roles> roles = new ArrayList<>();
|
||||
|
||||
public Actor(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void actedIn(Movie movie, String roleName) {
|
||||
public void actedIn(Movie movie, List<String> roleNames) {
|
||||
|
||||
Roles movieRoles = this.roles.computeIfAbsent(movie, m -> new Roles());
|
||||
movieRoles.addRole(roleName);
|
||||
movie.getActors().put(this, movieRoles);
|
||||
Roles movieRoles = new Roles(roleNames);
|
||||
movieRoles.setMovie(movie);
|
||||
|
||||
this.roles.add(movieRoles);
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
@@ -57,11 +58,11 @@ public class Actor {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Map<Movie, Roles> getRoles() {
|
||||
public List<Roles> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
public void setRoles(Map<Movie, Roles> roles) {
|
||||
public void setRoles(List<Roles> roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,14 +16,9 @@
|
||||
|
||||
package example.springdata.neo4j;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.data.neo4j.core.schema.GeneratedValue;
|
||||
import org.springframework.data.neo4j.core.schema.Id;
|
||||
import org.springframework.data.neo4j.core.schema.Node;
|
||||
import org.springframework.data.neo4j.core.schema.Relationship;
|
||||
import org.springframework.data.neo4j.core.schema.Relationship.Direction;
|
||||
|
||||
/**
|
||||
* A Movie node entity.
|
||||
@@ -38,8 +33,6 @@ public class Movie {
|
||||
private @Id @GeneratedValue Long id;
|
||||
|
||||
private final String title;
|
||||
private @Relationship(type = "ACTED_IN", direction = Direction.INCOMING)
|
||||
Map<Actor, Roles> actors = new HashMap<>();
|
||||
|
||||
public Movie(String title) {
|
||||
this.title = title;
|
||||
@@ -53,14 +46,6 @@ public class Movie {
|
||||
return title;
|
||||
}
|
||||
|
||||
public Map<Actor, Roles> getActors() {
|
||||
return actors;
|
||||
}
|
||||
|
||||
public void setActors(Map<Actor, Roles> actors) {
|
||||
this.actors = actors;
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
return "Movie{" +
|
||||
"title='" + title + '\'' +
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.List;
|
||||
|
||||
import org.springframework.data.annotation.PersistenceConstructor;
|
||||
import org.springframework.data.neo4j.core.schema.RelationshipProperties;
|
||||
import org.springframework.data.neo4j.core.schema.TargetNode;
|
||||
|
||||
/**
|
||||
* A Role relationship entity between an actor and movie.
|
||||
@@ -33,6 +34,9 @@ public class Roles {
|
||||
|
||||
private final List<String> roles;
|
||||
|
||||
@TargetNode
|
||||
private Movie movie;
|
||||
|
||||
public Roles() {
|
||||
this(Collections.emptyList());
|
||||
}
|
||||
@@ -42,6 +46,14 @@ public class Roles {
|
||||
this.roles = new ArrayList<>(roles);
|
||||
}
|
||||
|
||||
public Movie getMovie() {
|
||||
return movie;
|
||||
}
|
||||
|
||||
public void setMovie(Movie movie) {
|
||||
this.movie = movie;
|
||||
}
|
||||
|
||||
public List<String> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,10 @@
|
||||
*/
|
||||
package example.springdata.neo4j;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
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.Test;
|
||||
@@ -68,14 +71,15 @@ class ActorRepositoryIntegrationTest {
|
||||
Movie goblet = new Movie("Harry Potter and the Goblet of Fire");
|
||||
|
||||
Actor daniel = new Actor("Daniel Radcliffe");
|
||||
daniel.actedIn(goblet, "Harry Potter");
|
||||
daniel.actedIn(goblet, Collections.singletonList("Harry Potter"));
|
||||
|
||||
actorRepository.save(daniel); // saves the actor and the movie
|
||||
|
||||
assertThat(actorRepository.findById(daniel.getId())).hasValueSatisfying(actor -> {
|
||||
assertThat(actor.getName()).isEqualTo(daniel.getName());
|
||||
assertThat(actor.getRoles()).hasSize(1)
|
||||
.satisfies(roles -> assertThat(roles.values()).flatExtracting(Roles::getRoles).hasSize(1).first()
|
||||
.satisfies(roles -> assertThat(roles).flatExtracting(Roles::getRoles)
|
||||
.hasSize(1).first()
|
||||
.isEqualTo("Harry Potter"));
|
||||
});
|
||||
}
|
||||
@@ -88,14 +92,12 @@ class ActorRepositoryIntegrationTest {
|
||||
|
||||
Actor lindsayLohan = new Actor("Lindsay Lohan");
|
||||
|
||||
lindsayLohan.actedIn(theParentTrap, "Hallie Parker");
|
||||
lindsayLohan.actedIn(theParentTrap, "Annie James");
|
||||
lindsayLohan.actedIn(iKnowWhoKilledMe, "Aubrey Fleming");
|
||||
lindsayLohan.actedIn(iKnowWhoKilledMe, "Dakota Moss");
|
||||
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");
|
||||
nealMcDonough.actedIn(iKnowWhoKilledMe, "Daniel Fleming");
|
||||
nealMcDonough.actedIn(iKnowWhoKilledMe, Collections.singletonList("Daniel Fleming"));
|
||||
actorRepository.save(nealMcDonough);
|
||||
|
||||
assertThat(actorRepository.findAllByRolesMovieTitle(iKnowWhoKilledMe.getTitle())).hasSize(2)
|
||||
@@ -104,10 +106,10 @@ class ActorRepositoryIntegrationTest {
|
||||
.allSatisfy(actor -> {
|
||||
if (actor.getName().equals(nealMcDonough.getName())) {
|
||||
assertThat(actor.getRoles())
|
||||
.allSatisfy((m, r) -> assertThat(r.getRoles()).containsOnly("Daniel Fleming"));
|
||||
.allSatisfy((r) -> assertThat(r.getRoles()).containsOnly("Daniel Fleming"));
|
||||
} else if (actor.getName().equals(lindsayLohan.getName())) {
|
||||
assertThat(actor.getRoles())
|
||||
.allSatisfy((m, r) -> assertThat(r.getRoles()).containsOnly("Aubrey Fleming", "Dakota Moss"));
|
||||
.allSatisfy((r) -> assertThat(r.getRoles()).containsOnly("Aubrey Fleming", "Dakota Moss"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user