use of org.neo4j.ogm.domain.cineasts.annotated.Movie in project neo4j-ogm by neo4j.
the class RelationshipEntityMappingTest method testThatRelationshipEntityNameIsUsedAsRelationshipTypeWhenTypeIsNotDefined.
@Test
public void testThatRelationshipEntityNameIsUsedAsRelationshipTypeWhenTypeIsNotDefined() {
Movie hp = new Movie("Goblet of Fire", 2005);
Actor daniel = new Actor("Daniel Radcliffe");
daniel.nominatedFor(hp, "Saturn Award", 2005);
session.save(daniel);
session.clear();
assertThat(session.query("MATCH (m:Movie {uuid:\"" + hp.getUuid().toString() + "\"}), " + "(a:Actor {uuid:\"" + daniel.getUuid().toString() + "\"}) " + " WHERE m.title = 'Goblet of Fire' and m.year = 2005 " + " and a.name='Daniel Radcliffe' and (a)-[:NOMINATIONS {name:'Saturn Award', year:2005}]->(m) " + " return m, a", emptyMap()).queryResults()).hasSize(1);
}
use of org.neo4j.ogm.domain.cineasts.annotated.Movie in project neo4j-ogm by neo4j.
the class QueryCapabilityTest method shouldBeAbleToMapEntities.
// DATAGRAPH-700
@Test
public void shouldBeAbleToMapEntities() {
Iterator<Map<String, Object>> results = session.query("MATCH (u:User {name:$name})-[:RATED]->(m) RETURN u as user, m as movie", Collections.singletonMap("name", "Vince")).iterator();
assertThat(results).isNotNull();
Map<String, Object> result = results.next();
assertThat(result).isNotNull();
User user = (User) result.get("user");
assertThat(user).isNotNull();
Movie movie = (Movie) result.get("movie");
assertThat(movie).isNotNull();
assertThat(user.getName()).isEqualTo("Vince");
assertThat(movie.getTitle()).isEqualTo("Top Gear");
assertThat(results.hasNext()).isFalse();
}
use of org.neo4j.ogm.domain.cineasts.annotated.Movie in project neo4j-ogm by neo4j.
the class QueryCapabilityTest method shouldBeAbleToMapCollectionsOfNodes.
// DATAGRAPH-700
@Test
public void shouldBeAbleToMapCollectionsOfNodes() {
Iterator<Map<String, Object>> results = session.query("match (u:User {name:$name})-[r:RATED]->(m) return u as user,collect(r), collect(m) as movies", Collections.singletonMap("name", "Michal")).iterator();
assertThat(results).isNotNull();
Map<String, Object> result = results.next();
assertThat(result).isNotNull();
assertThat(((User) result.get("user")).getName()).isEqualTo("Michal");
List<Rating> ratings = (List) result.get("collect(r)");
assertThat(ratings).hasSize(2);
for (Rating rating : ratings) {
assertThat(rating.getUser().getName()).isEqualTo("Michal");
}
List<Movie> movies = (List) result.get("movies");
assertThat(movies).hasSize(2);
for (Movie movie : movies) {
if (movie.getRatings().iterator().next().getStars() == 3) {
assertThat(movie.getTitle()).isEqualTo("Top Gear");
} else {
assertThat(movie.getTitle()).isEqualTo("Pulp Fiction");
assertThat(movie.getRatings().iterator().next().getStars()).isEqualTo(5);
}
}
assertThat(results.hasNext()).isFalse();
}
use of org.neo4j.ogm.domain.cineasts.annotated.Movie in project neo4j-ogm by neo4j.
the class QueryCapabilityTest method shouldBeAbleToMapEntitiesAndScalarsMultipleRows.
// DATAGRAPH-700
@Test
public void shouldBeAbleToMapEntitiesAndScalarsMultipleRows() {
Iterator<Map<String, Object>> results = session.query("MATCH (u:User)-[r:RATED]->(m) RETURN m as movie, avg(r.stars) as average ORDER BY average DESC", emptyMap()).iterator();
assertThat(results).isNotNull();
Map<String, Object> result = results.next();
assertThat(result).isNotNull();
Movie movie = (Movie) result.get("movie");
assertThat(movie).isNotNull();
assertThat(movie.getTitle()).isEqualTo("Pulp Fiction");
Number avg = (Number) result.get("average");
assertThat(avg).isEqualTo(5.0);
result = results.next();
movie = (Movie) result.get("movie");
assertThat(movie).isNotNull();
assertThat(movie.getTitle()).isEqualTo("Top Gear");
avg = (Number) result.get("average");
assertThat(avg).isEqualTo(3.5);
assertThat(results.hasNext()).isFalse();
}
use of org.neo4j.ogm.domain.cineasts.annotated.Movie in project neo4j-ogm by neo4j.
the class QueryCapabilityTest method shouldBeAbleToMapEntitiesAndScalarsMultipleRowsAndNoAlias.
// DATAGRAPH-700
@Test
public void shouldBeAbleToMapEntitiesAndScalarsMultipleRowsAndNoAlias() {
Iterator<Map<String, Object>> results = session.query("MATCH (u:User)-[r:RATED]->(m) RETURN m, avg(r.stars) ORDER BY avg(r.stars) DESC", emptyMap()).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("Pulp Fiction");
Number avg = (Number) result.get("avg(r.stars)");
assertThat(avg).isEqualTo(5.0);
result = results.next();
movie = (Movie) result.get("m");
assertThat(movie).isNotNull();
assertThat(movie.getTitle()).isEqualTo("Top Gear");
avg = (Number) result.get("avg(r.stars)");
assertThat(avg).isEqualTo(3.5);
assertThat(results.hasNext()).isFalse();
}
Aggregations