use of org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator in project neo4j-ogm by neo4j.
the class SingleUseEntityMapperTest method gh813.
@Test
public void gh813() {
SingleUseEntityMapper entityMapper = new SingleUseEntityMapper(sessionFactory.metaData(), new ReflectionEntityInstantiator(sessionFactory.metaData()));
Iterable<Map<String, Object>> results;
results = sessionFactory.openSession().query("RETURN 'containerName' AS name, [i IN RANGE(0,3) | {a:{id: i, name:'a'+i}, b:{id: i, name:'b'+i}, c:{id: i, name:'c'+i}}] AS rows", EMPTY_MAP).queryResults();
assertThat(results).hasSize(1);
Container container = entityMapper.map(Container.class, results.iterator().next());
assertContainer(container, 4);
results = sessionFactory.openSession().query("WITH {a: {id: 0, name: 'a0'}, b: {id:0, name:'b0'}, c: {id:0, name: 'c0'}} AS i RETURN 'containerName' as name, collect(i) as rows", EMPTY_MAP).queryResults();
assertThat(results).hasSize(1);
container = entityMapper.map(Container.class, results.iterator().next());
assertContainer(container, 1);
}
use of org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator in project neo4j-ogm by neo4j.
the class SingleUseEntityMapperTest method shouldMapAggregatedMapProperties.
// GH-873
@Test
public void shouldMapAggregatedMapProperties() {
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, {b1: 'w1', b2: 'w2'} AS attributes 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("b1", "w1");
assertThat(thingResult.getAttributes()).containsEntry("b2", "w2");
}
use of org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator in project neo4j-ogm by neo4j.
the class SingleUseEntityMapperTest method shouldFailOnIncompatibleProperties.
// GH-748
@Test
public void shouldFailOnIncompatibleProperties() {
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) RETURN something, COLLECT(t) as entity", EMPTY_MAP).queryResults();
assertThat(results).hasSize(1);
assertThatIllegalArgumentException().isThrownBy(() -> entityMapper.map(ThingResult2.class, results.iterator().next())).withMessageContaining("Can not set org.neo4j.ogm.domain.gh551.ThingEntity field org.neo4j.ogm.domain.gh551.ThingResult2.entity to java.util.ArrayList");
Condition<String> stringMatches = new Condition<>(s -> s.contains("Cannot map property entity from result set: The result contains more than one entry for the property."), "String matches");
assertThat(loggerRule.getFormattedMessages()).areAtLeastOne(stringMatches);
}
use of org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator in project neo4j-ogm by neo4j.
the class SingleUseEntityMapperTest method assertThatNullOrEmptyObjectsAreMappedCorrectly.
// GH-777
@Test
public void assertThatNullOrEmptyObjectsAreMappedCorrectly() {
SingleUseEntityMapper entityMapper = new SingleUseEntityMapper(sessionFactory.metaData(), new ReflectionEntityInstantiator(sessionFactory.metaData()));
Iterable<Map<String, Object>> results = sessionFactory.openSession().query("OPTIONAL MATCH (ui:UserInfo {email: 'idontexists@here.com'}) RETURN 4711 AS id, 'infoIsNull' AS status, coalesce(ui, null) as info\n" + "UNION\n" + "OPTIONAL MATCH (ui:UserInfo {email: 'idontexists@either.com'}) RETURN 4712 AS id, 'infoIsEmptyStringApocWhen' AS status, coalesce(ui, '') as info\n" + "UNION\n" + "OPTIONAL MATCH (ui:UserInfo {email: 'i@do.com'}) RETURN 4713 AS id, 'existingMatch' AS status, coalesce(ui, '') as info\n", EMPTY_MAP).queryResults();
assertThat(results).hasSize(3);
UserSearchDto userSearchDto;
Iterator<Map<String, Object>> iterator = results.iterator();
userSearchDto = entityMapper.map(UserSearchDto.class, iterator.next());
assertThat(userSearchDto.getId()).isEqualTo(4711L);
assertThat(userSearchDto.getStatus()).isEqualTo("infoIsNull");
assertThat(userSearchDto.getInfo()).isNull();
userSearchDto = entityMapper.map(UserSearchDto.class, iterator.next());
assertThat(userSearchDto.getId()).isEqualTo(4712L);
assertThat(userSearchDto.getStatus()).isEqualTo("infoIsEmptyStringApocWhen");
assertThat(userSearchDto.getInfo()).isNull();
userSearchDto = entityMapper.map(UserSearchDto.class, iterator.next());
assertThat(userSearchDto.getId()).isEqualTo(4713L);
assertThat(userSearchDto.getStatus()).isEqualTo("existingMatch");
assertThat(userSearchDto.getInfo()).isNotNull();
assertThat(userSearchDto.getInfo().getFirstName()).isEqualTo("Foo");
assertThat(userSearchDto.getInfo().getLastName()).isEqualTo("Bar");
}
use of org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator in project neo4j-ogm by neo4j.
the class SingleUseEntityMapperTest method shouldWorkWithCustomConvertersOnListProperty.
// GH-750
@Test
public void shouldWorkWithCustomConvertersOnListProperty() {
SingleUseEntityMapper entityMapper = new SingleUseEntityMapper(sessionFactory.metaData(), new ReflectionEntityInstantiator(sessionFactory.metaData()));
Iterable<Map<String, Object>> results = sessionFactory.openSession().query("RETURN ['foo', 'bar'] AS foobars", EMPTY_MAP).queryResults();
assertThat(results).hasSize(1);
ThingResult3 thingResult = entityMapper.map(ThingResult3.class, results.iterator().next());
assertThat(thingResult.getFoobars()).extracting(ThingResult3.FooBar::getValue).containsExactlyInAnyOrder("foo", "bar");
}
Aggregations