Search in sources :

Example 11 with Movie

use of org.neo4j.ogm.domain.cineasts.annotated.Movie in project neo4j-ogm by neo4j.

the class CineastsIntegrationTest method nestedFilteringCanBeTheOneAndOnlyOredFilter.

@Test
public void nestedFilteringCanBeTheOneAndOnlyOredFilter() {
    Filter filterB = new Filter("name", ComparisonOperator.EQUALS, "Catty");
    filterB.setNestedPath(new Filter.NestedPathSegment("ratings", Rating.class), new Filter.NestedPathSegment("user", User.class), new Filter.NestedPathSegment("pets", Pet.class));
    filterB.setBooleanOperator(BooleanOperator.OR);
    Filters filters = new Filters(filterB);
    Collection<Movie> films = session.loadAll(Movie.class, filters);
    assertThat(films).hasSize(2);
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) Filters(org.neo4j.ogm.cypher.Filters) User(org.neo4j.ogm.domain.cineasts.annotated.User) Filter(org.neo4j.ogm.cypher.Filter) Rating(org.neo4j.ogm.domain.cineasts.annotated.Rating) Pet(org.neo4j.ogm.domain.cineasts.annotated.Pet) Test(org.junit.Test)

Example 12 with Movie

use of org.neo4j.ogm.domain.cineasts.annotated.Movie in project neo4j-ogm by neo4j.

the class CineastsIntegrationTest method loadFilmByRatingUsersPet.

@Test
public void loadFilmByRatingUsersPet() {
    // Pulp Fiction and Top Gear rated by Michal who owns Catty
    Filter filter = new Filter("name", ComparisonOperator.EQUALS, "Catty");
    filter.setOwnerEntityType(Movie.class);
    filter.setNestedPath(new Filter.NestedPathSegment("ratings", Rating.class), new Filter.NestedPathSegment("user", User.class), new Filter.NestedPathSegment("pets", Pet.class));
    Collection<Movie> films = session.loadAll(Movie.class, filter);
    assertThat(films).hasSize(2);
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) User(org.neo4j.ogm.domain.cineasts.annotated.User) Filter(org.neo4j.ogm.cypher.Filter) Rating(org.neo4j.ogm.domain.cineasts.annotated.Rating) Pet(org.neo4j.ogm.domain.cineasts.annotated.Pet) Test(org.junit.Test)

Example 13 with Movie

use of org.neo4j.ogm.domain.cineasts.annotated.Movie 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);
    }
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) Filter(org.neo4j.ogm.cypher.Filter) Rating(org.neo4j.ogm.domain.cineasts.annotated.Rating) Test(org.junit.Test)

Example 14 with Movie

use of org.neo4j.ogm.domain.cineasts.annotated.Movie 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);
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) User(org.neo4j.ogm.domain.cineasts.annotated.User) Filter(org.neo4j.ogm.cypher.Filter) Plays(org.neo4j.ogm.domain.cineasts.annotated.Plays) Rating(org.neo4j.ogm.domain.cineasts.annotated.Rating) Test(org.junit.Test)

Example 15 with Movie

use of org.neo4j.ogm.domain.cineasts.annotated.Movie 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");
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) User(org.neo4j.ogm.domain.cineasts.annotated.User) Filter(org.neo4j.ogm.cypher.Filter) Actor(org.neo4j.ogm.domain.cineasts.annotated.Actor) Rating(org.neo4j.ogm.domain.cineasts.annotated.Rating) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)41 Movie (org.neo4j.ogm.domain.cineasts.annotated.Movie)41 User (org.neo4j.ogm.domain.cineasts.annotated.User)25 Rating (org.neo4j.ogm.domain.cineasts.annotated.Rating)24 Filter (org.neo4j.ogm.cypher.Filter)17 HashMap (java.util.HashMap)11 Map (java.util.Map)11 ExtendedUser (org.neo4j.ogm.domain.cineasts.annotated.ExtendedUser)8 Actor (org.neo4j.ogm.domain.cineasts.annotated.Actor)7 HashSet (java.util.HashSet)6 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Result (org.neo4j.ogm.model.Result)3 Filters (org.neo4j.ogm.cypher.Filters)2 Pet (org.neo4j.ogm.domain.cineasts.annotated.Pet)2 Plays (org.neo4j.ogm.domain.cineasts.annotated.Plays)2 Role (org.neo4j.ogm.domain.cineasts.annotated.Role)2 URL (java.net.URL)1 Pagination (org.neo4j.ogm.cypher.query.Pagination)1 SortOrder (org.neo4j.ogm.cypher.query.SortOrder)1