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