Search in sources :

Example 41 with ClassInfo

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

Example 42 with ClassInfo

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);
}
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 43 with ClassInfo

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

Example 44 with ClassInfo

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

Example 45 with ClassInfo

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