use of org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator in project neo4j-ogm by neo4j.
the class SingleUseEntityMapperTest method singleUseEntityMapperShouldWorkWithNullableNestedNodeEntities.
// GH-748
@Test
public void singleUseEntityMapperShouldWorkWithNullableNestedNodeEntities() {
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 {na:false}) RETURN something, 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()).isNull();
}
use of org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator in project neo4j-ogm by neo4j.
the class SingleUseEntityMapperTest method shouldLookupCorrectRootClass.
// GH-552
@Test
public void shouldLookupCorrectRootClass() {
MetaData metaData = new MetaData("org.neo4j.ogm.domain.gh552");
String propertyKey = "notAName";
Map<String, Object> properties = Collections.singletonMap(propertyKey, "NOT A NAME!!!");
SingleUseEntityMapper entityMapper = new SingleUseEntityMapper(metaData, new ReflectionEntityInstantiator(metaData));
Thing thing = entityMapper.map(Thing.class, properties);
assertThat(thing.getNotAName()).isEqualTo(properties.get(propertyKey));
}
use of org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator in project neo4j-ogm by neo4j.
the class SingleUseEntityMapperTest method shouldMapEnumeratedMapProperties.
// GH-873
@Test
public void shouldMapEnumeratedMapProperties() {
SingleUseEntityMapper entityMapper = new SingleUseEntityMapper(sessionFactory.metaData(), new ReflectionEntityInstantiator(sessionFactory.metaData()));
Iterable<Map<String, Object>> results = sessionFactory.openSession().query("MATCH (t:MyNode) RETURN t.id AS id, t.type AS type, t.`attributes.a1` AS `attributes.a1`, t.`attributes.a2` AS `attributes.a2` LIMIT 1", EMPTY_MAP).queryResults();
assertThat(results).hasSize(1);
MyNode thingResult = entityMapper.map(MyNode.class, results.iterator().next());
assertThat(thingResult.getId()).isEqualTo("the-id");
assertThat(thingResult.getType()).isEqualTo("the-type");
assertThat(thingResult.getAttributes()).containsEntry("a1", "v1");
assertThat(thingResult.getAttributes()).containsEntry("a2", "v2");
}
use of org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator 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();
}
use of org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator in project neo4j-ogm by neo4j.
the class SingleUseEntityMapperTest method singleUseEntityMapperShouldWorkWithNonNullNestedNodeEntities.
// GH-748
@Test
public void singleUseEntityMapperShouldWorkWithNonNullNestedNodeEntities() {
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, 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");
}
Aggregations