Search in sources :

Example 46 with Serde

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

the class SecondSerdeTest method testDateDeserializeString.

@Test
public void testDateDeserializeString() {
    String dateInString = "2020-01-01T01:18:19";
    Second expectedDate = new Second(LocalDateTime.from(formatter.parse(dateInString)));
    String actual = "2020-01-01T01:18:19";
    Serde serde = new Second.SecondSerde();
    Object actualDate = serde.deserialize(actual);
    assertEquals(expectedDate, actualDate);
}
Also used : Serde(com.yahoo.elide.core.utils.coerce.converters.Serde) Second(com.yahoo.elide.datastores.aggregation.timegrains.Second) Test(org.junit.jupiter.api.Test)

Example 47 with Serde

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

the class SecondSerdeTest method testDeserializeOffsetDateTime.

@Test
public void testDeserializeOffsetDateTime() {
    String dateInString = "2020-01-01T01:18:19";
    Second expectedDate = new Second(LocalDateTime.from(formatter.parse(dateInString)));
    OffsetDateTime dateTime = OffsetDateTime.of(2020, 1, 1, 1, 18, 19, 0, ZoneOffset.UTC);
    Serde serde = new Second.SecondSerde();
    Object actualDate = serde.deserialize(dateTime);
    assertEquals(expectedDate, actualDate);
}
Also used : Serde(com.yahoo.elide.core.utils.coerce.converters.Serde) Second(com.yahoo.elide.datastores.aggregation.timegrains.Second) OffsetDateTime(java.time.OffsetDateTime) Test(org.junit.jupiter.api.Test)

Example 48 with Serde

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

the class SecondSerdeTest method testDeserializeDateInvalidFormat.

@Test
public void testDeserializeDateInvalidFormat() {
    String dateInString = "00:18:19 2020-01-01";
    Serde serde = new Second.SecondSerde();
    assertThrows(DateTimeParseException.class, () -> serde.deserialize(dateInString));
}
Also used : Serde(com.yahoo.elide.core.utils.coerce.converters.Serde) Test(org.junit.jupiter.api.Test)

Example 49 with Serde

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

the class TimeSerdeTest method testTimeDeserializeSecond.

@Test
public void testTimeDeserializeSecond() {
    LocalDateTime localDate = LocalDateTime.of(2020, java.time.Month.of(01), 01, 00, 00, 00);
    Time expectedDate = new Time(localDate, true, true, true, true, true, true, (unused) -> "");
    Serde serde = new Time.TimeSerde();
    Object actualDate = serde.deserialize(SECOND);
    assertEquals(expectedDate, actualDate);
    assertEquals(SECOND, serde.serialize(actualDate));
}
Also used : LocalDateTime(java.time.LocalDateTime) Serde(com.yahoo.elide.core.utils.coerce.converters.Serde) Time(com.yahoo.elide.datastores.aggregation.timegrains.Time) LocalDateTime(java.time.LocalDateTime) Test(org.junit.jupiter.api.Test)

Example 50 with Serde

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

the class TimeSerdeTest method testTimeDeserializeHour.

@Test
public void testTimeDeserializeHour() {
    LocalDateTime localDate = LocalDateTime.of(2020, java.time.Month.of(01), 01, 00, 00, 00);
    Time expectedDate = new Time(localDate, true, true, true, true, true, true, (unused) -> "");
    Serde serde = new Time.TimeSerde();
    Object actualDate = serde.deserialize(HOUR);
    assertEquals(expectedDate, actualDate);
    assertEquals(HOUR, serde.serialize(actualDate));
}
Also used : LocalDateTime(java.time.LocalDateTime) Serde(com.yahoo.elide.core.utils.coerce.converters.Serde) Time(com.yahoo.elide.datastores.aggregation.timegrains.Time) LocalDateTime(java.time.LocalDateTime) 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