Search in sources :

Example 1 with Actor

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

use of org.neo4j.ogm.domain.cineasts.annotated.Actor in project neo4j-ogm by neo4j.

the class QueryCapabilityTest method modifyingQueryShouldBePermittedWhenQueryingForObjects.

// DATAGRAPH-697
@Test
public void modifyingQueryShouldBePermittedWhenQueryingForObjects() {
    session.save(new Actor("Jeff"));
    session.save(new Actor("John"));
    session.save(new Actor("Colin"));
    Iterable<Actor> actors = session.query(Actor.class, "MATCH (a:Actor) set a.age=$age return a", Collections.singletonMap("age", 40));
    assertThat(actors).isNotNull();
    List<String> names = new ArrayList<>();
    Iterator<Actor> actorIterator = actors.iterator();
    while (actorIterator.hasNext()) {
        names.add(actorIterator.next().getName());
    }
    assertThat(names).hasSize(3);
    assertThat(names.contains("Jeff")).isTrue();
    assertThat(names.contains("John")).isTrue();
    assertThat(names.contains("Colin")).isTrue();
}
Also used : Actor(org.neo4j.ogm.domain.cineasts.annotated.Actor) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with Actor

use of org.neo4j.ogm.domain.cineasts.annotated.Actor in project neo4j-ogm by neo4j.

the class QueryCapabilityTest method modifyingQueryShouldReturnStatistics.

// DATAGRAPH-697
@Test
public void modifyingQueryShouldReturnStatistics() {
    session.save(new Actor("Jeff"));
    session.save(new Actor("John"));
    session.save(new Actor("Colin"));
    Result result = session.query("MATCH (a:Actor) SET a.age=$age", Collections.singletonMap("age", 5), false);
    assertThat(result).isNotNull();
    assertThat(result.queryStatistics()).isNotNull();
    assertThat(result.queryStatistics().getPropertiesSet()).isEqualTo(3);
    result = session.query("MATCH (a:Actor) SET a.age=$age", Collections.singletonMap("age", 5));
    assertThat(result).isNotNull();
    assertThat(result.queryStatistics()).isNotNull();
    assertThat(result.queryStatistics().getPropertiesSet()).isEqualTo(3);
}
Also used : Actor(org.neo4j.ogm.domain.cineasts.annotated.Actor) Result(org.neo4j.ogm.model.Result) Test(org.junit.Test)

Example 4 with Actor

use of org.neo4j.ogm.domain.cineasts.annotated.Actor in project neo4j-ogm by neo4j.

the class QueryCapabilityTest method shouldQueryForArbitraryDataUsingBespokeParameterisedCypherQuery.

// DATAGRAPH-697
@Test
public void shouldQueryForArbitraryDataUsingBespokeParameterisedCypherQuery() {
    session.save(new Actor("Helen Mirren"));
    Actor alec = new Actor("Alec Baldwin");
    session.save(alec);
    session.save(new Actor("Matt Damon"));
    Iterable<Map<String, Object>> resultsIterable = session.query("MATCH (a:Actor) WHERE a.uuid=$param RETURN a.name as name", Collections.<String, Object>singletonMap("param", // make sure the change is backward compatible
    alec.getUuid()));
    assertThat(resultsIterable).as("Results are empty").isNotNull();
    Map<String, Object> row = resultsIterable.iterator().next();
    assertThat(row.get("name")).isEqualTo("Alec Baldwin");
    Result results = session.query("MATCH (a:Actor) WHERE a.uuid=$param RETURN a.name as name", Collections.<String, Object>singletonMap("param", alec.getUuid()));
    assertThat(results).as("Results are empty").isNotNull();
    assertThat(results.iterator().next().get("name")).isEqualTo("Alec Baldwin");
}
Also used : Actor(org.neo4j.ogm.domain.cineasts.annotated.Actor) Map(java.util.Map) HashMap(java.util.HashMap) Result(org.neo4j.ogm.model.Result) Test(org.junit.Test)

Example 5 with Actor

use of org.neo4j.ogm.domain.cineasts.annotated.Actor in project neo4j-ogm by neo4j.

the class QueryCapabilityTest method modifyingQueryShouldReturnResultsWithStatistics.

// DATAGRAPH-697
@Test
public void modifyingQueryShouldReturnResultsWithStatistics() {
    session.save(new Actor("Jeff"));
    session.save(new Actor("John"));
    session.save(new Actor("Colin"));
    Result result = session.query("MATCH (a:Actor) SET a.age=$age RETURN a.name", Collections.singletonMap("age", 5), false);
    assertThat(result).isNotNull();
    assertThat(result.queryStatistics()).isNotNull();
    assertThat(result.queryStatistics().getPropertiesSet()).isEqualTo(3);
    List<String> names = new ArrayList<>();
    Iterator<Map<String, Object>> namesIterator = result.queryResults().iterator();
    while (namesIterator.hasNext()) {
        names.add((String) namesIterator.next().get("a.name"));
    }
    assertThat(names).hasSize(3);
    assertThat(names.contains("Jeff")).isTrue();
    assertThat(names.contains("John")).isTrue();
    assertThat(names.contains("Colin")).isTrue();
    result = session.query("MATCH (a:Actor) SET a.age=$age RETURN a.name, a.age", Collections.singletonMap("age", 5));
    assertThat(result).isNotNull();
    assertThat(result.queryStatistics()).isNotNull();
    assertThat(result.queryStatistics().getPropertiesSet()).isEqualTo(3);
    names = new ArrayList<>();
    namesIterator = result.queryResults().iterator();
    while (namesIterator.hasNext()) {
        Map<String, Object> row = namesIterator.next();
        names.add((String) row.get("a.name"));
        assertThat(((Number) row.get("a.age")).longValue()).isEqualTo(5L);
    }
    assertThat(names).hasSize(3);
    assertThat(names.contains("Jeff")).isTrue();
    assertThat(names.contains("John")).isTrue();
    assertThat(names.contains("Colin")).isTrue();
}
Also used : Actor(org.neo4j.ogm.domain.cineasts.annotated.Actor) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) Result(org.neo4j.ogm.model.Result) Test(org.junit.Test)

Aggregations

Actor (org.neo4j.ogm.domain.cineasts.annotated.Actor)27 Test (org.junit.Test)25 Movie (org.neo4j.ogm.domain.cineasts.annotated.Movie)7 HashMap (java.util.HashMap)6 Knows (org.neo4j.ogm.domain.cineasts.annotated.Knows)6 Map (java.util.Map)5 Result (org.neo4j.ogm.model.Result)5 Date (java.util.Date)4 Filter (org.neo4j.ogm.cypher.Filter)4 ArrayList (java.util.ArrayList)3 Document (org.neo4j.ogm.domain.filesystem.Document)3 Arrays (java.util.Arrays)2 EnumSet (java.util.EnumSet)2 List (java.util.List)2 Assertions (org.assertj.core.api.Assertions)2 Before (org.junit.Before)2 Role (org.neo4j.ogm.domain.cineasts.annotated.Role)2 Event (org.neo4j.ogm.session.event.Event)2 Transaction (org.neo4j.ogm.transaction.Transaction)2 HashSet (java.util.HashSet)1