Search in sources :

Example 36 with ClassInfo

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);
}
Also used : FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

Example 37 with ClassInfo

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);
}
Also used : FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

Example 38 with ClassInfo

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);
}
Also used : ArrayList(java.util.ArrayList) Satellite(org.neo4j.ogm.domain.satellites.Satellite) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

Example 39 with ClassInfo

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);
}
Also used : ForumTopicLink(org.neo4j.ogm.domain.forum.ForumTopicLink) Topic(org.neo4j.ogm.domain.forum.Topic) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

Example 40 with ClassInfo

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);
}
Also used : FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

Aggregations

ClassInfo (org.neo4j.ogm.metadata.ClassInfo)145 FieldInfo (org.neo4j.ogm.metadata.FieldInfo)100 Test (org.junit.Test)76 ArrayList (java.util.ArrayList)11 HashSet (java.util.HashSet)8 MetaData (org.neo4j.ogm.metadata.MetaData)8 CompileContext (org.neo4j.ogm.cypher.compiler.CompileContext)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 NodeBuilder (org.neo4j.ogm.cypher.compiler.NodeBuilder)5 MappingException (org.neo4j.ogm.exception.core.MappingException)5 RowModel (org.neo4j.ogm.model.RowModel)5 Collection (java.util.Collection)4 LinkedHashSet (java.util.LinkedHashSet)4 List (java.util.List)4 Optional (java.util.Optional)4 CypherQuery (org.neo4j.ogm.cypher.query.CypherQuery)4 Member (org.neo4j.ogm.domain.forum.Member)4 Satellite (org.neo4j.ogm.domain.satellites.Satellite)4 Collections (java.util.Collections)3