Search in sources :

Example 1 with Role

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

the class CineastsRelationshipEntityTest method updateRoleToSameValueResultsInTwoRelationshipBetweenSameObjects.

@Test
public void updateRoleToSameValueResultsInTwoRelationshipBetweenSameObjects() throws Exception {
    Movie movie = new Movie("The big John Travolta Party", 2016);
    Actor actor = new Actor("John Travolta");
    Role role1 = actor.playedIn(movie, "He danced mostly");
    Role role2 = actor.playedIn(movie, "He was dancing mostly");
    assertThat(actor.getRoles()).hasSize(2);
    session.save(actor);
    session.clear();
    Actor loaded = session.load(Actor.class, actor.getUuid());
    assertThat(loaded.getRoles()).hasSize(2);
    // set to identical role - this should behave consistently to previous test case
    role2.setRole("He danced mostly");
    session.save(actor);
    session.clear();
    loaded = session.load(Actor.class, actor.getUuid());
    assertThat(loaded.getRoles()).hasSize(2);
}
Also used : Role(org.neo4j.ogm.domain.cineasts.annotated.Role) Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) Actor(org.neo4j.ogm.domain.cineasts.annotated.Actor) Test(org.junit.Test)

Example 2 with Role

use of org.neo4j.ogm.domain.cineasts.annotated.Role 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)

Aggregations

Test (org.junit.Test)2 Actor (org.neo4j.ogm.domain.cineasts.annotated.Actor)2 Movie (org.neo4j.ogm.domain.cineasts.annotated.Movie)2 Role (org.neo4j.ogm.domain.cineasts.annotated.Role)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Result (org.neo4j.ogm.model.Result)1