use of org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator in project neo4j-ogm by neo4j.
the class SingleUseEntityMapperTest method shouldBeLenientWithSingleValuedCollectionsForSkalarPropertiesMode.
// GH-748
@Test
public void shouldBeLenientWithSingleValuedCollectionsForSkalarPropertiesMode() {
SingleUseEntityMapper entityMapper = new SingleUseEntityMapper(sessionFactory.metaData(), new ReflectionEntityInstantiator(sessionFactory.metaData()));
Iterable<Map<String, Object>> results = sessionFactory.openSession().query("WITH 'a name' AS something OPTIONAL MATCH (t:ThingEntity {name: 'Thing 7'}) RETURN something, COLLECT(t) as entity", EMPTY_MAP).queryResults();
assertThat(results).hasSize(1);
ThingResult2 thingResult = entityMapper.map(ThingResult2.class, results.iterator().next());
assertThat(thingResult.getSomething()).isEqualTo("a name");
assertThat(thingResult.getEntity()).isNotNull().extracting(ThingEntity::getName).isEqualTo("Thing 7");
}
use of org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator 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();
}
use of org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator 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");
}
}
Aggregations