Search in sources :

Example 1 with Movie

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);
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) Actor(org.neo4j.ogm.domain.cineasts.annotated.Actor) Test(org.junit.Test)

Example 2 with Movie

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();
}
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 3 with Movie

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();
}
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) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 4 with Movie

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();
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 5 with Movie

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();
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) 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