Search in sources :

Example 16 with Actor

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

the class CineastsIntegrationTest method shouldQueryForActorByIdUsingBespokeParameterisedCypherQuery.

@Test
public void shouldQueryForActorByIdUsingBespokeParameterisedCypherQuery() {
    session.save(new Actor("Keanu Reeves"));
    Actor carrie = new Actor("Carrie-Ann Moss");
    session.save(carrie);
    session.save(new Actor("Laurence Fishbourne"));
    Actor loadedActor = session.queryForObject(Actor.class, "MATCH (a:Actor) WHERE a.uuid=$param RETURN a", Collections.<String, Object>singletonMap("param", carrie.getUuid()));
    assertThat(loadedActor).as("The entity wasn't loaded").isNotNull();
    assertThat(loadedActor.getName()).isEqualTo("Carrie-Ann Moss");
}
Also used : Actor(org.neo4j.ogm.domain.cineasts.annotated.Actor) Test(org.junit.Test)

Example 17 with Actor

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

the class CineastsIntegrationTest method shouldQueryForCollectionOfActorsUsingBespokeCypherQuery.

@Test
public void shouldQueryForCollectionOfActorsUsingBespokeCypherQuery() {
    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) WHERE a.name=~'J.*' RETURN a", Collections.<String, Object>emptyMap());
    assertThat(actors).as("The entities weren't loaded").isNotNull();
    assertThat(actors.iterator().hasNext()).as("The entity wasn't loaded").isTrue();
    assertThat(actors).extracting(Actor::getName).containsOnly("John", "Jeff");
}
Also used : Actor(org.neo4j.ogm.domain.cineasts.annotated.Actor) Test(org.junit.Test)

Example 18 with Actor

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

the class CineastsRelationshipEntityTest method shouldSaveRelationshipEntityWithCamelCaseStartEndNodes.

// DATAGRAPH-567
@Test
public void shouldSaveRelationshipEntityWithCamelCaseStartEndNodes() {
    Actor bruce = new Actor("Bruce");
    Actor jim = new Actor("Jim");
    Knows knows = new Knows();
    knows.setFirstActor(bruce);
    knows.setSecondActor(jim);
    knows.setSince(new Date());
    bruce.getKnows().add(knows);
    session.save(bruce);
    Actor actor = TestUtils.firstOrNull(session.loadAll(Actor.class, new Filter("name", ComparisonOperator.EQUALS, "Bruce")));
    assertThat(actor).isNotNull();
    assertThat(actor.getKnows()).hasSize(1);
    assertThat(actor.getKnows().iterator().next().getSecondActor().getName()).isEqualTo("Jim");
}
Also used : Filter(org.neo4j.ogm.cypher.Filter) Actor(org.neo4j.ogm.domain.cineasts.annotated.Actor) Knows(org.neo4j.ogm.domain.cineasts.annotated.Knows) Date(java.util.Date) Test(org.junit.Test)

Example 19 with Actor

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

the class CineastsRelationshipEntityTest method shouldSaveSameRoleTwiceRelationshipBetweenTheSameTwoObjects.

@Test
public void shouldSaveSameRoleTwiceRelationshipBetweenTheSameTwoObjects() {
    Movie movie = new Movie("The big John Travolta Party", 2016);
    Actor actor = new Actor("John Travolta");
    actor.playedIn(movie, "He danced mostly");
    assertThat(actor.getRoles()).hasSize(1);
    session.save(actor);
    session.clear();
    Actor loadedActor = session.load(Actor.class, actor.getUuid());
    assertThat(loadedActor.getRoles()).hasSize(1);
    // Add an identical role
    actor.playedIn(movie, "He danced mostly");
    assertThat(actor.getRoles()).hasSize(2);
    session.save(actor);
    session.clear();
    loadedActor = session.load(Actor.class, actor.getUuid());
    assertThat(loadedActor.getRoles()).hasSize(2);
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) Actor(org.neo4j.ogm.domain.cineasts.annotated.Actor) Test(org.junit.Test)

Example 20 with Actor

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

the class CineastsRelationshipEntityTest method shouldSaveRelationshipEntityWithNullProperty.

// DATAGRAPH-610
@Test
public void shouldSaveRelationshipEntityWithNullProperty() {
    Actor bruce = new Actor("Bruce");
    Actor jim = new Actor("Jim");
    // since = null
    Knows knows = new Knows();
    knows.setFirstActor(bruce);
    knows.setSecondActor(jim);
    bruce.getKnows().add(knows);
    session.save(bruce);
    Actor actor = TestUtils.firstOrNull(session.loadAll(Actor.class, new Filter("name", ComparisonOperator.EQUALS, "Bruce")));
    assertThat(actor).isNotNull();
    assertThat(actor.getKnows()).hasSize(1);
    assertThat(actor.getKnows().iterator().next().getSecondActor().getName()).isEqualTo("Jim");
    bruce.getKnows().iterator().next().setSince(new Date());
    session.save(bruce);
    actor = TestUtils.firstOrNull(session.loadAll(Actor.class, new Filter("name", ComparisonOperator.EQUALS, "Bruce")));
    assertThat(actor.getKnows()).hasSize(1);
    assertThat(actor.getKnows().iterator().next().getSince()).isNotNull();
    bruce.getKnows().iterator().next().setSince(null);
    session.save(bruce);
    actor = TestUtils.firstOrNull(session.loadAll(Actor.class, new Filter("name", ComparisonOperator.EQUALS, "Bruce")));
    assertThat(actor.getKnows()).hasSize(1);
    assertThat(actor.getKnows().iterator().next().getSince()).isNull();
}
Also used : Filter(org.neo4j.ogm.cypher.Filter) Actor(org.neo4j.ogm.domain.cineasts.annotated.Actor) Knows(org.neo4j.ogm.domain.cineasts.annotated.Knows) Date(java.util.Date) 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