Search in sources :

Example 16 with Rating

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

the class CineastsIntegrationTest method loadRatingByUserName.

@Test
public void loadRatingByUserName() {
    Filter userNameFilter = new Filter("name", ComparisonOperator.EQUALS, "Michal");
    Filter ratingFilter = new Filter("stars", ComparisonOperator.EQUALS, 5);
    userNameFilter.setNestedPath(new Filter.NestedPathSegment("user", User.class));
    Collection<Rating> ratings = session.loadAll(Rating.class, userNameFilter.and(ratingFilter));
    assertThat(ratings).hasSize(1);
}
Also used : User(org.neo4j.ogm.domain.cineasts.annotated.User) Filter(org.neo4j.ogm.cypher.Filter) Rating(org.neo4j.ogm.domain.cineasts.annotated.Rating) Test(org.junit.Test)

Example 17 with Rating

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

Example 18 with Rating

use of org.neo4j.ogm.domain.cineasts.annotated.Rating 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();
}
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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 19 with Rating

use of org.neo4j.ogm.domain.cineasts.annotated.Rating 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);
}
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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 20 with Rating

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

the class CineastsRelationshipEntityTest method shouldSaveAndRetrieveRelationshipEntitiesDirectly.

// DATAGRAPH-552
@Test
public void shouldSaveAndRetrieveRelationshipEntitiesDirectly() {
    // we need some stuff in the database
    session.query("CREATE " + "(nc:NotAClass {name:'Colin'}), " + "(g:NotAClass {age: 39}), " + "(g)-[:TEST {comment : 'test'}]->(nc)", Collections.emptyMap());
    User critic = new User();
    critic.setName("Gary");
    critic.setLogin("gman");
    Movie film = new Movie("Fast and Furious XVII", 2015);
    Rating filmRating = new Rating();
    filmRating.setUser(critic);
    critic.setRatings(Collections.singleton(filmRating));
    filmRating.setMovie(film);
    film.setRatings(Collections.singleton(filmRating));
    filmRating.setStars(2);
    filmRating.setComment("They've made far too many of these films now!");
    session.save(filmRating);
    // load the rating by id
    Rating loadedRating = session.load(Rating.class, filmRating.getId());
    assertThat(loadedRating).as("The loaded rating shouldn't be null").isNotNull();
    assertThat(loadedRating.getStars()).as("The relationship properties weren't saved correctly").isEqualTo(filmRating.getStars());
    assertThat(loadedRating.getMovie().getTitle()).as("The rated film wasn't saved correctly").isEqualTo(film.getTitle());
    assertThat(loadedRating.getUser().getLogin()).as("The critic wasn't saved correctly").isEqualTo(critic.getLogin());
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) User(org.neo4j.ogm.domain.cineasts.annotated.User) Rating(org.neo4j.ogm.domain.cineasts.annotated.Rating) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)23 Rating (org.neo4j.ogm.domain.cineasts.annotated.Rating)23 Movie (org.neo4j.ogm.domain.cineasts.annotated.Movie)19 User (org.neo4j.ogm.domain.cineasts.annotated.User)19 Filter (org.neo4j.ogm.cypher.Filter)12 HashSet (java.util.HashSet)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ExtendedUser (org.neo4j.ogm.domain.cineasts.annotated.ExtendedUser)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Pagination (org.neo4j.ogm.cypher.query.Pagination)1 SortOrder (org.neo4j.ogm.cypher.query.SortOrder)1 Actor (org.neo4j.ogm.domain.cineasts.annotated.Actor)1 MetaData (org.neo4j.ogm.metadata.MetaData)1 Neo4jSession (org.neo4j.ogm.session.Neo4jSession)1