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();
}
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);
}
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");
}
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);
}
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");
}
Aggregations