Search in sources :

Example 41 with Movie

use of org.neo4j.ogm.domain.cineasts.annotated.Movie 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)

Aggregations

Test (org.junit.Test)41 Movie (org.neo4j.ogm.domain.cineasts.annotated.Movie)41 User (org.neo4j.ogm.domain.cineasts.annotated.User)25 Rating (org.neo4j.ogm.domain.cineasts.annotated.Rating)24 Filter (org.neo4j.ogm.cypher.Filter)17 HashMap (java.util.HashMap)11 Map (java.util.Map)11 ExtendedUser (org.neo4j.ogm.domain.cineasts.annotated.ExtendedUser)8 Actor (org.neo4j.ogm.domain.cineasts.annotated.Actor)7 HashSet (java.util.HashSet)6 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Result (org.neo4j.ogm.model.Result)3 Filters (org.neo4j.ogm.cypher.Filters)2 Pet (org.neo4j.ogm.domain.cineasts.annotated.Pet)2 Plays (org.neo4j.ogm.domain.cineasts.annotated.Plays)2 Role (org.neo4j.ogm.domain.cineasts.annotated.Role)2 URL (java.net.URL)1 Pagination (org.neo4j.ogm.cypher.query.Pagination)1 SortOrder (org.neo4j.ogm.cypher.query.SortOrder)1