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