Search in sources :

Example 16 with ContainerResource

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);
}
Also used : ContainerResource(org.datatransferproject.types.common.models.ContainerResource) MailContainerResource(org.datatransferproject.types.common.models.mail.MailContainerResource) MailContainerModel(org.datatransferproject.types.common.models.mail.MailContainerModel) MailContainerResource(org.datatransferproject.types.common.models.mail.MailContainerResource) MailMessageModel(org.datatransferproject.types.common.models.mail.MailMessageModel) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 17 with ContainerResource

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());
}
Also used : Truth(com.google.common.truth.Truth) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) ImmutableList(com.google.common.collect.ImmutableList) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ContainerResource(org.datatransferproject.types.common.models.ContainerResource) Test(org.junit.Test) ZoneOffset(java.time.ZoneOffset) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) Instant(java.time.Instant) ContainerResource(org.datatransferproject.types.common.models.ContainerResource) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 18 with ContainerResource

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);
}
Also used : ContainerResource(org.datatransferproject.types.common.models.ContainerResource) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 19 with ContainerResource

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);
}
Also used : TaskContainerResource(org.datatransferproject.types.common.models.tasks.TaskContainerResource) ContainerResource(org.datatransferproject.types.common.models.ContainerResource) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) TaskContainerResource(org.datatransferproject.types.common.models.tasks.TaskContainerResource) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TaskListModel(org.datatransferproject.types.common.models.tasks.TaskListModel) TaskModel(org.datatransferproject.types.common.models.tasks.TaskModel) Test(org.junit.Test)

Example 20 with ContainerResource

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);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) Matchers(org.mockito.Matchers) PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) PhotoModel(org.datatransferproject.types.common.models.photos.PhotoModel) Before(org.junit.Before) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory) Collection(java.util.Collection) IOException(java.io.IOException) ContainerResource(org.datatransferproject.types.common.models.ContainerResource) Test(org.junit.Test) UUID(java.util.UUID) Truth.assertThat(com.google.common.truth.Truth.assertThat) Collectors(java.util.stream.Collectors) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) Mockito(org.mockito.Mockito) List(java.util.List) Monitor(org.datatransferproject.api.launcher.Monitor) TokensAndUrlAuthData(org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData) DRIVE_TOKEN_PREFIX(org.datatransferproject.transfer.microsoft.photos.MicrosoftPhotosExporter.DRIVE_TOKEN_PREFIX) Optional(java.util.Optional) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) MicrosoftCredentialFactory(org.datatransferproject.transfer.microsoft.common.MicrosoftCredentialFactory) org.datatransferproject.transfer.microsoft.driveModels(org.datatransferproject.transfer.microsoft.driveModels) PhotoModel(org.datatransferproject.types.common.models.photos.PhotoModel) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) ContainerResource(org.datatransferproject.types.common.models.ContainerResource) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) Test(org.junit.Test)

Aggregations

ContainerResource (org.datatransferproject.types.common.models.ContainerResource)24 Test (org.junit.Test)20 ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)12 ExportInformation (org.datatransferproject.types.common.ExportInformation)11 StringPaginationToken (org.datatransferproject.types.common.StringPaginationToken)10 IdOnlyContainerResource (org.datatransferproject.types.common.models.IdOnlyContainerResource)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)7 InOrder (org.mockito.InOrder)7 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 PaginationData (org.datatransferproject.types.common.PaginationData)6 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)6 Truth.assertThat (com.google.common.truth.Truth.assertThat)5 IOException (java.io.IOException)5 Collection (java.util.Collection)5 Optional (java.util.Optional)5 UUID (java.util.UUID)5 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)5 PhotoModel (org.datatransferproject.types.common.models.photos.PhotoModel)5