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"));
}
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);
}
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");
}
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);
}
}
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();
}
Aggregations