Search in sources :

Example 1 with SomeQueryResult

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

the class SingleUseEntityMapperTest method queryResultShouldHandleNodeAndRelationshipEntities.

// GH-718
@Test
public void queryResultShouldHandleNodeAndRelationshipEntities() {
    SingleUseEntityMapper entityMapper = new SingleUseEntityMapper(sessionFactory.metaData(), new ReflectionEntityInstantiator(sessionFactory.metaData()));
    // so that it works the same way as the org.neo4j.ogm.result.adapter.GraphModelAdapter.adapt
    for (String query : new String[] { "MATCH (a:Actor {name: 'A1'})-[r:ACTS_IN]->(m:Movie) RETURN a AS actor,COLLECT(r) AS roles, COLLECT(m) as movies", "MATCH (a:Actor {name: 'A1'})-[r:ACTS_IN*]->(m:Movie) RETURN a AS actor,COLLECT(r) AS roles, COLLECT(m) as movies" }) {
        Iterable<Map<String, Object>> results = sessionFactory.openSession().query(query, EMPTY_MAP).queryResults();
        assertThat(results).hasSize(1);
        SomeQueryResult thingResult = entityMapper.map(SomeQueryResult.class, results.iterator().next());
        assertThat(thingResult.getActor().getName()).isEqualTo("A1");
        assertThat(thingResult.getRoles()).hasSize(2).extracting(Role::getPlayed).containsExactlyInAnyOrder("R1", "R2");
    }
}
Also used : SomeQueryResult(org.neo4j.ogm.domain.cineasts.minimum.SomeQueryResult) HashMap(java.util.HashMap) Map(java.util.Map) ReflectionEntityInstantiator(org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1 SomeQueryResult (org.neo4j.ogm.domain.cineasts.minimum.SomeQueryResult)1 ReflectionEntityInstantiator (org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator)1