use of org.neo4j.ogm.domain.cineasts.annotated.Movie in project neo4j-ogm by neo4j.
the class CineastsIntegrationTest method loadFilmByUserAndRatingUserPlays.
@Test
public void loadFilmByUserAndRatingUserPlays() {
Filter userFilter = new Filter("name", ComparisonOperator.EQUALS, "Michal");
userFilter.setNestedPath(new Filter.NestedPathSegment("ratings", Rating.class), new Filter.NestedPathSegment("user", User.class));
Filter playsFilter = new Filter("level", ComparisonOperator.EQUALS, "ok");
playsFilter.setOwnerEntityType(Movie.class);
playsFilter.setNestedPath(new Filter.NestedPathSegment("ratings", Rating.class), new Filter.NestedPathSegment("user", User.class), new Filter.NestedPathSegment("plays", Plays.class));
Filters filters = userFilter.and(playsFilter);
Collection<Movie> films = session.loadAll(Movie.class, filters);
assertThat(films).hasSize(2);
}
use of org.neo4j.ogm.domain.cineasts.annotated.Movie in project neo4j-ogm by neo4j.
the class CineastsIntegrationTest method loadFilmByRating.
@Test
public void loadFilmByRating() {
Filter filter = new Filter("stars", ComparisonOperator.EQUALS, 5);
filter.setOwnerEntityType(Movie.class);
filter.setNestedPath(new Filter.NestedPathSegment("ratings", Rating.class));
Collection<Movie> films = session.loadAll(Movie.class, filter);
assertThat(films).hasSize(1);
}
use of org.neo4j.ogm.domain.cineasts.annotated.Movie in project neo4j-ogm by neo4j.
the class CineastsIntegrationTest method loadRatingsAndCommentsAboutMovies.
@Test
public void loadRatingsAndCommentsAboutMovies() {
Collection<Movie> movies = session.loadAll(Movie.class);
assertThat(movies).hasSize(3);
for (Movie movie : movies) {
if (movie.getRatings() != null) {
for (Rating rating : movie.getRatings()) {
assertThat(rating.getMovie()).as("The film on the rating shouldn't be null").isNotNull();
assertThat(rating.getMovie()).as("The film on the rating was not mapped correctly").isSameAs(movie);
assertThat(rating.getUser()).as("The film critic wasn't set").isNotNull();
}
}
}
}
use of org.neo4j.ogm.domain.cineasts.annotated.Movie in project neo4j-ogm by neo4j.
the class CineastsRelationshipEntityTest method shouldBeAbleToDeleteAllRatings.
// DATAGRAPH-586
@Test
public void shouldBeAbleToDeleteAllRatings() {
Set<Rating> gobletRatings = new HashSet<>();
Set<Rating> phoenixRatings = new HashSet<>();
Movie goblet = new Movie("Harry Potter and the Goblet of Fire", 2006);
session.save(goblet);
Movie phoenix = new Movie("Harry Potter and the Order of the Phoenix", 2009);
session.save(phoenix);
User adam = new User();
adam.setName("Adam");
adam.setLogin("adamg");
Rating good = new Rating();
good.setUser(adam);
good.setMovie(goblet);
good.setStars(3);
gobletRatings.add(good);
goblet.setRatings(gobletRatings);
Rating okay = new Rating();
okay.setMovie(phoenix);
okay.setUser(adam);
okay.setStars(2);
phoenixRatings.add(okay);
phoenix.setRatings(phoenixRatings);
Set<Rating> adamsRatings = new HashSet<>();
adamsRatings.add(good);
adamsRatings.add(okay);
adam.setRatings(adamsRatings);
session.save(adam);
adam = session.loadAll(User.class, new Filter("name", ComparisonOperator.EQUALS, "Adam")).iterator().next();
assertThat(adam.getRatings()).hasSize(2);
// delete all ratings
session.deleteAll(Rating.class);
assertThat(session.loadAll(Rating.class)).isEmpty();
phoenix = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Harry Potter and the Order of the Phoenix")).iterator().next();
assertThat(phoenix.getRatings()).isNull();
goblet = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Harry Potter and the Goblet of Fire")).iterator().next();
assertThat(goblet.getRatings()).isNull();
adam = session.loadAll(User.class, new Filter("name", ComparisonOperator.EQUALS, "Adam")).iterator().next();
assertThat(adam.getRatings()).isNull();
}
use of org.neo4j.ogm.domain.cineasts.annotated.Movie in project neo4j-ogm by neo4j.
the class CineastsRelationshipEntityTest method shouldBeAbleToSaveAndUpdateMultipleUserRatings.
// DATAGRAPH-569
@Test
public void shouldBeAbleToSaveAndUpdateMultipleUserRatings() {
Set<Rating> gobletRatings = new HashSet<>();
Set<Rating> phoenixRatings = new HashSet<>();
Movie goblet = new Movie("Harry Potter and the Goblet of Fire", 2006);
session.save(goblet);
Movie phoenix = new Movie("Harry Potter and the Order of the Phoenix", 2009);
session.save(phoenix);
User adam = new User();
adam.setName("Adam");
adam.setLogin("adamg");
Rating good = new Rating();
good.setUser(adam);
good.setMovie(goblet);
good.setStars(3);
gobletRatings.add(good);
goblet.setRatings(gobletRatings);
Rating okay = new Rating();
okay.setMovie(phoenix);
okay.setUser(adam);
okay.setStars(2);
phoenixRatings.add(okay);
phoenix.setRatings(phoenixRatings);
Set<Rating> adamsRatings = new HashSet<>();
adamsRatings.add(good);
adamsRatings.add(okay);
adam.setRatings(adamsRatings);
session.save(adam);
Collection<Movie> movies = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Harry Potter and the Goblet of Fire"));
goblet = movies.iterator().next();
assertThat(goblet.getRatings()).isNotNull();
assertThat(goblet.getRatings()).hasSize(1);
movies = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Harry Potter and the Order of the Phoenix"));
phoenix = movies.iterator().next();
assertThat(phoenix.getRatings()).isNotNull();
assertThat(phoenix.getRatings()).hasSize(1);
adam = session.loadAll(User.class, new Filter("name", ComparisonOperator.EQUALS, "Adam")).iterator().next();
assertThat(adam.getRatings()).hasSize(2);
// Get rid of the Phoenix rating
adam.setRatings(gobletRatings);
session.save(adam);
adam = session.loadAll(User.class, new Filter("name", ComparisonOperator.EQUALS, "Adam")).iterator().next();
assertThat(adam.getRatings()).hasSize(1);
movies = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Harry Potter and the Order of the Phoenix"));
phoenix = movies.iterator().next();
assertThat(phoenix.getRatings()).isNull();
movies = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Harry Potter and the Goblet of Fire"));
goblet = movies.iterator().next();
assertThat(goblet.getRatings()).isNotNull();
assertThat(goblet.getRatings()).hasSize(1);
}
Aggregations