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);
}
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);
}
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);
}
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");
}
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);
}
Aggregations