use of org.neo4j.ogm.metadata.FieldInfo in project neo4j-ogm by neo4j.
the class EntityAccessManagerTest method shouldRetrieveAppropriateObjectAccessToAllRelationalAttributesForParticularClass.
@Test
public void shouldRetrieveAppropriateObjectAccessToAllRelationalAttributesForParticularClass() {
ClassInfo classInfo = this.domainInfo.getClass(DummyDomainObject.class.getName());
DummyDomainObject domainObject = new DummyDomainObject();
domainObject.postWithoutAccessorMethods = new Post();
domainObject.favouriteTopic = new Topic();
domainObject.member = new Member();
domainObject.readOnlyComment = new Comment();
domainObject.registeredMember = new Member();
domainObject.naturalSatellites = new ArrayList<>();
domainObject.artificialSatellites = Collections.singletonList(new Satellite());
Collection<FieldInfo> relationalAccessors = classInfo.relationshipFields();
assertThat(relationalAccessors).as("The resultant list of object accessors shouldn't be null").isNotNull();
assertThat(relationalAccessors).as("An unexpected number of accessors was returned").hasSize(7);
Map<String, Class<? extends FieldInfo>> expectedRelationalReaders = new HashMap<>();
expectedRelationalReaders.put("COMMENT", FieldInfo.class);
expectedRelationalReaders.put("FAVOURITE_TOPIC", FieldInfo.class);
expectedRelationalReaders.put("CONTAINS", FieldInfo.class);
expectedRelationalReaders.put("POST_WITHOUT_ACCESSOR_METHODS", FieldInfo.class);
expectedRelationalReaders.put("NATURAL", FieldInfo.class);
expectedRelationalReaders.put("ARTIFICIAL", FieldInfo.class);
expectedRelationalReaders.put("REGISTERED", FieldInfo.class);
for (FieldInfo objectAccess : relationalAccessors) {
String relType = objectAccess.relationshipType();
assertThat(expectedRelationalReaders.containsKey(relType)).as("Relationship type " + relType + " wasn't expected").isTrue();
assertThat(objectAccess.getClass()).isEqualTo(expectedRelationalReaders.get(relType));
assertThat(objectAccess.read(domainObject)).isNotNull();
}
}
use of org.neo4j.ogm.metadata.FieldInfo in project neo4j-ogm by neo4j.
the class EntityAccessManagerTest method shouldPreferMethodBasedAccessToFieldAccessWhenReadingFromObjectsWithoutAnnotations.
@Test
public void shouldPreferMethodBasedAccessToFieldAccessWhenReadingFromObjectsWithoutAnnotations() {
ClassInfo classInfo = this.domainInfo.getClass(DummyDomainObject.class.getName());
DummyDomainObject domainObject = new DummyDomainObject();
domainObject.nonAnnotatedTestProperty = 30.16;
FieldInfo objectAccess = classInfo.getFieldInfo("nonAnnotatedTestProperty");
assertThat(objectAccess).as("The resultant object accessor shouldn't be null").isNotNull();
assertThat(objectAccess.readProperty(domainObject)).isEqualTo(domainObject.nonAnnotatedTestProperty);
}
use of org.neo4j.ogm.metadata.FieldInfo in project neo4j-ogm by neo4j.
the class EntityAccessManagerTest method shouldRetrieveObjectAccessForWritingIterableObject.
@Test
public void shouldRetrieveObjectAccessForWritingIterableObject() {
ClassInfo classInfo = this.domainInfo.getClass(Program.class.getName());
FieldInfo iterableAccess = EntityAccessManager.getIterableField(classInfo, Satellite.class, "satellites", Relationship.Direction.OUTGOING);
assertThat(iterableAccess).as("The resultant object accessor shouldn't be null").isNotNull();
Program spaceProgramme = new Program();
iterableAccess.write(spaceProgramme, Arrays.asList(new Satellite()));
assertThat(spaceProgramme.getSatellites()).as("The satellites list wasn't set correctly").isNotNull();
assertThat(spaceProgramme.getSatellites().isEmpty()).as("The satellites list wasn't set correctly").isFalse();
}
use of org.neo4j.ogm.metadata.FieldInfo in project neo4j-ogm by neo4j.
the class IterableRelationalReaderWriterTest method testUserV14.
/**
* @see DATAGRAPH-636
*/
@Test
public void testUserV14() {
ClassInfo classInfo = this.domainInfo.getClass(UserV14.class.getName());
UserV14 instance = new UserV14();
Set<UserV14> relatedObject = Collections.singleton(new UserV14());
assertThat(EntityAccessManager.getIterableField(classInfo, UserV14.class, KNOWS, Relationship.Direction.INCOMING)).isNull();
assertThat(EntityAccessManager.getIterableField(classInfo, UserV14.class, KNOWS, Relationship.Direction.INCOMING)).isNull();
FieldInfo relationalReader = EntityAccessManager.getIterableField(classInfo, UserV14.class, KNOWS, Relationship.Direction.OUTGOING);
FieldInfo relationalWriter = EntityAccessManager.getIterableField(classInfo, UserV14.class, KNOWS, Relationship.Direction.OUTGOING);
relationalWriter.write(instance, relatedObject);
assertThat(instance.knows).isEqualTo(relatedObject);
assertThat(relationalReader.read(instance)).isEqualTo(relatedObject);
}
use of org.neo4j.ogm.metadata.FieldInfo in project neo4j-ogm by neo4j.
the class IterableRelationalReaderWriterTest method testUserV1.
/**
* @see DATAGRAPH-636
*/
@Test
public void testUserV1() {
final String KNOWN_BY = "KNOWN_BY";
ClassInfo classInfo = this.domainInfo.getClass(UserV1.class.getName());
UserV1 instance = new UserV1();
Set<UserV1> relatedObject = Collections.singleton(new UserV1());
assertThat(EntityAccessManager.getIterableField(classInfo, UserV1.class, KNOWN_BY, Relationship.Direction.OUTGOING)).isNull();
FieldInfo relationalReader = EntityAccessManager.getIterableField(classInfo, UserV1.class, KNOWN_BY, Relationship.Direction.INCOMING);
relationalReader.write(instance, relatedObject);
assertThat(instance.getKnownBy()).isEqualTo(relatedObject);
assertThat(relationalReader.read(instance)).isEqualTo(relatedObject);
}
Aggregations