Search in sources :

Example 21 with Actor

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

the class RelationshipEntityMappingTest method shouldBeAbleToSaveAndLoadRelationshipEntityWithNullProperties.

@Test
public void shouldBeAbleToSaveAndLoadRelationshipEntityWithNullProperties() {
    Actor keanu = new Actor("Keanu Reeves");
    Movie matrix = new Movie("The Matrix", 1999);
    HashSet<Role> roles = new HashSet<>();
    Role role = new Role(matrix, keanu, null);
    roles.add(role);
    keanu.setRoles(roles);
    session.save(keanu);
    Map<String, Object> params = new HashMap<>();
    params.put("actorId", keanu.getUuid());
    Result result = session.query("MATCH (a:Actor)-[r:ACTS_IN]-(m:Movie) WHERE a.uuid = $actorId RETURN r as rel", params, true);
    Iterator<Map<String, Object>> iterator = result.iterator();
    Map<String, Object> first = iterator.next();
    assertThat(role).isSameAs(first.get("rel"));
}
Also used : Role(org.neo4j.ogm.domain.cineasts.annotated.Role) Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) HashMap(java.util.HashMap) Actor(org.neo4j.ogm.domain.cineasts.annotated.Actor) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) Result(org.neo4j.ogm.model.Result) Test(org.junit.Test)

Example 22 with Actor

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

the class RelationshipEntityMappingTest method testThatAnnotatedRelationshipOnRelationshipEntityCreatesTheCorrectRelationshipTypeInTheGraph.

@Test
public void testThatAnnotatedRelationshipOnRelationshipEntityCreatesTheCorrectRelationshipTypeInTheGraph() {
    Movie hp = new Movie("Goblet of Fire", 2005);
    Actor daniel = new Actor("Daniel Radcliffe");
    daniel.playedIn(hp, "Harry Potter");
    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)-[:ACTS_IN {role:'Harry Potter'}]->(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 23 with Actor

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

the class QueryCapabilityTest method modifyingQueryShouldBePermittedWhenQueryingForObject.

// DATAGRAPH-697
@Test
public void modifyingQueryShouldBePermittedWhenQueryingForObject() {
    session.save(new Actor("Jeff"));
    session.save(new Actor("John"));
    session.save(new Actor("Colin"));
    Map<String, Object> params = new HashMap<>();
    params.put("name", "Jeff");
    params.put("age", 40);
    Actor jeff = session.queryForObject(Actor.class, "MATCH (a:Actor {name:$name}) set a.age=$age return a", params);
    assertThat(jeff).isNotNull();
    assertThat(jeff.getName()).isEqualTo("Jeff");
}
Also used : HashMap(java.util.HashMap) Actor(org.neo4j.ogm.domain.cineasts.annotated.Actor) Test(org.junit.Test)

Example 24 with Actor

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

the class QueryCapabilityTest method readOnlyQueryMustBeReadOnly.

// DATAGRAPH-697
@Test
public void readOnlyQueryMustBeReadOnly() {
    session.save(new Actor("Jeff"));
    if (isVersionOrGreater("4.1") && isBoltDriver()) {
        // 4.1+ will fail on any attempt to write in a read-only transaction.
        assertThatThrownBy(() -> session.query("MATCH (a:Actor) SET a.age=$age", Collections.singletonMap("age", 5), true)).hasMessageContaining("Writing in read access mode not allowed.");
    } else {
        session.query("MATCH (a:Actor) SET a.age=$age", Collections.singletonMap("age", 5), true);
        Condition<String> stringMatches = new Condition<>(s -> s.contains("Cypher query contains keywords that indicate a writing query but OGM is going to use a read only transaction as requested, so the query might fail."), "String matches");
        assertThat(loggerRule.getFormattedMessages()).areAtLeastOne(stringMatches);
    }
}
Also used : Condition(org.assertj.core.api.Condition) Actor(org.neo4j.ogm.domain.cineasts.annotated.Actor) Test(org.junit.Test)

Example 25 with Actor

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

the class QueryCapabilityTest method shouldBeAbleToHandleNullValuesInQueryResults.

@Test
public void shouldBeAbleToHandleNullValuesInQueryResults() {
    session.save(new Actor("Jeff"));
    Iterable<Map<String, Object>> results = session.query("MATCH (a:Actor) return a.nonExistent as nonExistent", emptyMap());
    Map<String, Object> result = results.iterator().next();
    assertThat(result.get("nonExistent")).isNull();
}
Also used : Actor(org.neo4j.ogm.domain.cineasts.annotated.Actor) Map(java.util.Map) HashMap(java.util.HashMap) 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