Search in sources :

Example 1 with CalendarEventTime

use of org.datatransferproject.types.common.models.calendar.CalendarEventModel.CalendarEventTime in project data-transfer-project by google.

the class CalendarContainerResourceTest method verifySerializeDeserialize.

@Test
public void verifySerializeDeserialize() throws Exception {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.registerModule(new JavaTimeModule());
    objectMapper.registerSubtypes(CalendarContainerResource.class);
    CalendarEventTime today = new CalendarEventTime(OffsetDateTime.of(1970, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC), true);
    List<CalendarModel> calendars = ImmutableList.of(new CalendarModel("id1", "name", "description"));
    List<CalendarEventModel> events = ImmutableList.of(new CalendarEventModel("id1", "event1", "A note", null, "Place1", today, today, null), new CalendarEventModel("id1", "event2", null, ImmutableList.of(new CalendarAttendeeModel("Person", "a@gmail.com", false)), "place 2", today, today, null));
    ContainerResource data = new CalendarContainerResource(calendars, events);
    String serialized = objectMapper.writeValueAsString(data);
    ContainerResource deserializedModel = objectMapper.readValue(serialized, ContainerResource.class);
    Truth.assertThat(deserializedModel).isNotNull();
    Truth.assertThat(deserializedModel).isInstanceOf(CalendarContainerResource.class);
    CalendarContainerResource deserialized = (CalendarContainerResource) deserializedModel;
    Truth.assertThat(deserialized.getCalendars()).hasSize(1);
    Truth.assertThat(deserialized.getEvents()).hasSize(2);
    Truth.assertThat(deserialized).isEqualTo(data);
}
Also used : CalendarEventTime(org.datatransferproject.types.common.models.calendar.CalendarEventModel.CalendarEventTime) ContainerResource(org.datatransferproject.types.common.models.ContainerResource) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)1 ContainerResource (org.datatransferproject.types.common.models.ContainerResource)1 CalendarEventTime (org.datatransferproject.types.common.models.calendar.CalendarEventModel.CalendarEventTime)1 Test (org.junit.Test)1