Search in sources :

Example 31 with FieldInfo

use of org.neo4j.ogm.metadata.FieldInfo in project neo4j-ogm by neo4j.

the class AnnotatedFieldWithNoSetterAndNonSetterTest method shouldPreferAnnotatedFieldOverNonSetterInAbsenceOfSetterForRelationshipEntity.

@Test
public void shouldPreferAnnotatedFieldOverNonSetterInAbsenceOfSetterForRelationshipEntity() {
    ClassInfo classInfo = this.domainInfo.getClass(End.class.getName());
    RelEntity relEntity = new RelEntity();
    Set<RelEntity> parameter = new HashSet();
    parameter.addAll(Arrays.asList(relEntity));
    FieldInfo objectAccess = EntityAccessManager.getRelationalWriter(classInfo, "REL_ENTITY_TYPE", Relationship.Direction.INCOMING, relEntity);
    assertThat(objectAccess).as("The resultant object accessor shouldn't be null").isNotNull();
    assertThat(objectAccess instanceof FieldInfo).as("The access mechanism should be via the field").isTrue();
    End end = new End();
    objectAccess.write(end, parameter);
    assertThat(parameter).isEqualTo(end.getRelEntities());
}
Also used : FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 32 with FieldInfo

use of org.neo4j.ogm.metadata.FieldInfo in project neo4j-ogm by neo4j.

the class EntityAccessManagerTest method shouldPreferAnnotatedFieldToMethodNotAnnotatedWithPropertyWhenFindingPropertyToSet.

/**
 * @see DATAGRAPH-674
 */
@Test
public void shouldPreferAnnotatedFieldToMethodNotAnnotatedWithPropertyWhenFindingPropertyToSet() {
    ClassInfo classInfo = this.domainInfo.getClass(DummyDomainObject.class.getName());
    DummyDomainObject domainObject = new DummyDomainObject();
    FieldInfo objectAccess = classInfo.getFieldInfo("testIgnored");
    assertThat(objectAccess).as("The resultant object accessor shouldn't be null").isNotNull();
    assertThat(objectAccess instanceof FieldInfo).isTrue();
    assertThat(objectAccess.type()).isEqualTo(String.class);
    objectAccess.write(domainObject, "TEST");
    assertThat(domainObject.propertyMethodsIgnored).isEqualTo("TEST");
}
Also used : FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

Example 33 with FieldInfo

use of org.neo4j.ogm.metadata.FieldInfo in project neo4j-ogm by neo4j.

the class EntityAccessManagerTest method shouldPreferAnnotatedFieldToGetterWhenReadingFromAnObject.

@Test
public void shouldPreferAnnotatedFieldToGetterWhenReadingFromAnObject() {
    ClassInfo classInfo = this.domainInfo.getClass(DummyDomainObject.class.getName());
    DummyDomainObject domainObject = new DummyDomainObject();
    domainObject.propertyWithDifferentAnnotatedGetter = "more arbitrary text";
    Collection<FieldInfo> readers = classInfo.propertyFields();
    FieldInfo objectAccess = classInfo.getFieldInfo("differentAnnotationOnGetter");
    assertThat(objectAccess).as("The resultant object accessor shouldn't be null").isNotNull();
    assertThat(objectAccess.readProperty(domainObject)).isEqualTo(domainObject.propertyWithDifferentAnnotatedGetter);
    for (FieldInfo reader : readers) {
        if (reader.propertyName().equals("differentAnnotationOnGetter")) {
            assertThat(reader instanceof FieldInfo).isTrue();
        }
    }
}
Also used : FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

Example 34 with FieldInfo

use of org.neo4j.ogm.metadata.FieldInfo 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 35 with FieldInfo

use of org.neo4j.ogm.metadata.FieldInfo 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)

Aggregations

FieldInfo (org.neo4j.ogm.metadata.FieldInfo)142 Test (org.junit.Test)102 ClassInfo (org.neo4j.ogm.metadata.ClassInfo)100 ArrayList (java.util.ArrayList)12 Date (java.util.Date)7 HashSet (java.util.HashSet)6 HashMap (java.util.HashMap)5 Collection (java.util.Collection)4 Satellite (org.neo4j.ogm.domain.satellites.Satellite)4 MappingException (org.neo4j.ogm.exception.core.MappingException)4 CompileContext (org.neo4j.ogm.cypher.compiler.CompileContext)3 Person (org.neo4j.ogm.domain.convertible.enums.Person)3 Member (org.neo4j.ogm.domain.forum.Member)3 Topic (org.neo4j.ogm.domain.forum.Topic)3 Post (org.neo4j.ogm.domain.forum.activity.Post)3 MetaData (org.neo4j.ogm.metadata.MetaData)3 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2