use of org.neo4j.ogm.domain.gh777.UserSearchDto 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");
}
Aggregations