Search in sources :

Example 16 with User

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");
    }
}
Also used : User(org.neo4j.ogm.domain.cineasts.annotated.User) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Test(org.junit.Test)

Example 17 with User

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");
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) User(org.neo4j.ogm.domain.cineasts.annotated.User) Filter(org.neo4j.ogm.cypher.Filter) Actor(org.neo4j.ogm.domain.cineasts.annotated.Actor) Rating(org.neo4j.ogm.domain.cineasts.annotated.Rating) Test(org.junit.Test)

Example 18 with User

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);
}
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) Test(org.junit.Test)

Example 19 with User

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);
        }
    }
}
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) SortOrder(org.neo4j.ogm.cypher.query.SortOrder) Test(org.junit.Test)

Example 20 with User

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();
}
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

User (org.neo4j.ogm.domain.cineasts.annotated.User)46 Test (org.junit.Test)45 Movie (org.neo4j.ogm.domain.cineasts.annotated.Movie)25 Rating (org.neo4j.ogm.domain.cineasts.annotated.Rating)24 Filter (org.neo4j.ogm.cypher.Filter)19 ExtendedUser (org.neo4j.ogm.domain.cineasts.annotated.ExtendedUser)17 Map (java.util.Map)12 HashMap (java.util.HashMap)11 HashSet (java.util.HashSet)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Filters (org.neo4j.ogm.cypher.Filters)3 Pet (org.neo4j.ogm.domain.cineasts.annotated.Pet)3 Pagination (org.neo4j.ogm.cypher.query.Pagination)2 SortOrder (org.neo4j.ogm.cypher.query.SortOrder)2 Plays (org.neo4j.ogm.domain.cineasts.annotated.Plays)2 Result (org.neo4j.ogm.model.Result)2 Session (org.neo4j.ogm.session.Session)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URL (java.net.URL)1