use of org.neo4j.ogm.metadata.ClassInfo 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.ClassInfo 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);
}
use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.
the class IterableRelationalReaderWriterTest method testUserV22.
/**
* @see issue #36
*/
@Test
public void testUserV22() {
ClassInfo classInfo = this.domainInfo.getClass(UserV22.class.getName());
UserV22 instance = new UserV22();
List<PlainUser> relatedObject = Collections.singletonList(new PlainUser());
UserV22 otherRelatedObject = new UserV22();
assertThat(EntityAccessManager.getIterableField(classInfo, UserV22.class, KNOWS, Relationship.Direction.INCOMING)).isNull();
assertThat(EntityAccessManager.getIterableField(classInfo, UserV22.class, KNOWS, Relationship.Direction.INCOMING)).isNull();
FieldInfo relationalReader = EntityAccessManager.getIterableField(classInfo, PlainUser.class, KNOWS, Relationship.Direction.OUTGOING);
FieldInfo relationalWriter = EntityAccessManager.getIterableField(classInfo, PlainUser.class, KNOWS, Relationship.Direction.OUTGOING);
relationalWriter.write(instance, relatedObject);
assertThat(instance.plainUsers).isEqualTo(relatedObject);
assertThat(relationalReader.read(instance)).isEqualTo(relatedObject);
instance = new UserV22();
relationalWriter = EntityAccessManager.getRelationalWriter(classInfo, KNOWS, Relationship.Direction.OUTGOING, otherRelatedObject);
relationalWriter.write(instance, otherRelatedObject);
assertThat(instance.user).isEqualTo(otherRelatedObject);
}
use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.
the class IterableRelationalReaderWriterTest method testUserV3.
/**
* @see DATAGRAPH-636
*/
@Test
public void testUserV3() {
ClassInfo classInfo = this.domainInfo.getClass(UserV3.class.getName());
UserV3 instance = new UserV3();
Set<UserV3> relatedObject = Collections.singleton(new UserV3());
assertThat(EntityAccessManager.getIterableField(classInfo, UserV3.class, KNOWS, Relationship.Direction.INCOMING)).isNull();
assertThat(EntityAccessManager.getIterableField(classInfo, UserV3.class, KNOWS, Relationship.Direction.INCOMING)).isNull();
FieldInfo relationalReader = EntityAccessManager.getIterableField(classInfo, UserV3.class, KNOWS, Relationship.Direction.OUTGOING);
FieldInfo relationalWriter = EntityAccessManager.getIterableField(classInfo, UserV3.class, KNOWS, Relationship.Direction.OUTGOING);
relationalWriter.write(instance, relatedObject);
assertThat(instance.getFriend()).isEqualTo(relatedObject);
assertThat(relationalReader.read(instance)).isEqualTo(relatedObject);
}
use of org.neo4j.ogm.metadata.ClassInfo in project neo4j-ogm by neo4j.
the class IterableRelationalReaderWriterTest method testUserV20.
/**
* @see issue #36
*/
@Test
public void testUserV20() {
ClassInfo classInfo = this.domainInfo.getClass(UserV20.class.getName());
UserV20 instance = new UserV20();
List<PlainUser> relatedObject = Collections.singletonList(new PlainUser());
UserV20 otherRelatedObject = new UserV20();
assertThat(EntityAccessManager.getIterableField(classInfo, UserV20.class, KNOWS, Relationship.Direction.INCOMING)).isNull();
assertThat(EntityAccessManager.getIterableField(classInfo, UserV20.class, KNOWS, Relationship.Direction.INCOMING)).isNull();
FieldInfo relationalReader = EntityAccessManager.getIterableField(classInfo, PlainUser.class, KNOWS, Relationship.Direction.OUTGOING);
FieldInfo relationalWriter = EntityAccessManager.getIterableField(classInfo, PlainUser.class, KNOWS, Relationship.Direction.OUTGOING);
relationalWriter.write(instance, relatedObject);
assertThat(instance.plainUsers).isEqualTo(relatedObject);
assertThat(relationalReader.read(instance)).isEqualTo(relatedObject);
instance = new UserV20();
relationalWriter = EntityAccessManager.getRelationalWriter(classInfo, KNOWS, Relationship.Direction.OUTGOING, otherRelatedObject);
relationalWriter.write(instance, otherRelatedObject);
assertThat(instance.user).isEqualTo(otherRelatedObject);
}
Aggregations