use of org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator in project neo4j-ogm by neo4j.
the class SingleUseEntityMapperTest method shouldDealWithStaticInnerClasses.
// GH-391
@Test
public void shouldDealWithStaticInnerClasses() {
SingleUseEntityMapper entityMapper = new SingleUseEntityMapper(sessionFactory.metaData(), new ReflectionEntityInstantiator(sessionFactory.metaData()));
Iterable<Map<String, Object>> results = sessionFactory.openSession().query("MATCH (t:ThingEntity) RETURN 'a name' as something LIMIT 1", EMPTY_MAP).queryResults();
assertThat(results).hasSize(1);
SomeContainer.StaticInnerThingResult thingResult = entityMapper.map(SomeContainer.StaticInnerThingResult.class, results.iterator().next());
assertThat(thingResult.getSomething()).isEqualTo("a name");
}
use of org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator in project neo4j-ogm by neo4j.
the class SingleUseEntityMapperTest method shouldMapFromMap.
@Test
public void shouldMapFromMap() {
MetaData metaData = new MetaData("org.neo4j.ogm.context");
SingleUseEntityMapper entityMapper = new SingleUseEntityMapper(metaData, new ReflectionEntityInstantiator(metaData));
Collection<Object> toReturn = new ArrayList<>();
Iterable<Map<String, Object>> results = getQueryResults();
for (Map<String, Object> result : results) {
toReturn.add(entityMapper.map(UserResult.class, result));
}
assertThat(toReturn).hasSize(1);
assertThat(toReturn).first().isInstanceOf(UserResult.class);
UserResult userResult = (UserResult) toReturn.iterator().next();
assertThat(userResult.getProfile()).containsAllEntriesOf((Map<? extends String, ?>) results.iterator().next().get("profile"));
}
use of org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator in project neo4j-ogm by neo4j.
the class SingleUseEntityMapperTest method shouldWorkWithCustomConverters.
// GH-750
@Test
public void shouldWorkWithCustomConverters() {
SingleUseEntityMapper entityMapper = new SingleUseEntityMapper(sessionFactory.metaData(), new ReflectionEntityInstantiator(sessionFactory.metaData()));
Iterable<Map<String, Object>> results = sessionFactory.openSession().query("RETURN 'foo' AS foobar", EMPTY_MAP).queryResults();
assertThat(results).hasSize(1);
ThingResult3 thingResult = entityMapper.map(ThingResult3.class, results.iterator().next());
assertThat(thingResult.getFoobar()).isNotNull();
assertThat(thingResult.getFoobar().getValue()).isEqualTo("foo");
}
use of org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator in project neo4j-ogm by neo4j.
the class SingleUseEntityMapperTest method singleUseEntityMapperShouldWorkWithNestedObjects.
// GH-551
@Test
public void singleUseEntityMapperShouldWorkWithNestedObjects() {
SingleUseEntityMapper entityMapper = new SingleUseEntityMapper(sessionFactory.metaData(), new ReflectionEntityInstantiator(sessionFactory.metaData()));
Iterable<Map<String, Object>> results = sessionFactory.openSession().query("MATCH (t:ThingEntity) RETURN 'a name' as something, collect({name: t.name}) as things", EMPTY_MAP).queryResults();
assertThat(results).hasSize(1);
ThingResult thingResult = entityMapper.map(ThingResult.class, results.iterator().next());
assertThat(thingResult.getSomething()).isEqualTo("a name");
assertThat(thingResult.getThings()).hasSize(10).extracting(AnotherThing::getName).allSatisfy(s -> s.startsWith("Thing"));
}
use of org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator in project neo4j-ogm by neo4j.
the class SingleUseEntityMapperTest method shouldUseIdFields.
/**
* ID fields are treated differently in different versions of OGM. This tests assures that they work correctly.
*/
// GH-551
@Test
public void shouldUseIdFields() {
SingleUseEntityMapper entityMapper = new SingleUseEntityMapper(sessionFactory.metaData(), new ReflectionEntityInstantiator(sessionFactory.metaData()));
Iterable<Map<String, Object>> results = sessionFactory.openSession().query("MATCH (t:ThingEntity) RETURN 4711 as id, 'a name' as name LIMIT 1", EMPTY_MAP).queryResults();
assertThat(results).hasSize(1);
ThingWIthId thingResult = entityMapper.map(ThingWIthId.class, results.iterator().next());
assertThat(thingResult.getName()).isEqualTo("a name");
assertThat(thingResult.getId()).isEqualTo(4711);
}
Aggregations