Search in sources :

Example 6 with ContainerResource

use of org.dataportabilityproject.types.transfer.models.ContainerResource in project data-transfer-project by google.

the class PhotosContainerResourceTest method verifySerializeDeserialize.

@Test
public void verifySerializeDeserialize() throws Exception {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.registerSubtypes(PhotosContainerResource.class);
    List<PhotoAlbum> albums = ImmutableList.of(new PhotoAlbum("id1", "albumb1", "This is a fake albumb"));
    List<PhotoModel> photos = ImmutableList.of(new PhotoModel("Pic1", "http://fake.com/1.jpg", "A pic", "image/jpg", "id1"), new PhotoModel("Pic2", "https://fake.com/pic.png", "fine art", "image/png", "id1"));
    ContainerResource data = new PhotosContainerResource(albums, photos);
    String serialized = objectMapper.writeValueAsString(data);
    ContainerResource deserializedModel = objectMapper.readValue(serialized, ContainerResource.class);
    Truth.assertThat(deserializedModel).isNotNull();
    Truth.assertThat(deserializedModel).isInstanceOf(PhotosContainerResource.class);
    PhotosContainerResource deserialized = (PhotosContainerResource) deserializedModel;
    Truth.assertThat(deserialized.getAlbums()).hasSize(1);
    Truth.assertThat(deserialized.getPhotos()).hasSize(2);
}
Also used : ContainerResource(org.dataportabilityproject.types.transfer.models.ContainerResource) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 7 with ContainerResource

use of org.dataportabilityproject.types.transfer.models.ContainerResource 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.now(), 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), new CalendarEventModel("id1", "event2", null, ImmutableList.of(new CalendarAttendeeModel("Person", "a@gmail.com", false)), "place 2", today, today));
    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);
}
Also used : CalendarEventTime(org.dataportabilityproject.types.transfer.models.calendar.CalendarEventModel.CalendarEventTime) ContainerResource(org.dataportabilityproject.types.transfer.models.ContainerResource) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 8 with ContainerResource

use of org.dataportabilityproject.types.transfer.models.ContainerResource in project data-transfer-project by google.

the class MailContainerResourceTest method verifySerializeDeserialize.

@Test
public void verifySerializeDeserialize() throws Exception {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.registerSubtypes(MailContainerResource.class);
    List<MailContainerModel> containers = ImmutableList.of(new MailContainerModel("id1", "container1"), new MailContainerModel("id2", "container2"));
    List<MailMessageModel> messages = ImmutableList.of(new MailMessageModel("foo", ImmutableList.of("1")), new MailMessageModel("bar", ImmutableList.of("1", "2'")));
    ContainerResource data = new MailContainerResource(containers, messages);
    String serialized = objectMapper.writeValueAsString(data);
    ContainerResource deserializedModel = objectMapper.readValue(serialized, ContainerResource.class);
    Truth.assertThat(deserializedModel).isNotNull();
    Truth.assertThat(deserializedModel).isInstanceOf(MailContainerResource.class);
    MailContainerResource deserialized = (MailContainerResource) deserializedModel;
    Truth.assertThat(deserialized.getMessages()).hasSize(2);
    Truth.assertThat(deserialized.getFolders()).hasSize(2);
}
Also used : ContainerResource(org.dataportabilityproject.types.transfer.models.ContainerResource) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

ContainerResource (org.dataportabilityproject.types.transfer.models.ContainerResource)8 Test (org.junit.Test)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 ContinuationData (org.dataportabilityproject.spi.transfer.types.ContinuationData)4 ExportInformation (org.dataportabilityproject.spi.transfer.types.ExportInformation)4 IdOnlyContainerResource (org.dataportabilityproject.spi.transfer.types.IdOnlyContainerResource)3 StringPaginationToken (org.dataportabilityproject.spi.transfer.types.StringPaginationToken)3 CalendarContainerResource (org.dataportabilityproject.types.transfer.models.calendar.CalendarContainerResource)3 PaginationData (org.dataportabilityproject.spi.transfer.types.PaginationData)2 CalendarEventModel (org.dataportabilityproject.types.transfer.models.calendar.CalendarEventModel)2 InOrder (org.mockito.InOrder)2 JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)1 Calendar (com.google.api.services.calendar.Calendar)1 CalendarList (com.google.api.services.calendar.model.CalendarList)1 CalendarListEntry (com.google.api.services.calendar.model.CalendarListEntry)1 Event (com.google.api.services.calendar.model.Event)1 Events (com.google.api.services.calendar.model.Events)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1