use of org.neo4j.ogm.domain.cineasts.annotated.User in project neo4j-ogm by neo4j.
the class CineastsIntegrationTest method saveAndRetrieveUserWithDifferentCharset.
// DATAGRAPH-614
@Test
public void saveAndRetrieveUserWithDifferentCharset() {
User user = new User();
user.setLogin("aki");
user.setName("Aki Kaurism\u00E4ki");
user.setPassword("aki");
session.save(user);
User aki = session.load(User.class, "aki");
assertThat(aki).isNotNull();
try {
assertThat(aki.getName().getBytes("UTF-8")).isEqualTo("Aki Kaurism\u00E4ki".getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
fail("UTF-8 encoding not supported on this platform");
}
}
use of org.neo4j.ogm.domain.cineasts.annotated.User 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");
}
use of org.neo4j.ogm.domain.cineasts.annotated.User in project neo4j-ogm by neo4j.
the class CineastsRelationshipEntityTest method shouldSaveMultipleRatingsFromDifferentUsersForSameMovie.
@Test
public void shouldSaveMultipleRatingsFromDifferentUsersForSameMovie() {
Movie movie = new Movie("Pulp Fiction", 1994);
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");
// Add a rating from luanne for the same movie
User luanne = new User();
luanne.setName("luanne");
luanne.setLogin("luanne");
luanne.setPassword("luanne");
Rating rating = new Rating();
rating.setMovie(film);
rating.setUser(luanne);
rating.setStars(3);
luanne.setRatings(Collections.singleton(rating));
session.save(luanne);
// Verify that pulp fiction has two ratings
films = session.loadAll(Movie.class, new Filter("title", ComparisonOperator.EQUALS, "Pulp Fiction"));
film = films.iterator().next();
// Fail, it has just one rating, luannes
assertThat(film.getRatings()).hasSize(2);
// Verify that luanne's rating is saved
User foundLuanne = session.load(User.class, "luanne");
assertThat(foundLuanne.getRatings()).hasSize(1);
// Verify that Michals rating still exists
Collection<User> users = session.loadAll(User.class, new Filter("name", ComparisonOperator.EQUALS, "Michal"));
User foundMichal = users.iterator().next();
// Fail, Michals rating is gone
assertThat(foundMichal.getRatings()).hasSize(1);
}
use of org.neo4j.ogm.domain.cineasts.annotated.User in project neo4j-ogm by neo4j.
the class CineastsRelationshipEntityTest method shouldSortRatings.
@Test
public void shouldSortRatings() {
Movie movie = new Movie("Pulp Fiction", 1994);
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);
// Add a rating from luanne for the same movie
User luanne = new User();
luanne.setName("luanne");
luanne.setLogin("luanne");
luanne.setPassword("luanne");
Rating rating = new Rating();
rating.setMovie(movie);
rating.setUser(luanne);
rating.setStars(3);
luanne.setRatings(Collections.singleton(rating));
session.save(luanne);
session.clear();
Collection<Rating> ratings = session.loadAll(Rating.class, new SortOrder().add(SortOrder.Direction.ASC, "stars"));
assertThat(ratings).isNotNull();
int i = 0;
for (Rating r : ratings) {
if (i++ == 0) {
assertThat(r.getStars()).isEqualTo(3);
} else {
assertThat(r.getStars()).isEqualTo(5);
}
}
}
use of org.neo4j.ogm.domain.cineasts.annotated.User in project neo4j-ogm by neo4j.
the class CineastsRelationshipEntityTest method shouldBeAbleToSetREPropertiesToNull.
/**
* @throws MalformedURLException
* @see Issue #128
*/
@Test
public void shouldBeAbleToSetREPropertiesToNull() throws MalformedURLException {
Movie movie = new Movie("Pulp Fiction", 1994);
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);
awesome.setComment("Just awesome");
michal.setRatings(Collections.singleton(awesome));
session.save(michal);
awesome.setComment(null);
session.save(awesome);
awesome = session.load(Rating.class, awesome.getId());
assertThat(awesome.getComment()).isNull();
assertThat(awesome.getStars()).isEqualTo(5);
session.clear();
awesome = session.load(Rating.class, awesome.getId());
assertThat(awesome.getComment()).isNull();
assertThat(awesome.getStars()).isEqualTo(5);
// make sure there's still just one rating
session.clear();
movie = session.load(Movie.class, movie.getUuid());
assertThat(movie.getRatings()).hasSize(1);
assertThat(movie.getRatings().iterator().next().getComment()).isNull();
}
Aggregations