Search in sources :

Example 11 with Rating

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

the class CineastsRelationshipEntityTest method shouldBeAbleToModifyRating.

// DATAGRAPH-714
@Test
public void shouldBeAbleToModifyRating() {
    Movie movie = new Movie("Harry Potter and the Philosophers Stone", 2003);
    User vince = new User();
    vince.setName("Vince");
    vince.setLogin("bickerv");
    Set<Rating> ratings = new HashSet<>();
    Rating awesome = new Rating();
    awesome.setComment("Awesome");
    awesome.setMovie(movie);
    awesome.setUser(vince);
    awesome.setStars(5);
    ratings.add(awesome);
    vince.setRatings(ratings);
    movie.setRatings(ratings);
    session.save(movie);
    Collection<Movie> movies = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Harry Potter and the Philosophers Stone"));
    movie = movies.iterator().next();
    assertThat(movie.getRatings()).hasSize(1);
    Rating rating = movie.getRatings().iterator().next();
    assertThat(rating.getUser().getName()).isEqualTo("Vince");
    assertThat(rating.getStars()).isEqualTo(5);
    // Modify the rating stars and save the rating directly
    rating.setStars(3);
    session.save(rating);
    session.clear();
    movies = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Harry Potter and the Philosophers Stone"));
    movie = movies.iterator().next();
    assertThat(movie.getRatings()).hasSize(1);
    rating = movie.getRatings().iterator().next();
    assertThat(rating.getUser().getName()).isEqualTo("Vince");
    assertThat(rating.getStars()).isEqualTo(3);
    vince = rating.getUser();
    // Modify the rating stars and save the user (start node)
    movie.getRatings().iterator().next().setStars(2);
    session.save(vince);
    session.clear();
    movies = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Harry Potter and the Philosophers Stone"));
    movie = movies.iterator().next();
    assertThat(movie.getRatings()).hasSize(1);
    rating = movie.getRatings().iterator().next();
    assertThat(rating.getUser().getName()).isEqualTo("Vince");
    assertThat(rating.getStars()).isEqualTo(2);
    // Modify the rating stars and save the movie (end node)
    movie.getRatings().iterator().next().setStars(1);
    session.save(movie);
    session.clear();
    movies = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Harry Potter and the Philosophers Stone"));
    movie = movies.iterator().next();
    assertThat(movie.getRatings()).hasSize(1);
    rating = movie.getRatings().iterator().next();
    assertThat(rating.getUser().getName()).isEqualTo("Vince");
    assertThat(rating.getStars()).isEqualTo(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 12 with Rating

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

the class CineastsRelationshipEntityTest method shouldBeAbleToDeleteOneRating.

// DATAGRAPH-586
@Test
public void shouldBeAbleToDeleteOneRating() {
    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 one rating
    session.delete(okay);
    Collection<Rating> ratings = session.loadAll(Rating.class);
    assertThat(ratings).hasSize(1);
    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()).hasSize(1);
    adam = session.loadAll(User.class, new Filter("name", ComparisonOperator.EQUALS, "Adam")).iterator().next();
    assertThat(adam.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 13 with Rating

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

the class CineastsRelationshipEntityTest method testFilterOnRelationshipEntity.

@Test
public void testFilterOnRelationshipEntity() throws Exception {
    Movie pulpFiction = new Movie("Pulp Fiction", 1994);
    Movie ootf = new Movie("Harry Potter and the Order of the Phoenix", 2009);
    User frantisek = new User();
    frantisek.setName("Frantisek");
    frantisek.setLogin("frantisek");
    Rating pulpRating = new Rating();
    pulpRating.setStars(3);
    pulpRating.setMovie(pulpFiction);
    pulpRating.setUser(frantisek);
    pulpFiction.setRatings(new HashSet<>(Arrays.asList(pulpRating)));
    Rating ootfRating = new Rating();
    ootfRating.setStars(3);
    ootfRating.setMovie(ootf);
    ootfRating.setUser(frantisek);
    frantisek.setRatings(new HashSet<>(Arrays.asList(ootfRating, pulpRating)));
    User otto = new User();
    otto.setName("Otto");
    otto.setLogin("otto");
    Rating pulpRating2 = new Rating();
    pulpRating2.setStars(3);
    pulpRating2.setMovie(pulpFiction);
    pulpRating2.setUser(otto);
    Rating ootfRating2 = new Rating();
    ootfRating2.setStars(3);
    ootfRating2.setMovie(ootf);
    ootfRating2.setUser(otto);
    pulpFiction.setRatings(new HashSet<>(Arrays.asList(pulpRating, pulpRating2)));
    ootf.setRatings(new HashSet<>(Arrays.asList(ootfRating, ootfRating2)));
    otto.setRatings(new HashSet<>(Arrays.asList(pulpRating2, ootfRating2)));
    session.save(otto);
    session.clear();
    Filter filter = new Filter("stars", ComparisonOperator.EQUALS, 3);
    filter.setNestedPropertyName("ratings");
    filter.setNestedPropertyType(Rating.class);
    filter.setNestedRelationshipEntity(true);
    Collection<User> users = session.loadAll(User.class, filter, new Pagination(0, 2));
    assertThat(users).hasSize(2);
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) Pagination(org.neo4j.ogm.cypher.query.Pagination) 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 14 with Rating

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

the class MovieTest method testDeserialiseMovie.

@Test
public void testDeserialiseMovie() {
    MetaData metadata = new MetaData("org.neo4j.ogm.domain.cineasts.annotated");
    Neo4jSession session = new Neo4jSession(metadata, true, new MoviesRequest());
    Movie movie = session.load(Movie.class, UUID.fromString("38ebe777-bc85-4810-8217-096f29a361f1"), 1);
    assertThat(movie.getTitle()).isEqualTo("Pulp Fiction");
    assertThat(movie.getRatings()).isNotNull();
    assertThat(movie.getRatings()).hasSize(1);
    Rating rating = movie.getRatings().iterator().next();
    assertThat(rating.getUser().getName()).isEqualTo("Michal");
    assertThat(rating.getMovie().getTitle()).isEqualTo("Pulp Fiction");
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) MetaData(org.neo4j.ogm.metadata.MetaData) Neo4jSession(org.neo4j.ogm.session.Neo4jSession) Rating(org.neo4j.ogm.domain.cineasts.annotated.Rating) Test(org.junit.Test)

Example 15 with Rating

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

the class CineastsIntegrationTest method loadRatingByUserNameAndStars.

@Test
public void loadRatingByUserNameAndStars() {
    Filter userNameFilter = new Filter("name", ComparisonOperator.EQUALS, "Michal");
    userNameFilter.setNestedPath(new Filter.NestedPathSegment("user", User.class));
    Collection<Rating> ratings = session.loadAll(Rating.class, userNameFilter);
    assertThat(ratings).hasSize(2);
}
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)

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