Search in sources :

Example 61 with Serde

use of com.yahoo.elide.core.utils.coerce.converters.Serde in project elide by yahoo.

the class YearSerdeTest method testDeserializeDateInvalidFormat.

@Test
public void testDeserializeDateInvalidFormat() {
    String dateInString = "January";
    Serde serde = new Year.YearSerde();
    assertThrows(DateTimeParseException.class, () -> serde.deserialize(dateInString));
}
Also used : Serde(com.yahoo.elide.core.utils.coerce.converters.Serde) Test(org.junit.jupiter.api.Test)

Example 62 with Serde

use of com.yahoo.elide.core.utils.coerce.converters.Serde in project elide by yahoo.

the class CoerceUtilTest method testDateToTimestamp.

@Test
public void testDateToTimestamp() {
    String dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'";
    TimeZone tz = TimeZone.getTimeZone("UTC");
    Serde oldDateSerde = CoerceUtil.lookup(Date.class);
    Serde oldTimestampSerde = CoerceUtil.lookup(java.sql.Timestamp.class);
    Serde timestampSerde = new ISO8601DateSerde(dateFormat, tz, java.sql.Timestamp.class);
    CoerceUtil.register(Date.class, new ISO8601DateSerde(dateFormat, tz));
    CoerceUtil.register(java.sql.Timestamp.class, timestampSerde);
    Date date = new Date();
    Timestamp timestamp = CoerceUtil.coerce(date, Timestamp.class);
    assertEquals(date.getTime(), timestamp.getTime());
    CoerceUtil.register(Date.class, oldDateSerde);
    CoerceUtil.register(java.sql.Timestamp.class, oldTimestampSerde);
}
Also used : ISO8601DateSerde(com.yahoo.elide.core.utils.coerce.converters.ISO8601DateSerde) Serde(com.yahoo.elide.core.utils.coerce.converters.Serde) TimeZone(java.util.TimeZone) ISO8601DateSerde(com.yahoo.elide.core.utils.coerce.converters.ISO8601DateSerde) Timestamp(java.sql.Timestamp) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Aggregations

Serde (com.yahoo.elide.core.utils.coerce.converters.Serde)62 Test (org.junit.jupiter.api.Test)59 LocalDateTime (java.time.LocalDateTime)34 OffsetDateTime (java.time.OffsetDateTime)12 Timestamp (java.sql.Timestamp)10 Time (com.yahoo.elide.datastores.aggregation.timegrains.Time)6 ISOWeek (com.yahoo.elide.datastores.aggregation.timegrains.ISOWeek)5 Quarter (com.yahoo.elide.datastores.aggregation.timegrains.Quarter)5 Week (com.yahoo.elide.datastores.aggregation.timegrains.Week)5 Day (com.yahoo.elide.datastores.aggregation.timegrains.Day)4 Hour (com.yahoo.elide.datastores.aggregation.timegrains.Hour)4 Minute (com.yahoo.elide.datastores.aggregation.timegrains.Minute)4 Month (com.yahoo.elide.datastores.aggregation.timegrains.Month)4 Second (com.yahoo.elide.datastores.aggregation.timegrains.Second)4 Year (com.yahoo.elide.datastores.aggregation.timegrains.Year)4 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)1 Injector (com.yahoo.elide.core.dictionary.Injector)1 AccessibleObject (com.yahoo.elide.core.type.AccessibleObject)1 Field (com.yahoo.elide.core.type.Field)1 Method (com.yahoo.elide.core.type.Method)1