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();
}
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();
}
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");
}
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");
}
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);
}
Aggregations