use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.
the class EntityAccessManagerTest method shouldUseFieldAccessUnconditionallyForReadingIdentityProperty.
@Test
public void shouldUseFieldAccessUnconditionallyForReadingIdentityProperty() {
ClassInfo classInfo = this.domainInfo.getClass(DummyDomainObject.class.getName());
final long id = 593L;
DummyDomainObject domainObject = new DummyDomainObject();
domainObject.setId(id);
FieldInfo idReader = classInfo.identityField();
assertThat(idReader).as("The resultant ID reader shouldn't be null").isNotNull();
assertThat(idReader.readProperty(domainObject)).isEqualTo(id);
}
use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.
the class EntityAccessManagerTest method shouldPreferAnnotatedFieldToPlainGetterWhenReadingFromAnObject.
@Test
public void shouldPreferAnnotatedFieldToPlainGetterWhenReadingFromAnObject() {
ClassInfo classInfo = this.domainInfo.getClass(DummyDomainObject.class.getName());
DummyDomainObject domainObject = new DummyDomainObject();
domainObject.annotatedTestProperty = "more arbitrary text";
FieldInfo objectAccess = classInfo.getFieldInfo("testProp");
assertThat(objectAccess).as("The resultant object accessor shouldn't be null").isNotNull();
assertThat(objectAccess.readProperty(domainObject)).isEqualTo(domainObject.annotatedTestProperty);
}
use of org.neo4j.ogm.metadata.ClassInfo 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.ClassInfo 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.ClassInfo 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);
}
Aggregations