Search in sources :

Example 1 with ThingResult

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

Example 2 with ThingResult

use of org.neo4j.ogm.domain.gh551.ThingResult 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);
}
Also used : ThingWIthId(org.neo4j.ogm.domain.gh551.ThingWIthId) HashMap(java.util.HashMap) Map(java.util.Map) ReflectionEntityInstantiator(org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator) Test(org.junit.Test)

Example 3 with ThingResult

use of org.neo4j.ogm.domain.gh551.ThingResult 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();
}
Also used : ThingResult2(org.neo4j.ogm.domain.gh551.ThingResult2) HashMap(java.util.HashMap) Map(java.util.Map) ReflectionEntityInstantiator(org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator) Test(org.junit.Test)

Example 4 with ThingResult

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

Example 5 with ThingResult

use of org.neo4j.ogm.domain.gh551.ThingResult in project neo4j-ogm by neo4j.

the class SingleUseEntityMapperTest method shouldBeLenientWithSingleValuedCollectionsForSkalarPropertiesMode.

// GH-748
@Test
public void shouldBeLenientWithSingleValuedCollectionsForSkalarPropertiesMode() {
    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, COLLECT(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");
}
Also used : ThingResult2(org.neo4j.ogm.domain.gh551.ThingResult2) HashMap(java.util.HashMap) Map(java.util.Map) ReflectionEntityInstantiator(org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)5 Map (java.util.Map)5 Test (org.junit.Test)5 ReflectionEntityInstantiator (org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator)5 ThingResult2 (org.neo4j.ogm.domain.gh551.ThingResult2)3 ThingResult (org.neo4j.ogm.domain.gh551.ThingResult)1 ThingWIthId (org.neo4j.ogm.domain.gh551.ThingWIthId)1