Search in sources :

Example 36 with FieldInfo

use of org.neo4j.ogm.metadata.FieldInfo in project neo4j-ogm by neo4j.

the class EntityAccessManagerTest method shouldPreferAnnotatedFieldWithMatchingRelationshipTypeWhenGettingIterableWriter.

/**
 * @see DATAGRAPH-637
 */
@Test
public void shouldPreferAnnotatedFieldWithMatchingRelationshipTypeWhenGettingIterableWriter() {
    // 2nd, try to find a field annotated with with relationship type
    ClassInfo classInfo = this.domainInfo.getClass(DummyDomainObject.class.getName());
    List<Satellite> natural = new ArrayList<>();
    natural.add(new Satellite());
    FieldInfo objectAccess = EntityAccessManager.getIterableField(classInfo, Satellite.class, "NATURAL", Relationship.Direction.OUTGOING);
    assertThat(objectAccess).as("The resultant object accessor shouldn't be null").isNotNull();
    DummyDomainObject domainObject = new DummyDomainObject();
    objectAccess.write(domainObject, natural);
    assertThat(domainObject.naturalSatellites).isEqualTo(natural);
}
Also used : ArrayList(java.util.ArrayList) Satellite(org.neo4j.ogm.domain.satellites.Satellite) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

Example 37 with FieldInfo

use of org.neo4j.ogm.metadata.FieldInfo in project neo4j-ogm by neo4j.

the class EntityAccessManagerTest method shouldRetrieveAppropriateObjectAccessToEndNodeAttributeOnRelationshipEntity.

@Test
public void shouldRetrieveAppropriateObjectAccessToEndNodeAttributeOnRelationshipEntity() {
    ClassInfo relationshipEntityClassInfo = domainInfo.getClass(ForumTopicLink.class.getName());
    FieldInfo endNodeReader = relationshipEntityClassInfo.getEndNodeReader();
    assertThat(endNodeReader).as("The resultant end node reader shouldn't be null").isNotNull();
    ForumTopicLink forumTopicLink = new ForumTopicLink();
    Topic topic = new Topic();
    forumTopicLink.setTopic(topic);
    assertThat(endNodeReader.read(forumTopicLink)).as("The value wasn't read correctly").isSameAs(topic);
}
Also used : ForumTopicLink(org.neo4j.ogm.domain.forum.ForumTopicLink) Topic(org.neo4j.ogm.domain.forum.Topic) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

Example 38 with FieldInfo

use of org.neo4j.ogm.metadata.FieldInfo in project neo4j-ogm by neo4j.

the class EntityAccessManagerTest method shouldAccessViaFieldCorrespondingToPropertyIfNoAnnotationsOrAccessorMethodsArePresent.

@Test
public void shouldAccessViaFieldCorrespondingToPropertyIfNoAnnotationsOrAccessorMethodsArePresent() {
    ClassInfo classInfo = this.domainInfo.getClass(DummyDomainObject.class.getName());
    DummyDomainObject domainObject = new DummyDomainObject();
    domainObject.propertyWithoutAccessorMethods = 9;
    // test writing via field
    FieldInfo writer = classInfo.getFieldInfo("propertyWithoutAccessorMethods");
    assertThat(writer).as("The resultant writer shouldn't be null").isNotNull();
    writer.write(domainObject, 27);
    assertThat(domainObject.propertyWithoutAccessorMethods).isEqualTo(27);
    // test reading via field
    FieldInfo reader = classInfo.getFieldInfo("propertyWithoutAccessorMethods");
    assertThat(reader).as("The resultant reader shouldn't be null").isNotNull();
    assertThat(reader.readProperty(domainObject)).isEqualTo(domainObject.propertyWithoutAccessorMethods);
}
Also used : FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

Example 39 with FieldInfo

use of org.neo4j.ogm.metadata.FieldInfo in project neo4j-ogm by neo4j.

the class EntityAccessManagerTest method shouldPreferAnnotatedFieldToPlainMethodWhenFindingPropertyToSet.

@Test
public void shouldPreferAnnotatedFieldToPlainMethodWhenFindingPropertyToSet() {
    ClassInfo classInfo = this.domainInfo.getClass(DummyDomainObject.class.getName());
    FieldInfo objectAccess = classInfo.getFieldInfo("testProp");
    assertThat(objectAccess).as("The resultant object accessor shouldn't be null").isNotNull();
    DummyDomainObject domainObject = new DummyDomainObject();
    objectAccess.write(domainObject, "TEST");
    assertThat(domainObject.annotatedTestProperty).isEqualTo("TEST");
}
Also used : FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

Example 40 with FieldInfo

use of org.neo4j.ogm.metadata.FieldInfo in project neo4j-ogm by neo4j.

the class EntityAccessManagerTest method shouldPreferAnnotatedFieldWithMatchingRelationshipTypeWhenGettingIterableReader.

/**
 * @see DATAGRAPH-637
 */
@Test
public void shouldPreferAnnotatedFieldWithMatchingRelationshipTypeWhenGettingIterableReader() {
    // 2nd, try to find a field annotated with with relationship type
    ClassInfo classInfo = this.domainInfo.getClass(DummyDomainObject.class.getName());
    List<Satellite> natural = new ArrayList<>();
    natural.add(new Satellite());
    FieldInfo relationalReader = EntityAccessManager.getIterableField(classInfo, Satellite.class, "NATURAL", Relationship.Direction.OUTGOING);
    assertThat(relationalReader).as("The resultant object accessor shouldn't be null").isNotNull();
    DummyDomainObject domainObject = new DummyDomainObject();
    domainObject.naturalSatellites = natural;
    Object o = relationalReader.read(domainObject);
    assertThat(o).isEqualTo(natural);
}
Also used : ArrayList(java.util.ArrayList) Satellite(org.neo4j.ogm.domain.satellites.Satellite) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

Aggregations

FieldInfo (org.neo4j.ogm.metadata.FieldInfo)142 Test (org.junit.Test)102 ClassInfo (org.neo4j.ogm.metadata.ClassInfo)100 ArrayList (java.util.ArrayList)12 Date (java.util.Date)7 HashSet (java.util.HashSet)6 HashMap (java.util.HashMap)5 Collection (java.util.Collection)4 Satellite (org.neo4j.ogm.domain.satellites.Satellite)4 MappingException (org.neo4j.ogm.exception.core.MappingException)4 CompileContext (org.neo4j.ogm.cypher.compiler.CompileContext)3 Person (org.neo4j.ogm.domain.convertible.enums.Person)3 Member (org.neo4j.ogm.domain.forum.Member)3 Topic (org.neo4j.ogm.domain.forum.Topic)3 Post (org.neo4j.ogm.domain.forum.activity.Post)3 MetaData (org.neo4j.ogm.metadata.MetaData)3 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2