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