Search in sources :

Example 11 with ReflectionEntityInstantiator

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

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

the class SingleUseEntityMapperTest method shouldLookupCorrectRootClass.

// GH-552
@Test
public void shouldLookupCorrectRootClass() {
    MetaData metaData = new MetaData("org.neo4j.ogm.domain.gh552");
    String propertyKey = "notAName";
    Map<String, Object> properties = Collections.singletonMap(propertyKey, "NOT A NAME!!!");
    SingleUseEntityMapper entityMapper = new SingleUseEntityMapper(metaData, new ReflectionEntityInstantiator(metaData));
    Thing thing = entityMapper.map(Thing.class, properties);
    assertThat(thing.getNotAName()).isEqualTo(properties.get(propertyKey));
}
Also used : MetaData(org.neo4j.ogm.metadata.MetaData) ReflectionEntityInstantiator(org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator) AnotherThing(org.neo4j.ogm.domain.gh551.AnotherThing) Thing(org.neo4j.ogm.domain.gh552.Thing) Test(org.junit.Test)

Example 13 with ReflectionEntityInstantiator

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

the class SingleUseEntityMapperTest method shouldMapEnumeratedMapProperties.

// GH-873
@Test
public void shouldMapEnumeratedMapProperties() {
    SingleUseEntityMapper entityMapper = new SingleUseEntityMapper(sessionFactory.metaData(), new ReflectionEntityInstantiator(sessionFactory.metaData()));
    Iterable<Map<String, Object>> results = sessionFactory.openSession().query("MATCH (t:MyNode) RETURN t.id AS id, t.type AS type, t.`attributes.a1` AS `attributes.a1`, t.`attributes.a2` AS `attributes.a2` LIMIT 1", EMPTY_MAP).queryResults();
    assertThat(results).hasSize(1);
    MyNode thingResult = entityMapper.map(MyNode.class, results.iterator().next());
    assertThat(thingResult.getId()).isEqualTo("the-id");
    assertThat(thingResult.getType()).isEqualTo("the-type");
    assertThat(thingResult.getAttributes()).containsEntry("a1", "v1");
    assertThat(thingResult.getAttributes()).containsEntry("a2", "v2");
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) MyNode(org.neo4j.ogm.domain.gh873.MyNode) ReflectionEntityInstantiator(org.neo4j.ogm.metadata.reflect.ReflectionEntityInstantiator) Test(org.junit.Test)

Example 14 with ReflectionEntityInstantiator

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

the class SingleUseEntityMapperTest method genericTargetTypesWithCollectionsOfUnkownThings.

@Test
public void genericTargetTypesWithCollectionsOfUnkownThings() {
    SingleUseEntityMapper entityMapper = new SingleUseEntityMapper(sessionFactory.metaData(), new ReflectionEntityInstantiator(sessionFactory.metaData()));
    Iterable<Map<String, Object>> results;
    GenericQueryResultWrapper<List<Long>> genericQueryResultWrapper;
    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()).containsExactly(0L, 1L);
    results = sessionFactory.openSession().query("unwind  range (0,0) 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()).containsExactly(0L);
    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 15 with ReflectionEntityInstantiator

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

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