use of org.neo4j.ogm.domain.cineasts.annotated.Movie in project neo4j-ogm by neo4j.
the class CineastsRelationshipEntityTest method shouldRetainREsWhenAStartOrEndNodeIsLoaded.
/**
* @see DATAGRAPH-704
*/
@Test
public void shouldRetainREsWhenAStartOrEndNodeIsLoaded() {
bootstrap("org/neo4j/ogm/cql/cineasts.cql");
Collection<Movie> films = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Top Gear"));
Movie movie = films.iterator().next();
assertThat(movie.getRatings()).hasSize(2);
session.loadAll(User.class, new Filter("name", ComparisonOperator.EQUALS, "Michal")).iterator().next();
assertThat(movie.getRatings()).hasSize(// should not lose one rating because Michal is loaded; ratings should me merged and not overwritten
2);
}
use of org.neo4j.ogm.domain.cineasts.annotated.Movie 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());
}
use of org.neo4j.ogm.domain.cineasts.annotated.Movie in project neo4j-ogm by neo4j.
the class CineastsRelationshipEntityTest method shouldLoadActorsForAPersistedMovie.
@Test
public void shouldLoadActorsForAPersistedMovie() {
session.query("CREATE " + "(dh:Movie {title:'Die Hard'}), " + "(bw:Actor {name: 'Bruce Willis'}), " + "(bw)-[:ACTS_IN {role : 'John'}]->(dh)", Collections.emptyMap());
// Movie dieHard = TestUtils.firstOrNull(session.loadByProperty(Movie.class, new Parameter("title", "Die Hard")));
Movie dieHard = session.loadAll(Movie.class).iterator().next();
assertThat(dieHard).isNotNull();
assertThat(dieHard.getRoles()).isNotNull();
assertThat(dieHard.getRoles()).hasSize(1);
}
use of org.neo4j.ogm.domain.cineasts.annotated.Movie in project neo4j-ogm by neo4j.
the class CineastsRelationshipEntityTest method shouldCreateREWithExistingStartAndEndNodes.
@Test
public void shouldCreateREWithExistingStartAndEndNodes() {
bootstrap("org/neo4j/ogm/cql/cineasts.cql");
Collection<Movie> films = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Top Gear"));
Movie movie = films.iterator().next();
assertThat(movie.getRatings()).hasSize(2);
User michal = null;
for (Rating rating : movie.getRatings()) {
if (rating.getUser().getName().equals("Michal")) {
michal = rating.getUser();
break;
}
}
assertThat(michal).isNotNull();
Set<Rating> ratings = new HashSet<>();
Rating awesome = new Rating();
awesome.setComment("Awesome");
awesome.setMovie(movie);
awesome.setUser(michal);
awesome.setStars(5);
ratings.add(awesome);
// Overwrite Michal's earlier rating
michal.setRatings(ratings);
movie.setRatings(ratings);
session.save(movie);
Collection<Movie> movies = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Top Gear"));
movie = movies.iterator().next();
assertThat(movie.getRatings()).isNotNull();
assertThat(movie.getRatings()).hasSize(1);
assertThat(movie.getRatings().iterator().next().getUser().getName()).isEqualTo("Michal");
}
use of org.neo4j.ogm.domain.cineasts.annotated.Movie in project neo4j-ogm by neo4j.
the class CineastsRelationshipEntityTest method shouldSaveSameRoleTwiceRelationshipBetweenTheSameTwoObjects.
@Test
public void shouldSaveSameRoleTwiceRelationshipBetweenTheSameTwoObjects() {
Movie movie = new Movie("The big John Travolta Party", 2016);
Actor actor = new Actor("John Travolta");
actor.playedIn(movie, "He danced mostly");
assertThat(actor.getRoles()).hasSize(1);
session.save(actor);
session.clear();
Actor loadedActor = session.load(Actor.class, actor.getUuid());
assertThat(loadedActor.getRoles()).hasSize(1);
// Add an identical role
actor.playedIn(movie, "He danced mostly");
assertThat(actor.getRoles()).hasSize(2);
session.save(actor);
session.clear();
loadedActor = session.load(Actor.class, actor.getUuid());
assertThat(loadedActor.getRoles()).hasSize(2);
}
Aggregations