use of org.datatransferproject.types.common.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);
Truth.assertThat(deserialized).isEqualTo(data);
}
use of org.datatransferproject.types.common.models.ContainerResource in project data-transfer-project by google.
the class SocialActivityContainerResourceTest method verifySerializeDeserialize.
@Test
public void verifySerializeDeserialize() throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
objectMapper.registerSubtypes(SocialActivityContainerResource.class);
Instant timePublished = OffsetDateTime.of(1970, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC).toInstant();
SocialActivityLocation location = new SocialActivityLocation("Somewhere", 0, 0);
SocialActivityAttachment linkAttachment = new SocialActivityAttachment(SocialActivityAttachmentType.LINK, "some url", "some link", "this is the link text");
SocialActivityAttachment imageAttachment = new SocialActivityAttachment(SocialActivityAttachmentType.IMAGE, "some image url", "some image", "this is the image description");
SocialActivityAttachment videoAttachment = new SocialActivityAttachment(SocialActivityAttachmentType.VIDEO, "some url", "some video", "this is the video text");
List<SocialActivityModel> activities = ImmutableList.of(new SocialActivityModel("id1", timePublished, SocialActivityType.NOTE, null, null, "Write Better tests", "Here's some sample content", "https://facebook.com"), new SocialActivityModel("id2", timePublished, SocialActivityType.POST, ImmutableList.of(linkAttachment, imageAttachment, videoAttachment), null, "Write Some more tests", "Here's some sample post content", "https://facebook.com/dtp"), new SocialActivityModel("id3", timePublished, SocialActivityType.CHECKIN, null, location, "Write Some location tests", "Here's some sample checkin content", "https://facebook.com/dtp"));
SocialActivityActor actor = new SocialActivityActor("actor ID", "actor url", "facebook.com/zuck");
ContainerResource data = new SocialActivityContainerResource("someID", actor, activities);
String serialized = objectMapper.writeValueAsString(data);
ContainerResource deserializedModel = objectMapper.readValue(serialized, ContainerResource.class);
Truth.assertThat(deserializedModel).isNotNull();
Truth.assertThat(deserializedModel).isInstanceOf(SocialActivityContainerResource.class);
SocialActivityContainerResource deserialized = (SocialActivityContainerResource) deserializedModel;
Truth.assertThat(deserialized.getActivities()).hasSize(3);
SocialActivityModel postModel = deserialized.getActivities().stream().filter(socialActivityModel -> socialActivityModel.getType() == SocialActivityType.POST).collect(Collectors.toList()).get(0);
List<SocialActivityAttachment> imageActivityAttachment = postModel.getAttachments().stream().filter(socialActivityAttachment -> socialActivityAttachment.getType() == SocialActivityAttachmentType.IMAGE).collect(Collectors.toList());
List<SocialActivityAttachment> linkActivityAttachment = postModel.getAttachments().stream().filter(socialActivityAttachment -> socialActivityAttachment.getType() == SocialActivityAttachmentType.LINK).collect(Collectors.toList());
List<SocialActivityAttachment> videoActivityAttachment = postModel.getAttachments().stream().filter(socialActivityAttachment -> socialActivityAttachment.getType() == SocialActivityAttachmentType.VIDEO).collect(Collectors.toList());
Truth.assertThat(imageActivityAttachment).hasSize(1);
Truth.assertThat(linkActivityAttachment).hasSize(1);
Truth.assertThat(videoActivityAttachment).hasSize(1);
Truth.assertThat(deserialized).isEqualTo(data);
Truth.assertThat(deserialized.getCounts().get(SocialActivityContainerResource.ACTIVITIES_COUNT_DATA_NAME)).isEqualTo(activities.size());
}
use of org.datatransferproject.types.common.models.ContainerResource in project data-transfer-project by google.
the class VideosContainerResourceTest method verifySerializeDeserialize.
@Test
public void verifySerializeDeserialize() throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerSubtypes(VideosContainerResource.class);
List<VideoAlbum> albums = ImmutableList.of(new VideoAlbum("id1", "album1", "This is a fake album"));
List<VideoModel> videos = ImmutableList.of(new VideoModel("Vid1", "http://example.com/1.mp4", "A video", "video/mp4", "v1", "id1", false), new VideoModel("Vid2", "https://example.com/2.mpeg", "A 2. video", "video/mpeg", "v2", "id1", false));
ContainerResource data = new VideosContainerResource(albums, videos);
String serialized = objectMapper.writeValueAsString(data);
ContainerResource deserializedModel = objectMapper.readValue(serialized, ContainerResource.class);
Truth.assertThat(deserializedModel).isNotNull();
Truth.assertThat(deserializedModel).isInstanceOf(VideosContainerResource.class);
VideosContainerResource deserialized = (VideosContainerResource) deserializedModel;
Truth.assertThat(deserialized.getAlbums()).hasSize(1);
Truth.assertThat(deserialized.getVideos()).hasSize(2);
Truth.assertThat(deserialized).isEqualTo(data);
}
use of org.datatransferproject.types.common.models.ContainerResource in project data-transfer-project by google.
the class TaskContainerResourceTest method verifySerializeDeserialize.
@Test
public void verifySerializeDeserialize() throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
objectMapper.registerSubtypes(TaskContainerResource.class);
List<TaskListModel> taskLists = ImmutableList.of(new TaskListModel("id1", "List 1"));
List<TaskModel> tasks = ImmutableList.of(new TaskModel("id1", "Write Better tests", "Do this soon", null, null), new TaskModel("id2", "Liberate all the data", "do this in stages", null, null));
ContainerResource data = new TaskContainerResource(taskLists, tasks);
String serialized = objectMapper.writeValueAsString(data);
ContainerResource deserializedModel = objectMapper.readValue(serialized, ContainerResource.class);
Truth.assertThat(deserializedModel).isNotNull();
Truth.assertThat(deserializedModel).isInstanceOf(TaskContainerResource.class);
TaskContainerResource deserialized = (TaskContainerResource) deserializedModel;
Truth.assertThat(deserialized.getLists()).hasSize(1);
Truth.assertThat(deserialized.getTasks()).hasSize(2);
Truth.assertThat(deserialized).isEqualTo(data);
}
use of org.datatransferproject.types.common.models.ContainerResource in project data-transfer-project by google.
the class MicrosoftPhotosExporterTest method exportAlbumAndPhotoWithNextPage.
@Test
public void exportAlbumAndPhotoWithNextPage() throws IOException {
// Setup
MicrosoftDriveItem folderItem = setUpSingleAlbum();
MicrosoftDriveItem photoItem = setUpSinglePhoto(IMAGE_URI, PHOTO_ID);
when(driveItemsResponse.getDriveItems()).thenReturn(new MicrosoftDriveItem[] { folderItem, photoItem });
when(driveItemsResponse.getNextPageLink()).thenReturn(DRIVE_PAGE_URL);
// Run
ExportResult<PhotosContainerResource> result = microsoftPhotosExporter.exportOneDrivePhotos(null, Optional.empty(), Optional.empty(), uuid);
// Verify method calls
verify(photosInterface).getDriveItemsFromSpecialFolder(MicrosoftSpecialFolder.FolderType.photos);
verify(driveItemsResponse).getDriveItems();
// Verify pagination token is set
ContinuationData continuationData = result.getContinuationData();
StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
assertThat(paginationToken.getToken()).isEqualTo(DRIVE_TOKEN_PREFIX + DRIVE_PAGE_URL);
// Verify one album is ready for import
Collection<PhotoAlbum> actualAlbums = result.getExportedData().getAlbums();
assertThat(actualAlbums.stream().map(PhotoAlbum::getId).collect(Collectors.toList())).containsExactly(FOLDER_ID);
// Verify one photo should be present (in the root Photos special folder)
Collection<PhotoModel> actualPhotos = result.getExportedData().getPhotos();
assertThat(actualPhotos.stream().map(PhotoModel::getFetchableUrl).collect(Collectors.toList())).containsExactly(IMAGE_URI);
assertThat(actualPhotos.stream().map(PhotoModel::getAlbumId).collect(Collectors.toList())).containsExactly(null);
assertThat(actualPhotos.stream().map(PhotoModel::getTitle).collect(Collectors.toList())).containsExactly(FILENAME);
// Verify there is one container ready for sub-processing
List<ContainerResource> actualResources = continuationData.getContainerResources();
assertThat(actualResources.stream().map(a -> ((IdOnlyContainerResource) a).getId()).collect(Collectors.toList())).containsExactly(FOLDER_ID);
}
Aggregations