Search in sources :

Example 36 with User

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

the class CineastsRelationshipEntityTest method shouldLoadASingleRating.

@Test
public void shouldLoadASingleRating() {
    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();
    Rating loadedRating = session.load(Rating.class, rating.getId(), 3);
    assertThat(loadedRating).isNotNull();
    assertThat(loadedRating.getId()).isEqualTo(rating.getId());
    assertThat(loadedRating.getStars()).isEqualTo(rating.getStars());
}
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)

Example 37 with User

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

the class UserTest method testDeserialiseUserWithArrayOfEnums.

@Test
public void testDeserialiseUserWithArrayOfEnums() {
    MetaData metadata = new MetaData("org.neo4j.ogm.domain.cineasts.annotated");
    Neo4jSession session = new Neo4jSession(metadata, true, new UsersRequest());
    User user = session.load(User.class, "luanne", 1);
    assertThat(user.getLogin()).isEqualTo("luanne");
    assertThat(user.getSecurityRoles()).isNotNull();
    assertThat(user.getSecurityRoles().length).isEqualTo(2);
}
Also used : User(org.neo4j.ogm.domain.cineasts.annotated.User) MetaData(org.neo4j.ogm.metadata.MetaData) Neo4jSession(org.neo4j.ogm.session.Neo4jSession) Test(org.junit.Test)

Example 38 with User

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

the class LookupByPrimaryIndexTests method loadUsesPrimaryIndexWhenPresentOnSuperclass.

@Test
public void loadUsesPrimaryIndexWhenPresentOnSuperclass() {
    ExtendedUser user1 = new ExtendedUser("login2", "Name 2", "password");
    session.save(user1);
    final Session session2 = sessionFactory.openSession();
    final User retrievedUser1 = session2.load(ExtendedUser.class, "login2");
    assertThat(retrievedUser1).isNotNull();
    assertThat(retrievedUser1.getLogin()).isEqualTo(user1.getLogin());
}
Also used : User(org.neo4j.ogm.domain.cineasts.annotated.User) ExtendedUser(org.neo4j.ogm.domain.cineasts.annotated.ExtendedUser) ExtendedUser(org.neo4j.ogm.domain.cineasts.annotated.ExtendedUser) Session(org.neo4j.ogm.session.Session) Test(org.junit.Test)

Example 39 with User

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

the class LookupByPrimaryIndexTests method loadShouldNotMixPrimaryKeysOfDifferentLabels.

@Test
public void loadShouldNotMixPrimaryKeysOfDifferentLabels() {
    User user = new User("login", "name", "password");
    session.save(user);
    IdAndGenerationType entity = new IdAndGenerationType();
    entity.identifier = "login";
    session.save(entity);
    User loadedUser = session.load(User.class, "login");
    assertThat(loadedUser).isEqualTo(user);
    IdAndGenerationType loadedEntity = session.load(IdAndGenerationType.class, "login");
    assertThat(loadedEntity).isEqualTo(entity);
}
Also used : User(org.neo4j.ogm.domain.cineasts.annotated.User) ExtendedUser(org.neo4j.ogm.domain.cineasts.annotated.ExtendedUser) IdAndGenerationType(org.neo4j.ogm.domain.annotations.ids.ValidAnnotations.IdAndGenerationType) Test(org.junit.Test)

Example 40 with User

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

the class LookupByPrimaryIndexTests method loadAllUsesPrimaryIndexWhenPresent.

@Test
public void loadAllUsesPrimaryIndexWhenPresent() {
    User user1 = new User("login1", "Name 1", "password");
    session.save(user1);
    User user2 = new User("login2", "Name 2", "password");
    session.save(user2);
    session.clear();
    Collection<User> users = session.loadAll(User.class, asList("login1", "login2"));
    assertThat(users.size()).isEqualTo(2);
    session.clear();
    users = session.loadAll(User.class, asList("login1", "login2"), 0);
    assertThat(users.size()).isEqualTo(2);
    session.clear();
    users = session.loadAll(User.class, asList("login1", "login2"), -1);
    assertThat(users.size()).isEqualTo(2);
}
Also used : User(org.neo4j.ogm.domain.cineasts.annotated.User) ExtendedUser(org.neo4j.ogm.domain.cineasts.annotated.ExtendedUser) 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