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);
}
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);
}
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);
}
Aggregations