Search in sources :

Example 11 with FieldInfo

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

the class DateConversionTest method assertCollectionFieldDateConversionToISO8601FormatByDefault.

// DATAGRAPH-550
@Test
public void assertCollectionFieldDateConversionToISO8601FormatByDefault() {
    simpleDateISO8601format.setTimeZone(TimeZone.getTimeZone("UTC"));
    List<Date> dates = new ArrayList<>();
    dates.add(new Date(0));
    dates.add(new Date(20000));
    FieldInfo fieldInfo = memoInfo.propertyField("implementations");
    assertThat(fieldInfo.hasPropertyConverter()).isTrue();
    AttributeConverter attributeConverter = fieldInfo.getPropertyConverter();
    assertThat(attributeConverter.getClass().isAssignableFrom(DateCollectionStringConverter.class)).isTrue();
    String[] converted = (String[]) attributeConverter.toGraphProperty(dates);
    assertThat(converted[0].equals("1970-01-01T00:00:00.000Z") || converted[1].equals("1970-01-01T00:00:00.000Z")).isTrue();
    assertThat(converted[0].equals(simpleDateISO8601format.format(new Date(20000))) || converted[1].equals(simpleDateISO8601format.format(new Date(20000)))).isTrue();
}
Also used : ArrayList(java.util.ArrayList) DateString(org.neo4j.ogm.annotation.typeconversion.DateString) Date(java.util.Date) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) Test(org.junit.Test)

Example 12 with FieldInfo

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

the class DateConversionTest method assertFieldCustomTypeConversion.

@Test
public void assertFieldCustomTypeConversion() {
    FieldInfo fieldInfo = memoInfo.propertyField("approved");
    assertThat(fieldInfo.hasPropertyConverter()).isTrue();
    AttributeConverter attributeConverter = fieldInfo.getPropertyConverter();
    assertThat(attributeConverter.toGraphProperty(new Date(1234567890123L))).isEqualTo("20090213113130");
}
Also used : FieldInfo(org.neo4j.ogm.metadata.FieldInfo) Date(java.util.Date) Test(org.junit.Test)

Example 13 with FieldInfo

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

the class DateConversionTest method assertFieldDateLongConversion.

@Test
public void assertFieldDateLongConversion() {
    FieldInfo fieldInfo = memoInfo.propertyField("closed");
    assertThat(fieldInfo.hasPropertyConverter()).isTrue();
    AttributeConverter attributeConverter = fieldInfo.getPropertyConverter();
    assertThat(attributeConverter.getClass().isAssignableFrom(DateLongConverter.class)).isTrue();
    Date date = new Date(0);
    Long value = (Long) attributeConverter.toGraphProperty(date);
    assertThat(value).isEqualTo(new Long(0));
}
Also used : FieldInfo(org.neo4j.ogm.metadata.FieldInfo) Date(java.util.Date) Test(org.junit.Test)

Example 14 with FieldInfo

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

the class DateConversionTest method assertFieldDateConversionWithExplicitAnnotation.

// DATAGRAPH-424
@Test
public void assertFieldDateConversionWithExplicitAnnotation() {
    FieldInfo fieldInfo = memoInfo.propertyField("modified");
    assertThat(fieldInfo.hasPropertyConverter()).isTrue();
    AttributeConverter attributeConverter = fieldInfo.getPropertyConverter();
    assertThat(attributeConverter.getClass().isAssignableFrom(DateStringConverter.class)).isTrue();
    assertThat(attributeConverter.toGraphProperty(new Date(0))).isEqualTo("1970-01-01T00:00:00.000Z");
}
Also used : FieldInfo(org.neo4j.ogm.metadata.FieldInfo) Date(java.util.Date) Test(org.junit.Test)

Example 15 with FieldInfo

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

the class DateConversionTest method assertFieldDateConversionToISO8601FormatByDefault.

@Test
public void assertFieldDateConversionToISO8601FormatByDefault() {
    FieldInfo fieldInfo = memoInfo.propertyField("recorded");
    assertThat(fieldInfo.hasPropertyConverter()).isTrue();
    AttributeConverter attributeConverter = fieldInfo.getPropertyConverter();
    assertThat(attributeConverter.getClass().isAssignableFrom(DateStringConverter.class)).isTrue();
    assertThat(attributeConverter.toGraphProperty(new Date(0))).isEqualTo("1970-01-01T00:00:00.000Z");
}
Also used : FieldInfo(org.neo4j.ogm.metadata.FieldInfo) Date(java.util.Date) 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