use of org.neo4j.ogm.cypher.Filter 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.cypher.Filter in project neo4j-ogm by neo4j.
the class CineastsIntegrationTest method nestedFilteringMustThrowExceptionWithOrInThePipelineForRelationshipEntities.
@Test
public void nestedFilteringMustThrowExceptionWithOrInThePipelineForRelationshipEntities() {
Filter userNameFilter = new Filter("name", ComparisonOperator.EQUALS, "Michal");
userNameFilter.setBooleanOperator(BooleanOperator.OR);
Filter ratingFilter = new Filter("stars", ComparisonOperator.EQUALS, 5);
userNameFilter.setNestedPath(new Filter.NestedPathSegment("user", User.class));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> session.loadAll(Rating.class, userNameFilter.and(ratingFilter))).withMessage("Filters containing nested paths cannot be combined via the logical OR operator.");
}
use of org.neo4j.ogm.cypher.Filter 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);
}
}
use of org.neo4j.ogm.cypher.Filter in project neo4j-ogm by neo4j.
the class CineastsIntegrationTest method loadFilmByRatingUserPlays.
@Test
public void loadFilmByRatingUserPlays() {
Filter filter = new Filter("level", ComparisonOperator.EQUALS, "ok");
filter.setOwnerEntityType(Movie.class);
filter.setNestedPath(new Filter.NestedPathSegment("ratings", Rating.class), new Filter.NestedPathSegment("user", User.class), new Filter.NestedPathSegment("plays", Plays.class));
Collection<Movie> films = session.loadAll(Movie.class, filter);
assertThat(films).hasSize(2);
}
use of org.neo4j.ogm.cypher.Filter in project neo4j-ogm by neo4j.
the class CineastsRelationshipEntityTest method shouldHydrateTheEndNodeOfAnRECorrectly.
// DATAGRAPH-552
@Test
public void shouldHydrateTheEndNodeOfAnRECorrectly() {
Movie movie = new Movie("Pulp Fiction", 1994);
Actor actor = new Actor("John Travolta");
actor.playedIn(movie, "Vincent");
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);
// Check that Pulp Fiction has one rating from Michal
Collection<Movie> films = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Pulp Fiction"));
assertThat(films).hasSize(1);
Movie film = films.iterator().next();
assertThat(film).isNotNull();
assertThat(film.getRatings()).hasSize(1);
assertThat(film.getRatings().iterator().next().getUser().getName()).isEqualTo("Michal");
assertThat(film.getRoles().iterator().next().getRole()).isEqualTo("Vincent");
session.clear();
Rating rating = session.load(Rating.class, awesome.getId(), 2);
assertThat(rating).isNotNull();
Movie loadedMovie = rating.getMovie();
assertThat(loadedMovie).isNotNull();
assertThat(loadedMovie.getTitle()).isEqualTo("Pulp Fiction");
assertThat(loadedMovie.getRoles().iterator().next().getRole()).isEqualTo("Vincent");
}
Aggregations