Search in sources :

Example 91 with FieldInfo

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

the class EntityAccessManagerTest method shouldPreferFieldBasedOnRelationshipTypeToPlainSetterWithMatchingParameterType.

@Test
public void shouldPreferFieldBasedOnRelationshipTypeToPlainSetterWithMatchingParameterType() {
    // 4th, try to find a "XYZ" field name where XYZ is derived from the relationship type
    ClassInfo classInfo = this.domainInfo.getClass(DummyDomainObject.class.getName());
    Topic favouriteTopic = new Topic();
    // NB: the setter is called setTopic here, so a relationship type of just "TOPIC" would choose the setter
    FieldInfo objectAccess = EntityAccessManager.getRelationalWriter(classInfo, "FAVOURITE_TOPIC", Relationship.Direction.OUTGOING, favouriteTopic);
    assertThat(objectAccess).as("The resultant object accessor shouldn't be null").isNotNull();
    DummyDomainObject domainObject = new DummyDomainObject();
    objectAccess.write(domainObject, favouriteTopic);
    assertThat(favouriteTopic).isEqualTo(domainObject.favouriteTopic);
    assertThat(domainObject.topicAccessorWasCalled).as("The access should be via the field").isFalse();
}
Also used : Topic(org.neo4j.ogm.domain.forum.Topic) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

Example 92 with FieldInfo

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

the class EntityAccessManagerTest method shouldPreferAnnotatedFieldToPlainSetterMatchingRelationshipTypeWhenSettingRelationshipObject.

@Test
public void shouldPreferAnnotatedFieldToPlainSetterMatchingRelationshipTypeWhenSettingRelationshipObject() {
    // 2nd, try to find a field annotated with with relationship type
    ClassInfo classInfo = this.domainInfo.getClass(DummyDomainObject.class.getName());
    Member parameter = new Member();
    FieldInfo objectAccess = EntityAccessManager.getRelationalWriter(classInfo, "CONTAINS", Relationship.Direction.OUTGOING, parameter);
    assertThat(objectAccess).as("The resultant object accessor shouldn't be null").isNotNull();
    DummyDomainObject domainObject = new DummyDomainObject();
    objectAccess.write(domainObject, parameter);
    assertThat(parameter).isEqualTo(domainObject.member);
    Member otherMember = new Member();
    objectAccess = EntityAccessManager.getRelationalWriter(classInfo, "REGISTERED", Relationship.Direction.OUTGOING, otherMember);
    assertThat(objectAccess).as("The resultant object accessor shouldn't be null").isNotNull();
    domainObject = new DummyDomainObject();
    objectAccess.write(domainObject, otherMember);
    assertThat(otherMember).isEqualTo(domainObject.registeredMember);
}
Also used : Member(org.neo4j.ogm.domain.forum.Member) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

Example 93 with FieldInfo

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

the class EntityAccessManagerTest method shouldPreferAnnotatedFieldToPlainGetterMethodMatchingRelationshipType.

@Test
public void shouldPreferAnnotatedFieldToPlainGetterMethodMatchingRelationshipType() {
    ClassInfo classInfo = this.domainInfo.getClass(DummyDomainObject.class.getName());
    DummyDomainObject domainObject = new DummyDomainObject();
    domainObject.member = new Member();
    domainObject.registeredMember = new Member();
    FieldInfo reader = EntityAccessManager.getRelationalReader(classInfo, "CONTAINS", Relationship.Direction.OUTGOING);
    assertThat(reader).as("The resultant object reader shouldn't be null").isNotNull();
    assertThat(reader.read(domainObject)).isSameAs(domainObject.member);
    assertThat(reader.relationshipType()).isEqualTo("CONTAINS");
    reader = EntityAccessManager.getRelationalReader(classInfo, "REGISTERED", Relationship.Direction.OUTGOING);
    assertThat(reader).as("The resultant object reader shouldn't be null").isNotNull();
    assertThat(reader.read(domainObject)).isSameAs(domainObject.registeredMember);
    assertThat(reader.relationshipType()).isEqualTo("REGISTERED");
}
Also used : Member(org.neo4j.ogm.domain.forum.Member) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

Example 94 with FieldInfo

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

the class EntityAccessManagerTest method shouldDefaultToFieldThatMatchesTheParameterTypeIfRelationshipTypeCannotBeMatchedAndNoSetterExists.

@Test
public void shouldDefaultToFieldThatMatchesTheParameterTypeIfRelationshipTypeCannotBeMatchedAndNoSetterExists() {
    // 6th, try to find a field that shares the same type as the parameter
    ClassInfo classInfo = this.domainInfo.getClass(DummyDomainObject.class.getName());
    Post forumPost = new Post();
    FieldInfo objectAccess = EntityAccessManager.getRelationalWriter(classInfo, "UTTER_RUBBISH", Relationship.Direction.OUTGOING, forumPost);
    assertThat(objectAccess).as("The resultant object accessor shouldn't be null").isNotNull();
    DummyDomainObject domainObject = new DummyDomainObject();
    objectAccess.write(domainObject, forumPost);
    assertThat(forumPost).isEqualTo(domainObject.postWithoutAccessorMethods);
}
Also used : Post(org.neo4j.ogm.domain.forum.activity.Post) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

Example 95 with FieldInfo

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

the class EntityAccessManagerTest method shouldReadFromFieldMatchingRelationshipTypeInObjectWithoutAnnotationsOrAccessorMethods.

@Test
public void shouldReadFromFieldMatchingRelationshipTypeInObjectWithoutAnnotationsOrAccessorMethods() {
    ClassInfo classInfo = this.domainInfo.getClass(DummyDomainObject.class.getName());
    DummyDomainObject domainObject = new DummyDomainObject();
    domainObject.postWithoutAccessorMethods = new Post();
    FieldInfo reader = EntityAccessManager.getRelationalReader(classInfo, "POST_WITHOUT_ACCESSOR_METHODS", Relationship.Direction.OUTGOING);
    assertThat(reader).as("The resultant object accessor shouldn't be null").isNotNull();
    assertThat(reader.read(domainObject)).isSameAs(domainObject.postWithoutAccessorMethods);
    assertThat(reader.relationshipType()).isEqualTo("POST_WITHOUT_ACCESSOR_METHODS");
}
Also used : Post(org.neo4j.ogm.domain.forum.activity.Post) 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