use of org.neo4j.ogm.domain.cineasts.annotated.Movie in project neo4j-ogm by neo4j.
the class QueryCapabilityTest method modifyingQueryShouldBeAbleToMapEntitiesAndReturnStatistics.
// DATAGRAPH-700
@Test
public void modifyingQueryShouldBeAbleToMapEntitiesAndReturnStatistics() {
Map<String, Object> params = new HashMap<>();
params.put("name", "Vince");
params.put("age", 20);
Result result = session.query("MATCH (u:User {name:$name})-[:RATED]->(m) WITH u,m SET u.age=$age RETURN u as user, m as movie", params);
Iterator<Map<String, Object>> results = result.queryResults().iterator();
assertThat(results).isNotNull();
Map<String, Object> row = results.next();
assertThat(row).isNotNull();
User user = (User) row.get("user");
assertThat(user).isNotNull();
Movie movie = (Movie) row.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 shouldBeAbleToMapVariableDepthRelationshipsWithIncompletePaths.
// DATAGRAPH-700
@Test
public void shouldBeAbleToMapVariableDepthRelationshipsWithIncompletePaths() {
Map<String, Object> params = new HashMap<>();
params.put("name", "Vince");
params.put("title", "Top Gear");
Iterator<Map<String, Object>> results = session.query("match (u:User {name:$name}) match (m:Movie {title:$title}) match (u)-[r*0..2]-(m) return u,r,m", params).iterator();
assertThat(results).isNotNull();
Map<String, Object> result = results.next();
assertThat(result).isNotNull();
/*
Expect 2 rows:
one with (vince)-[:FRIENDS]-(michal)-[:RATED]-(topgear) where FRIENDS cannot be mapped because michal isn't known
one with (vince)-[:RATED]-(top gear) where RATED can be mapped
*/
boolean ratedRelationshipFound = false;
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");
List<Rating> ratings = (List) result.get("r");
if (ratings.size() == 1) {
// because the list of ratings with size 2= friends,rated relationships
Rating rating = ratings.get(0);
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());
ratedRelationshipFound = true;
}
assertThat(user.getFriends()).isNull();
result = results.next();
assertThat(result).isNotNull();
movie = (Movie) result.get("m");
assertThat(movie).isNotNull();
assertThat(movie.getTitle()).isEqualTo("Top Gear");
user = (User) result.get("u");
assertThat(user).isNotNull();
assertThat(user.getName()).isEqualTo("Vince");
ratings = (List) result.get("r");
if (ratings.size() == 1) {
// because the list of ratings with size 2= friends,rated relationships
Rating rating = ratings.get(0);
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());
ratedRelationshipFound = true;
}
assertThat(ratedRelationshipFound).isTrue();
assertThat(user.getFriends()).isNull();
}
use of org.neo4j.ogm.domain.cineasts.annotated.Movie in project neo4j-ogm by neo4j.
the class QueryCapabilityTest method shouldLoadNodesWithUnmappedOrNoLabels.
// #150
@Test
public void shouldLoadNodesWithUnmappedOrNoLabels() {
int movieCount = 0;
int userCount = 0;
int unmappedCount = 0;
int noLabelCount = 0;
session.query("CREATE (unknown), (m:Unmapped), (n:Movie), (n)-[:UNKNOWN]->(m)", emptyMap());
Result result = session.query("MATCH (n) return n", emptyMap());
assertThat(result).isNotNull();
Iterator<Map<String, Object>> resultIterator = result.iterator();
while (resultIterator.hasNext()) {
Map<String, Object> row = resultIterator.next();
Object n = row.get("n");
if (n instanceof User) {
userCount++;
} else if (n instanceof Movie) {
movieCount++;
} else if (n instanceof NodeModel) {
if (((NodeModel) n).getLabels().length == 0) {
noLabelCount++;
} else if (((NodeModel) n).getLabels()[0].equals("Unmapped")) {
unmappedCount++;
}
}
}
assertThat(unmappedCount).isEqualTo(1);
assertThat(noLabelCount).isEqualTo(1);
assertThat(movieCount).isEqualTo(4);
assertThat(userCount).isEqualTo(5);
}
use of org.neo4j.ogm.domain.cineasts.annotated.Movie in project neo4j-ogm by neo4j.
the class QueryCapabilityTest method shouldBeAbleToMapCollectionsFromPath.
// DATAGRAPH-700
@Test
public void shouldBeAbleToMapCollectionsFromPath() {
Iterator<Map<String, Object>> results = session.query("MATCH p=(u:User {name:$name})-[r:RATED]->(m) RETURN nodes(p) as nodes, relationships(p) as rels", Collections.singletonMap("name", "Vince")).iterator();
assertThat(results).isNotNull();
Map<String, Object> result = results.next();
assertThat(result).isNotNull();
List<Object> nodes = (List) result.get("nodes");
List<Object> rels = (List) result.get("rels");
assertThat(nodes).hasSize(2);
assertThat(rels).hasSize(1);
for (Object o : nodes) {
if (o instanceof User) {
User user = (User) o;
assertThat(user.getName()).isEqualTo("Vince");
assertThat(user.getRatings()).hasSize(1);
Movie movie = user.getRatings().iterator().next().getMovie();
assertThat(movie).isNotNull();
assertThat(movie.getTitle()).isEqualTo("Top Gear");
Rating rating = movie.getRatings().iterator().next();
assertThat(rating).isNotNull();
assertThat(rating.getStars()).isEqualTo(4);
}
}
}
use of org.neo4j.ogm.domain.cineasts.annotated.Movie in project neo4j-ogm by neo4j.
the class CineastsIntegrationTest method shouldBeAbleToSetNodePropertiesToNull.
// GH-128
@Test
public void shouldBeAbleToSetNodePropertiesToNull() throws MalformedURLException {
Movie movie = new Movie("Zootopia", 2016);
movie.setImdbUrl(new URL("http://www.imdb.com/title/tt2948356/"));
session.save(movie);
movie.setTitle(null);
movie.setImdbUrl(null);
session.save(movie);
movie = session.load(Movie.class, movie.getUuid());
assertThat(movie.getTitle()).isNull();
assertThat(movie.getImdbUrl()).isNull();
session.clear();
movie = session.load(Movie.class, movie.getUuid());
assertThat(movie.getTitle()).isNull();
assertThat(movie.getImdbUrl()).isNull();
}
Aggregations