use of org.neo4j.ogm.domain.cineasts.annotated.Rating in project neo4j-ogm by neo4j.
the class QueryCapabilityTest method shouldBeAbleToMapCollectionsOfNodes.
// DATAGRAPH-700
@Test
public void shouldBeAbleToMapCollectionsOfNodes() {
Iterator<Map<String, Object>> results = session.query("match (u:User {name:$name})-[r:RATED]->(m) return u as user,collect(r), collect(m) as movies", Collections.singletonMap("name", "Michal")).iterator();
assertThat(results).isNotNull();
Map<String, Object> result = results.next();
assertThat(result).isNotNull();
assertThat(((User) result.get("user")).getName()).isEqualTo("Michal");
List<Rating> ratings = (List) result.get("collect(r)");
assertThat(ratings).hasSize(2);
for (Rating rating : ratings) {
assertThat(rating.getUser().getName()).isEqualTo("Michal");
}
List<Movie> movies = (List) result.get("movies");
assertThat(movies).hasSize(2);
for (Movie movie : movies) {
if (movie.getRatings().iterator().next().getStars() == 3) {
assertThat(movie.getTitle()).isEqualTo("Top Gear");
} else {
assertThat(movie.getTitle()).isEqualTo("Pulp Fiction");
assertThat(movie.getRatings().iterator().next().getStars()).isEqualTo(5);
}
}
assertThat(results.hasNext()).isFalse();
}
use of org.neo4j.ogm.domain.cineasts.annotated.Rating in project neo4j-ogm by neo4j.
the class QueryCapabilityTest method shouldBeAbleToMapVariableDepthRelationshipsWithIncompletePaths.
// DATAGRAPH-700
@Test
public void shouldBeAbleToMapVariableDepthRelationshipsWithIncompletePaths() {
Map<String, Object> params = new HashMap<>();
params.put("name", "Vince");
params.put("title", "Top Gear");
Iterator<Map<String, Object>> results = session.query("match (u:User {name:$name}) match (m:Movie {title:$title}) match (u)-[r*0..2]-(m) return u,r,m", params).iterator();
assertThat(results).isNotNull();
Map<String, Object> result = results.next();
assertThat(result).isNotNull();
/*
Expect 2 rows:
one with (vince)-[:FRIENDS]-(michal)-[:RATED]-(topgear) where FRIENDS cannot be mapped because michal isn't known
one with (vince)-[:RATED]-(top gear) where RATED can be mapped
*/
boolean ratedRelationshipFound = false;
Movie movie = (Movie) result.get("m");
assertThat(movie).isNotNull();
assertThat(movie.getTitle()).isEqualTo("Top Gear");
User user = (User) result.get("u");
assertThat(user).isNotNull();
assertThat(user.getName()).isEqualTo("Vince");
List<Rating> ratings = (List) result.get("r");
if (ratings.size() == 1) {
// because the list of ratings with size 2= friends,rated relationships
Rating rating = ratings.get(0);
assertThat(rating).isNotNull();
assertThat(rating.getStars()).isEqualTo(4);
assertThat(movie.getRatings().iterator().next().getId()).isEqualTo(rating.getId());
assertThat(user.getRatings().iterator().next().getId()).isEqualTo(rating.getId());
ratedRelationshipFound = true;
}
assertThat(user.getFriends()).isNull();
result = results.next();
assertThat(result).isNotNull();
movie = (Movie) result.get("m");
assertThat(movie).isNotNull();
assertThat(movie.getTitle()).isEqualTo("Top Gear");
user = (User) result.get("u");
assertThat(user).isNotNull();
assertThat(user.getName()).isEqualTo("Vince");
ratings = (List) result.get("r");
if (ratings.size() == 1) {
// because the list of ratings with size 2= friends,rated relationships
Rating rating = ratings.get(0);
assertThat(rating).isNotNull();
assertThat(rating.getStars()).isEqualTo(4);
assertThat(movie.getRatings().iterator().next().getId()).isEqualTo(rating.getId());
assertThat(user.getRatings().iterator().next().getId()).isEqualTo(rating.getId());
ratedRelationshipFound = true;
}
assertThat(ratedRelationshipFound).isTrue();
assertThat(user.getFriends()).isNull();
}
use of org.neo4j.ogm.domain.cineasts.annotated.Rating in project neo4j-ogm by neo4j.
the class QueryCapabilityTest method shouldBeAbleToMapCollectionsFromPath.
// DATAGRAPH-700
@Test
public void shouldBeAbleToMapCollectionsFromPath() {
Iterator<Map<String, Object>> results = session.query("MATCH p=(u:User {name:$name})-[r:RATED]->(m) RETURN nodes(p) as nodes, relationships(p) as rels", Collections.singletonMap("name", "Vince")).iterator();
assertThat(results).isNotNull();
Map<String, Object> result = results.next();
assertThat(result).isNotNull();
List<Object> nodes = (List) result.get("nodes");
List<Object> rels = (List) result.get("rels");
assertThat(nodes).hasSize(2);
assertThat(rels).hasSize(1);
for (Object o : nodes) {
if (o instanceof User) {
User user = (User) o;
assertThat(user.getName()).isEqualTo("Vince");
assertThat(user.getRatings()).hasSize(1);
Movie movie = user.getRatings().iterator().next().getMovie();
assertThat(movie).isNotNull();
assertThat(movie.getTitle()).isEqualTo("Top Gear");
Rating rating = movie.getRatings().iterator().next();
assertThat(rating).isNotNull();
assertThat(rating.getStars()).isEqualTo(4);
}
}
}
use of org.neo4j.ogm.domain.cineasts.annotated.Rating in project neo4j-ogm by neo4j.
the class CineastsIntegrationTest method loadParticularUserRatingsAndComments.
@Test
public void loadParticularUserRatingsAndComments() {
Collection<User> filmCritics = session.loadAll(User.class, new Filter("name", ComparisonOperator.EQUALS, "Michal"));
assertThat(filmCritics).hasSize(1);
User critic = filmCritics.iterator().next();
assertThat(critic.getRatings()).hasSize(2);
for (Rating rating : critic.getRatings()) {
assertThat(rating.getComment()).as("The comment should've been mapped").isNotNull();
assertThat(rating.getStars() > 0).as("The star rating should've been mapped").isTrue();
assertThat(rating.getUser()).as("The user start node should've been mapped").isNotNull();
assertThat(rating.getMovie()).as("The movie end node should've been mapped").isNotNull();
}
}
use of org.neo4j.ogm.domain.cineasts.annotated.Rating in project neo4j-ogm by neo4j.
the class CineastsIntegrationTest method loadRatingsForSpecificFilm.
@Test
public void loadRatingsForSpecificFilm() {
Collection<Movie> films = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Top Gear"));
assertThat(films).hasSize(1);
Movie film = films.iterator().next();
assertThat(film.getRatings()).hasSize(2);
for (Rating rating : film.getRatings()) {
assertThat(rating.getStars() > 0).as("The star rating should've been mapped").isTrue();
assertThat(rating.getUser()).as("The user start node should've been mapped").isNotNull();
assertThat(rating.getMovie()).as("The wrong film was mapped to the rating").isSameAs(film);
}
}
Aggregations