Search in sources :

Example 6 with ReflectionEntityInstantiator

use of org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator in project neo4j-ogm by neo4j.

the class SingleUseEntityMapperTest method shouldDealWithStaticInnerClasses.

// GH-391
@Test
public void shouldDealWithStaticInnerClasses() {
    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 LIMIT 1", EMPTY_MAP).queryResults();
    assertThat(results).hasSize(1);
    SomeContainer.StaticInnerThingResult thingResult = entityMapper.map(SomeContainer.StaticInnerThingResult.class, results.iterator().next());
    assertThat(thingResult.getSomething()).isEqualTo("a name");
}
Also used : SomeContainer(org.neo4j.ogm.domain.gh391.SomeContainer) HashMap(java.util.HashMap) Map(java.util.Map) ReflectionEntityInstantiator(org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator) Test(org.junit.Test)

Example 7 with ReflectionEntityInstantiator

use of org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator in project neo4j-ogm by neo4j.

the class SingleUseEntityMapperTest method shouldMapFromMap.

@Test
public void shouldMapFromMap() {
    MetaData metaData = new MetaData("org.neo4j.ogm.context");
    SingleUseEntityMapper entityMapper = new SingleUseEntityMapper(metaData, new ReflectionEntityInstantiator(metaData));
    Collection<Object> toReturn = new ArrayList<>();
    Iterable<Map<String, Object>> results = getQueryResults();
    for (Map<String, Object> result : results) {
        toReturn.add(entityMapper.map(UserResult.class, result));
    }
    assertThat(toReturn).hasSize(1);
    assertThat(toReturn).first().isInstanceOf(UserResult.class);
    UserResult userResult = (UserResult) toReturn.iterator().next();
    assertThat(userResult.getProfile()).containsAllEntriesOf((Map<? extends String, ?>) results.iterator().next().get("profile"));
}
Also used : MetaData(org.neo4j.ogm.metadata.MetaData) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) ReflectionEntityInstantiator(org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator) Test(org.junit.Test)

Example 8 with ReflectionEntityInstantiator

use of org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator in project neo4j-ogm by neo4j.

the class SingleUseEntityMapperTest method shouldWorkWithCustomConverters.

// GH-750
@Test
public void shouldWorkWithCustomConverters() {
    SingleUseEntityMapper entityMapper = new SingleUseEntityMapper(sessionFactory.metaData(), new ReflectionEntityInstantiator(sessionFactory.metaData()));
    Iterable<Map<String, Object>> results = sessionFactory.openSession().query("RETURN 'foo' AS foobar", EMPTY_MAP).queryResults();
    assertThat(results).hasSize(1);
    ThingResult3 thingResult = entityMapper.map(ThingResult3.class, results.iterator().next());
    assertThat(thingResult.getFoobar()).isNotNull();
    assertThat(thingResult.getFoobar().getValue()).isEqualTo("foo");
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) ReflectionEntityInstantiator(org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator) ThingResult3(org.neo4j.ogm.domain.gh750.ThingResult3) Test(org.junit.Test)

Example 9 with ReflectionEntityInstantiator

use of org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator 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 10 with ReflectionEntityInstantiator

use of org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator 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)

Aggregations

Test (org.junit.Test)18 ReflectionEntityInstantiator (org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator)18 HashMap (java.util.HashMap)17 Map (java.util.Map)17 ArrayList (java.util.ArrayList)3 ThingResult2 (org.neo4j.ogm.domain.gh551.ThingResult2)3 List (java.util.List)2 SomeContainer (org.neo4j.ogm.domain.gh391.SomeContainer)2 GenericQueryResultWrapper (org.neo4j.ogm.domain.gh551.GenericQueryResultWrapper)2 ThingResult3 (org.neo4j.ogm.domain.gh750.ThingResult3)2 MyNode (org.neo4j.ogm.domain.gh873.MyNode)2 MetaData (org.neo4j.ogm.metadata.MetaData)2 Condition (org.assertj.core.api.Condition)1 SomeQueryResult (org.neo4j.ogm.domain.cineasts.minimum.SomeQueryResult)1 AnotherThing (org.neo4j.ogm.domain.gh551.AnotherThing)1 ThingResult (org.neo4j.ogm.domain.gh551.ThingResult)1 ThingWIthId (org.neo4j.ogm.domain.gh551.ThingWIthId)1 Thing (org.neo4j.ogm.domain.gh552.Thing)1 UserSearchDto (org.neo4j.ogm.domain.gh777.UserSearchDto)1 Container (org.neo4j.ogm.domain.gh813.Container)1