Search in sources :

Example 1 with UserSearchDto

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");
}
Also used : UserSearchDto(org.neo4j.ogm.domain.gh777.UserSearchDto) HashMap(java.util.HashMap) Map(java.util.Map) ReflectionEntityInstantiator(org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1 UserSearchDto (org.neo4j.ogm.domain.gh777.UserSearchDto)1 ReflectionEntityInstantiator (org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator)1