Search in sources :

Example 1 with Actor

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

the class RelationshipEntityPartialMappingTest method testCreateActorRoleAndMovie.

@Test
public void testCreateActorRoleAndMovie() {
    Actor keanu = new Actor("Keanu Reeves");
    Movie matrix = new Movie("The Matrix");
    // note: this does not establish a role relationship on the matrix
    keanu.addRole("Neo", matrix);
    session.save(keanu);
    session.clear();
    assertThat(session.query("MATCH (a:Actor {name:'Keanu Reeves'}), " + "(m:Movie {name:'The Matrix'}) " + "WHERE (a)-[:ACTS_IN {played:'Neo'}]->(m) return a, m", emptyMap()).queryResults()).hasSize(1);
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.minimum.Movie) Actor(org.neo4j.ogm.domain.cineasts.minimum.Actor) Test(org.junit.Test)

Example 2 with Actor

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

the class RelationshipEntityPartialMappingTest method testCreateAndDeleteActorMultipleRolesAndMovies.

@Test
public void testCreateAndDeleteActorMultipleRolesAndMovies() {
    Actor keanu = new Actor("Keanu Reeves");
    Movie matrix = new Movie("The Matrix");
    Movie hp = new Movie("Harry Potter");
    keanu.addRole("Neo", matrix);
    keanu.addRole("Dumbledore", hp);
    session.save(keanu);
    Actor keanu2 = session.load(Actor.class, keanu.getId());
    assertThat(keanu2.roles()).hasSize(2);
    keanu2.removeRole("Dumbledore");
    session.save(keanu2);
    Actor keanu3 = session.load(Actor.class, keanu2.getId());
    assertThat(keanu3.roles()).hasSize(1);
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.minimum.Movie) Actor(org.neo4j.ogm.domain.cineasts.minimum.Actor) Test(org.junit.Test)

Example 3 with Actor

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

the class SingleUseEntityMapperTest method oneTimeSetUp.

@BeforeClass
public static void oneTimeSetUp() {
    sessionFactory = new SessionFactory(getDriver(), "org.neo4j.ogm.domain.gh551", "org.neo4j.ogm.domain.gh391", "org.neo4j.ogm.domain.gh750", "org.neo4j.ogm.domain.gh777", "org.neo4j.ogm.domain.cineasts.minimum", "org.neo4j.ogm.domain.gh813", "org.neo4j.ogm.domain.gh873");
    // Prepare test data
    Session session = sessionFactory.openSession();
    session.query("MATCH (n) DETACH DELETE n", EMPTY_MAP);
    session.query("unwind range(1,10) as x with x create (n:ThingEntity {name: 'Thing ' + x}) return n", EMPTY_MAP);
    Actor actor = new Actor("A1");
    Movie movie = new Movie("M1");
    Role role = new Role("R1", actor, movie);
    session.save(role);
    movie = new Movie("M2");
    role = new Role("R2", actor, movie);
    session.save(role);
    session.save(new UserInfo("Foo", "Bar", "i@do.com"));
    MyNode myNode = new MyNode();
    myNode.setId("the-id");
    myNode.setType("the-type");
    myNode.getAttributes().put("a1", "v1");
    myNode.getAttributes().put("a2", "v2");
    session.save(myNode);
}
Also used : SessionFactory(org.neo4j.ogm.session.SessionFactory) Role(org.neo4j.ogm.domain.cineasts.minimum.Role) Movie(org.neo4j.ogm.domain.cineasts.minimum.Movie) Actor(org.neo4j.ogm.domain.cineasts.minimum.Actor) UserInfo(org.neo4j.ogm.domain.gh777.UserInfo) MyNode(org.neo4j.ogm.domain.gh873.MyNode) Session(org.neo4j.ogm.session.Session) BeforeClass(org.junit.BeforeClass)

Example 4 with Actor

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

the class RelationshipEntityPartialMappingTest method testCreateAndReloadActorMultipleRolesAndMovies.

@Test
public void testCreateAndReloadActorMultipleRolesAndMovies() {
    Actor keanu = new Actor("Keanu Reeves");
    Movie matrix = new Movie("The Matrix");
    Movie speed = new Movie("Speed");
    keanu.addRole("Neo", matrix);
    keanu.addRole("Jack Traven", speed);
    session.save(keanu);
    Actor keanu2 = session.load(Actor.class, keanu.getId());
    assertThat(keanu2.roles()).hasSize(2);
    keanu2.addRole("John Constantine", new Movie("Constantine"));
    session.save(keanu2);
    Actor keanu3 = session.load(Actor.class, keanu2.getId());
    assertThat(keanu3.roles()).hasSize(3);
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.minimum.Movie) Actor(org.neo4j.ogm.domain.cineasts.minimum.Actor) Test(org.junit.Test)

Example 5 with Actor

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

the class RelationshipEntityPartialMappingTest method testCreateAndReloadActorRoleAndMovie.

@Test
public void testCreateAndReloadActorRoleAndMovie() {
    Actor keanu = new Actor("Keanu Reeves");
    Movie matrix = new Movie("The Matrix");
    keanu.addRole("Neo", matrix);
    session.save(keanu);
    Actor keanu2 = session.load(Actor.class, keanu.getId());
    assertThat(keanu2.roles()).hasSize(1);
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.minimum.Movie) Actor(org.neo4j.ogm.domain.cineasts.minimum.Actor) Test(org.junit.Test)

Aggregations

Actor (org.neo4j.ogm.domain.cineasts.minimum.Actor)8 Movie (org.neo4j.ogm.domain.cineasts.minimum.Movie)8 Test (org.junit.Test)7 Role (org.neo4j.ogm.domain.cineasts.minimum.Role)4 Map (java.util.Map)3 Session (org.neo4j.ogm.session.Session)3 BeforeClass (org.junit.BeforeClass)1 UserInfo (org.neo4j.ogm.domain.gh777.UserInfo)1 MyNode (org.neo4j.ogm.domain.gh873.MyNode)1 SessionFactory (org.neo4j.ogm.session.SessionFactory)1