Search in sources :

Example 1 with Algebra

use of org.neo4j.ogm.domain.convertible.enums.Algebra 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 2 with Algebra

use of org.neo4j.ogm.domain.convertible.enums.Algebra 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)

Aggregations

Test (org.junit.Test)2 Algebra (org.neo4j.ogm.domain.convertible.enums.Algebra)2 FieldInfo (org.neo4j.ogm.metadata.FieldInfo)2