Search in sources :

Example 16 with ReflectionEntityInstantiator

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

Example 17 with ReflectionEntityInstantiator

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

the class SingleUseEntityMapperTest method genericTargetTypesWithCollectionsOfKownThings.

@Test
public void genericTargetTypesWithCollectionsOfKownThings() {
    SingleUseEntityMapper entityMapper = new SingleUseEntityMapper(sessionFactory.metaData(), new ReflectionEntityInstantiator(sessionFactory.metaData()));
    Iterable<Map<String, Object>> results;
    GenericQueryResultWrapper<List<ThingEntity>> genericQueryResultWrapper;
    results = sessionFactory.openSession().query("match (r:ThingEntity) return collect (r) as result", EMPTY_MAP).queryResults();
    assertThat(results).hasSize(1);
    genericQueryResultWrapper = entityMapper.map(GenericQueryResultWrapper.class, results.iterator().next());
    assertThat(genericQueryResultWrapper.getResult()).hasSize(10).extracting(ThingEntity::getName).allSatisfy(s -> s.startsWith("Thing"));
    results = sessionFactory.openSession().query("match (r:ThingEntity {name: 'Thing 1'}) return collect (r) as result", EMPTY_MAP).queryResults();
    assertThat(results).hasSize(1);
    genericQueryResultWrapper = entityMapper.map(GenericQueryResultWrapper.class, results.iterator().next());
    assertThat(genericQueryResultWrapper.getResult()).hasSize(1).extracting(ThingEntity::getName).allSatisfy(s -> s.startsWith("Thing"));
    results = sessionFactory.openSession().query("unwind  range (0,-1) as x return collect(x) as result", EMPTY_MAP).queryResults();
    assertThat(results).hasSize(1);
    genericQueryResultWrapper = entityMapper.map(GenericQueryResultWrapper.class, results.iterator().next());
    assertThat(genericQueryResultWrapper.getResult()).isEmpty();
}
Also used : GenericQueryResultWrapper(org.neo4j.ogm.domain.gh551.GenericQueryResultWrapper) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ReflectionEntityInstantiator(org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator) Test(org.junit.Test)

Example 18 with ReflectionEntityInstantiator

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

the class SingleUseEntityMapperTest method queryResultShouldHandleNodeAndRelationshipEntities.

// GH-718
@Test
public void queryResultShouldHandleNodeAndRelationshipEntities() {
    SingleUseEntityMapper entityMapper = new SingleUseEntityMapper(sessionFactory.metaData(), new ReflectionEntityInstantiator(sessionFactory.metaData()));
    // so that it works the same way as the org.neo4j.ogm.result.adapter.GraphModelAdapter.adapt
    for (String query : new String[] { "MATCH (a:Actor {name: 'A1'})-[r:ACTS_IN]->(m:Movie) RETURN a AS actor,COLLECT(r) AS roles, COLLECT(m) as movies", "MATCH (a:Actor {name: 'A1'})-[r:ACTS_IN*]->(m:Movie) RETURN a AS actor,COLLECT(r) AS roles, COLLECT(m) as movies" }) {
        Iterable<Map<String, Object>> results = sessionFactory.openSession().query(query, EMPTY_MAP).queryResults();
        assertThat(results).hasSize(1);
        SomeQueryResult thingResult = entityMapper.map(SomeQueryResult.class, results.iterator().next());
        assertThat(thingResult.getActor().getName()).isEqualTo("A1");
        assertThat(thingResult.getRoles()).hasSize(2).extracting(Role::getPlayed).containsExactlyInAnyOrder("R1", "R2");
    }
}
Also used : SomeQueryResult(org.neo4j.ogm.domain.cineasts.minimum.SomeQueryResult) 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