Search in sources :

Example 16 with FieldInfo

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

the class EnumConversionTest method shouldWorkOnEmptyGraphPropertyWithLenientConversionEnabled.

/**
 * @see issue #424
 */
@Test
public void shouldWorkOnEmptyGraphPropertyWithLenientConversionEnabled() {
    FieldInfo fieldInfo = algebraInfo.propertyField("operationLenient");
    assertThat(fieldInfo.hasPropertyConverter()).isTrue();
    AttributeConverter attributeConverter = fieldInfo.getPropertyConverter();
    assertThat(attributeConverter.toEntityAttribute("")).isNull();
}
Also used : FieldInfo(org.neo4j.ogm.metadata.FieldInfo) Test(org.junit.Test)

Example 17 with FieldInfo

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

the class EnumConversionTest method testEducationCollectionFieldWithAutoDetectedConverter.

/**
 * @see DATAGRAPH-550
 */
@Test
public void testEducationCollectionFieldWithAutoDetectedConverter() {
    List<Education> completedEducation = new ArrayList<>();
    completedEducation.add(Education.HIGHSCHOOL);
    completedEducation.add(Education.BACHELORS);
    Person bob = new Person();
    bob.setCompletedEducation(completedEducation);
    FieldInfo fieldInfo = personInfo.propertyField("completedEducation");
    assertThat(fieldInfo.hasPropertyConverter()).isTrue();
    String[] converted = (String[]) fieldInfo.getPropertyConverter().toGraphProperty(bob.getCompletedEducation());
    assertThat("HIGHSCHOOL".equals(converted[0]) || "HIGHSCHOOL".equals(converted[1])).isTrue();
    assertThat("BACHELORS".equals(converted[0]) || "BACHELORS".equals(converted[1])).isTrue();
}
Also used : Education(org.neo4j.ogm.domain.convertible.enums.Education) ArrayList(java.util.ArrayList) Person(org.neo4j.ogm.domain.convertible.enums.Person) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) Test(org.junit.Test)

Example 18 with FieldInfo

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

the class EnumConversionTest method testSaveFieldWithAnnotatedConverter.

@Test
public void testSaveFieldWithAnnotatedConverter() {
    FieldInfo fieldInfo = algebraInfo.propertyField("numberSystem");
    assertThat(fieldInfo.hasPropertyConverter()).isTrue();
    Algebra algebra = new Algebra();
    algebra.setNumberSystem(NumberSystem.NATURAL);
    assertThat(algebra.getNumberSystem().getDomain()).isEqualTo("N");
    String value = (String) fieldInfo.getPropertyConverter().toGraphProperty(algebra.getNumberSystem());
    // the converted enum value that will be stored as a neo4j node / rel property
    assertThat(value).isEqualTo("NATURAL");
}
Also used : Algebra(org.neo4j.ogm.domain.convertible.enums.Algebra) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) Test(org.junit.Test)

Example 19 with FieldInfo

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

the class EnumConversionTest method testLoadFieldWithAnnotatedConverter.

@Test
public void testLoadFieldWithAnnotatedConverter() {
    FieldInfo fieldInfo = algebraInfo.propertyField("numberSystem");
    assertThat(fieldInfo.hasPropertyConverter()).isTrue();
    // a node / rel property value loaded from neo4j, to be stored in on an enum
    String value = "INTEGER";
    Algebra algebra = new Algebra();
    algebra.setNumberSystem((NumberSystem) fieldInfo.getPropertyConverter().toEntityAttribute(value));
    assertThat(algebra.getNumberSystem()).isEqualTo(NumberSystem.INTEGER);
    assertThat(algebra.getNumberSystem().getDomain()).isEqualTo("Z");
}
Also used : Algebra(org.neo4j.ogm.domain.convertible.enums.Algebra) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) Test(org.junit.Test)

Example 20 with FieldInfo

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

the class EnumConversionTest method assertConvertingNullArrayAttributeWorksCorrectly.

/**
 * @see DATAGRAPH-550
 */
@Test
public void assertConvertingNullArrayAttributeWorksCorrectly() {
    FieldInfo methodInfo = personInfo.propertyField("inProgressEducation");
    assertThat(methodInfo.hasPropertyConverter()).isTrue();
    AttributeConverter attributeConverter = methodInfo.getPropertyConverter();
    assertThat(attributeConverter.toGraphProperty(null)).isEqualTo(null);
}
Also used : FieldInfo(org.neo4j.ogm.metadata.FieldInfo) 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