Search in sources :

Example 6 with Movie

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

the class MinimalRelationshipEntityMappingTest method verifyChangeOfRelationshipEnd.

// GH-607
@Test
public void verifyChangeOfRelationshipEnd() {
    session = sessionFactory.openSession();
    Actor actor = new Actor("A1");
    Movie movie = new Movie("M1");
    Role role = new Role("R1", actor, movie);
    session.save(role);
    session = sessionFactory.openSession();
    Iterable<Map<String, Object>> results = session.query("MATCH (m:Movie) <- [:ACTS_IN] - (:Actor {name: 'A1'}) RETURN COUNT(m) as cnt", Collections.emptyMap()).queryResults();
    assertThat(results).hasSize(1);
    assertThat(results).first().satisfies(m -> assertThat(m).containsEntry("cnt", 1L));
    // New session / TX
    session = sessionFactory.openSession();
    movie = new Movie("M2");
    role = session.load(Role.class, role.getId());
    role.setMovie(new Movie("M2"));
    session.save(role);
    session = sessionFactory.openSession();
    results = session.query("MATCH (m:Movie) <- [:ACTS_IN] - (:Actor {name: 'A1'}) RETURN COUNT(m) as cnt", Collections.emptyMap()).queryResults();
    assertThat(results).hasSize(1);
    assertThat(results).first().satisfies(m -> assertThat(m).containsEntry("cnt", 1L));
}
Also used : Role(org.neo4j.ogm.domain.cineasts.minimum.Role) Movie(org.neo4j.ogm.domain.cineasts.minimum.Movie) Actor(org.neo4j.ogm.domain.cineasts.minimum.Actor) Map(java.util.Map) Test(org.junit.Test)

Example 7 with Movie

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

the class RelationshipEntityPartialMappingTest method shouldNotDropUnmappedRelationshipModels.

// GH-727
@Test
public void shouldNotDropUnmappedRelationshipModels() {
    Session session = sessionFactory.openSession();
    Actor actor = new Actor("A1");
    Movie movie = new Movie("M1");
    Role role = new Role("R1", actor, movie);
    session.save(role);
    session = sessionFactory.openSession();
    Iterable<Map<String, Object>> results = session.query("MATCH (m) - [r] - (a) WHERE id(a) = $id RETURN r", Collections.singletonMap("id", actor.getId())).queryResults();
    assertThat(results).hasSize(1);
    Map<String, Object> row = results.iterator().next();
    assertThat(row).containsKeys("r");
    assertThat(row.get("r")).isNotNull().isInstanceOf(RelationshipModel.class);
}
Also used : Role(org.neo4j.ogm.domain.cineasts.minimum.Role) Movie(org.neo4j.ogm.domain.cineasts.minimum.Movie) Actor(org.neo4j.ogm.domain.cineasts.minimum.Actor) Map(java.util.Map) Session(org.neo4j.ogm.session.Session) Test(org.junit.Test)

Example 8 with Movie

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

the class RelationshipEntityPartialMappingTest method shouldMapSingleRelationshipModel.

// GH-727
@Test
public void shouldMapSingleRelationshipModel() {
    Session session = sessionFactory.openSession();
    Actor actor = new Actor("A1");
    Movie movie = new Movie("M1");
    Role role = new Role("R1", actor, movie);
    session.save(role);
    session = sessionFactory.openSession();
    Iterable<Map<String, Object>> results = session.query("MATCH (m) - [r] - (a) WHERE id(a) = $id RETURN m, r, a", Collections.singletonMap("id", actor.getId())).queryResults();
    assertThat(results).hasSize(1);
    Map<String, Object> row = results.iterator().next();
    assertThat(row).containsKeys("r");
    assertThat(row.get("r")).isNotNull().isInstanceOf(Role.class);
}
Also used : Role(org.neo4j.ogm.domain.cineasts.minimum.Role) Movie(org.neo4j.ogm.domain.cineasts.minimum.Movie) Actor(org.neo4j.ogm.domain.cineasts.minimum.Actor) Map(java.util.Map) Session(org.neo4j.ogm.session.Session) 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