Search in sources :

Example 1 with GenericQueryResultWrapper

use of org.neo4j.ogm.domain.gh551.GenericQueryResultWrapper in project neo4j-ogm by neo4j.

the class SingleUseEntityMapperTest method genericTargetTypesWithCollectionsOfUnkownThings.

@Test
public void genericTargetTypesWithCollectionsOfUnkownThings() {
    SingleUseEntityMapper entityMapper = new SingleUseEntityMapper(sessionFactory.metaData(), new ReflectionEntityInstantiator(sessionFactory.metaData()));
    Iterable<Map<String, Object>> results;
    GenericQueryResultWrapper<List<Long>> genericQueryResultWrapper;
    results = sessionFactory.openSession().query("unwind  range (0,1) as x return collect(x) as result", EMPTY_MAP).queryResults();
    assertThat(results).hasSize(1);
    genericQueryResultWrapper = entityMapper.map(GenericQueryResultWrapper.class, results.iterator().next());
    assertThat(genericQueryResultWrapper.getResult()).containsExactly(0L, 1L);
    results = sessionFactory.openSession().query("unwind  range (0,0) as x return collect(x) as result", EMPTY_MAP).queryResults();
    assertThat(results).hasSize(1);
    genericQueryResultWrapper = entityMapper.map(GenericQueryResultWrapper.class, results.iterator().next());
    assertThat(genericQueryResultWrapper.getResult()).containsExactly(0L);
    results = sessionFactory.openSession().query("unwind  range (0,-1) as x return collect(x) as result", EMPTY_MAP).queryResults();
    assertThat(results).hasSize(1);
    genericQueryResultWrapper = entityMapper.map(GenericQueryResultWrapper.class, results.iterator().next());
    assertThat(genericQueryResultWrapper.getResult()).isEmpty();
}
Also used : GenericQueryResultWrapper(org.neo4j.ogm.domain.gh551.GenericQueryResultWrapper) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ReflectionEntityInstantiator(org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator) Test(org.junit.Test)

Example 2 with GenericQueryResultWrapper

use of org.neo4j.ogm.domain.gh551.GenericQueryResultWrapper in project neo4j-ogm by neo4j.

the class SingleUseEntityMapperTest method genericTargetTypesWithCollectionsOfKownThings.

@Test
public void genericTargetTypesWithCollectionsOfKownThings() {
    SingleUseEntityMapper entityMapper = new SingleUseEntityMapper(sessionFactory.metaData(), new ReflectionEntityInstantiator(sessionFactory.metaData()));
    Iterable<Map<String, Object>> results;
    GenericQueryResultWrapper<List<ThingEntity>> genericQueryResultWrapper;
    results = sessionFactory.openSession().query("match (r:ThingEntity) return collect (r) as result", EMPTY_MAP).queryResults();
    assertThat(results).hasSize(1);
    genericQueryResultWrapper = entityMapper.map(GenericQueryResultWrapper.class, results.iterator().next());
    assertThat(genericQueryResultWrapper.getResult()).hasSize(10).extracting(ThingEntity::getName).allSatisfy(s -> s.startsWith("Thing"));
    results = sessionFactory.openSession().query("match (r:ThingEntity {name: 'Thing 1'}) return collect (r) as result", EMPTY_MAP).queryResults();
    assertThat(results).hasSize(1);
    genericQueryResultWrapper = entityMapper.map(GenericQueryResultWrapper.class, results.iterator().next());
    assertThat(genericQueryResultWrapper.getResult()).hasSize(1).extracting(ThingEntity::getName).allSatisfy(s -> s.startsWith("Thing"));
    results = sessionFactory.openSession().query("unwind  range (0,-1) as x return collect(x) as result", EMPTY_MAP).queryResults();
    assertThat(results).hasSize(1);
    genericQueryResultWrapper = entityMapper.map(GenericQueryResultWrapper.class, results.iterator().next());
    assertThat(genericQueryResultWrapper.getResult()).isEmpty();
}
Also used : GenericQueryResultWrapper(org.neo4j.ogm.domain.gh551.GenericQueryResultWrapper) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ReflectionEntityInstantiator(org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Test (org.junit.Test)2 GenericQueryResultWrapper (org.neo4j.ogm.domain.gh551.GenericQueryResultWrapper)2 ReflectionEntityInstantiator (org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator)2