use of org.neo4j.ogm.domain.cineasts.annotated.Rating in project neo4j-ogm by neo4j.
the class CineastsRelationshipEntityTest method shouldCreateREWithExistingStartAndEndNodes.
@Test
public void shouldCreateREWithExistingStartAndEndNodes() {
bootstrap("org/neo4j/ogm/cql/cineasts.cql");
Collection<Movie> films = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Top Gear"));
Movie movie = films.iterator().next();
assertThat(movie.getRatings()).hasSize(2);
User michal = null;
for (Rating rating : movie.getRatings()) {
if (rating.getUser().getName().equals("Michal")) {
michal = rating.getUser();
break;
}
}
assertThat(michal).isNotNull();
Set<Rating> ratings = new HashSet<>();
Rating awesome = new Rating();
awesome.setComment("Awesome");
awesome.setMovie(movie);
awesome.setUser(michal);
awesome.setStars(5);
ratings.add(awesome);
// Overwrite Michal's earlier rating
michal.setRatings(ratings);
movie.setRatings(ratings);
session.save(movie);
Collection<Movie> movies = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Top Gear"));
movie = movies.iterator().next();
assertThat(movie.getRatings()).isNotNull();
assertThat(movie.getRatings()).hasSize(1);
assertThat(movie.getRatings().iterator().next().getUser().getName()).isEqualTo("Michal");
}
use of org.neo4j.ogm.domain.cineasts.annotated.Rating in project neo4j-ogm by neo4j.
the class CineastsRelationshipEntityTest method shouldLoadASingleRating.
@Test
public void shouldLoadASingleRating() {
Movie movie = new Movie("Pulp Fiction", 1994);
session.save(movie);
User michal = new User();
michal.setName("Michal");
michal.setLogin("bachmania");
Rating awesome = new Rating();
awesome.setMovie(movie);
awesome.setUser(michal);
awesome.setStars(5);
michal.setRatings(Collections.singleton(awesome));
session.save(michal);
// Add a rating from luanne for the same movie
User luanne = new User();
luanne.setName("luanne");
luanne.setLogin("luanne");
luanne.setPassword("luanne");
Rating rating = new Rating();
rating.setMovie(movie);
rating.setUser(luanne);
rating.setStars(3);
luanne.setRatings(Collections.singleton(rating));
session.save(luanne);
session.clear();
Rating loadedRating = session.load(Rating.class, rating.getId(), 3);
assertThat(loadedRating).isNotNull();
assertThat(loadedRating.getId()).isEqualTo(rating.getId());
assertThat(loadedRating.getStars()).isEqualTo(rating.getStars());
}
use of org.neo4j.ogm.domain.cineasts.annotated.Rating in project neo4j-ogm by neo4j.
the class QueryCapabilityTest method shouldBeAbleToMapRelationshipEntities.
// DATAGRAPH-700
@Test
public void shouldBeAbleToMapRelationshipEntities() {
Iterator<Map<String, Object>> results = session.query("MATCH (u:User {name:$name})-[r:RATED]->(m) RETURN u,r,m", Collections.singletonMap("name", "Vince")).iterator();
assertThat(results).isNotNull();
Map<String, Object> result = results.next();
assertThat(result).isNotNull();
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");
Rating rating = (Rating) result.get("r");
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());
assertThat(results.hasNext()).isFalse();
}
Aggregations