Search in sources :

Example 41 with User

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

the class LookupByPrimaryIndexTests method loadUsesPrimaryIndexWhenPresent.

@Test
public void loadUsesPrimaryIndexWhenPresent() {
    User user1 = new User("login1", "Name 1", "password");
    session.save(user1);
    final Session session2 = sessionFactory.openSession();
    final User retrievedUser1 = session2.load(User.class, "login1");
    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) Session(org.neo4j.ogm.session.Session) Test(org.junit.Test)

Example 42 with User

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

the class QueryCapabilityTest method shouldBeAbleToMapRelationshipEntities.

// DATAGRAPH-700
@Test
public void shouldBeAbleToMapRelationshipEntities() {
    Iterator<Map<String, Object>> results = session.query("MATCH (u:User {name:$name})-[r:RATED]->(m) RETURN u,r,m", Collections.singletonMap("name", "Vince")).iterator();
    assertThat(results).isNotNull();
    Map<String, Object> result = results.next();
    assertThat(result).isNotNull();
    Movie movie = (Movie) result.get("m");
    assertThat(movie).isNotNull();
    assertThat(movie.getTitle()).isEqualTo("Top Gear");
    User user = (User) result.get("u");
    assertThat(user).isNotNull();
    assertThat(user.getName()).isEqualTo("Vince");
    Rating rating = (Rating) result.get("r");
    assertThat(rating).isNotNull();
    assertThat(rating.getStars()).isEqualTo(4);
    assertThat(movie.getRatings().iterator().next().getId()).isEqualTo(rating.getId());
    assertThat(user.getRatings().iterator().next().getId()).isEqualTo(rating.getId());
    assertThat(results.hasNext()).isFalse();
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) ExtendedUser(org.neo4j.ogm.domain.cineasts.annotated.ExtendedUser) User(org.neo4j.ogm.domain.cineasts.annotated.User) Rating(org.neo4j.ogm.domain.cineasts.annotated.Rating) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 43 with User

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

the class QueryCapabilityTest method shouldBeAbleToMapEntitiesAndScalars.

// DATAGRAPH-700
@Test
public void shouldBeAbleToMapEntitiesAndScalars() {
    Iterator<Map<String, Object>> results = session.query("MATCH (u:User {name:$name})-[:RATED]->(m) RETURN u as user, count(m) as count", Collections.singletonMap("name", "Michal")).iterator();
    assertThat(results).isNotNull();
    Map<String, Object> result = results.next();
    assertThat(result).isNotNull();
    User user = (User) result.get("user");
    assertThat(user).isNotNull();
    assertThat(user.getName()).isEqualTo("Michal");
    Number count = (Number) result.get("count");
    assertThat(count.longValue()).isEqualTo(2L);
    assertThat(results.hasNext()).isFalse();
}
Also used : ExtendedUser(org.neo4j.ogm.domain.cineasts.annotated.ExtendedUser) User(org.neo4j.ogm.domain.cineasts.annotated.User) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 44 with User

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

the class QueryCapabilityTest method shouldBeAbleToMapEntitiesAndRelationshipsOfDifferentTypes.

// DATAGRAPH-700
@Test
public void shouldBeAbleToMapEntitiesAndRelationshipsOfDifferentTypes() {
    Iterator<Map<String, Object>> results = session.query("MATCH (u:User {name:$name})-[r:FRIENDS]->(friend)-[r2:RATED]->(m) RETURN u as user, friend as friend, r, r2, m as movie, r2.stars as stars", Collections.singletonMap("name", "Michal")).iterator();
    assertThat(results).isNotNull();
    Map<String, Object> result = results.next();
    assertThat(result).isNotNull();
    User user = (User) result.get("user");
    assertThat(user).isNotNull();
    assertThat(user.getName()).isEqualTo("Michal");
    User friend = (User) result.get("friend");
    assertThat(friend).isNotNull();
    assertThat(friend.getName()).isEqualTo("Vince");
    assertThat(user.getFriends().iterator().next().getName()).isEqualTo(friend.getName());
    Movie topGear = (Movie) result.get("movie");
    assertThat(topGear).isNotNull();
    assertThat(topGear.getTitle()).isEqualTo("Top Gear");
    assertThat(friend.getRatings()).hasSize(1);
    assertThat(friend.getRatings().iterator().next().getMovie().getTitle()).isEqualTo(topGear.getTitle());
    Number stars = (Number) result.get("stars");
    assertThat(stars.longValue()).isEqualTo(4L);
    assertThat(results.hasNext()).isFalse();
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) ExtendedUser(org.neo4j.ogm.domain.cineasts.annotated.ExtendedUser) User(org.neo4j.ogm.domain.cineasts.annotated.User) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 45 with User

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

the class QueryCapabilityTest method checkForMichal.

private static boolean checkForMichal(Map<String, Object> result) {
    if (result.get("n") instanceof User) {
        User u = (User) result.get("n");
        if (u.getName().equals("Michal")) {
            assertThat(u.getFriends()).hasSize(1);
            assertThat(u.getFriends().iterator().next().getName()).isEqualTo("Vince");
            return true;
        }
    }
    return false;
}
Also used : ExtendedUser(org.neo4j.ogm.domain.cineasts.annotated.ExtendedUser) User(org.neo4j.ogm.domain.cineasts.annotated.User)

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