Search in sources :

Example 96 with FieldInfo

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();
    }
}
Also used : Comment(org.neo4j.ogm.domain.forum.activity.Comment) HashMap(java.util.HashMap) Post(org.neo4j.ogm.domain.forum.activity.Post) Satellite(org.neo4j.ogm.domain.satellites.Satellite) Topic(org.neo4j.ogm.domain.forum.Topic) Member(org.neo4j.ogm.domain.forum.Member) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

Example 97 with FieldInfo

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

Example 98 with FieldInfo

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

Example 99 with FieldInfo

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

Example 100 with FieldInfo

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);
}
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