Search in sources :

Example 26 with IdOnlyContainerResource

use of org.datatransferproject.types.common.models.IdOnlyContainerResource in project data-transfer-project by google.

the class ImgurPhotoExporterTest method testPagination.

@Test
public void testPagination() throws Exception {
    server.enqueue(new MockResponse().setBody(page1Response));
    server.enqueue(new MockResponse().setBody(page2Response));
    int page = 0;
    ExportResult<PhotosContainerResource> page1Result = exporter.export(UUID.randomUUID(), token, Optional.of(new ExportInformation(new IntPaginationToken(page), new IdOnlyContainerResource(ImgurPhotosExporter.DEFAULT_ALBUM_ID))));
    page++;
    PhotosContainerResource page1Resource = page1Result.getExportedData();
    // 1th request returns 10 photos
    assertEquals(10, page1Resource.getPhotos().size());
    assertEquals(page, ((IntPaginationToken) page1Result.getContinuationData().getPaginationData()).getStart());
    ExportResult<PhotosContainerResource> page2Result = exporter.export(UUID.randomUUID(), token, Optional.of(new ExportInformation(new IntPaginationToken(page), new IdOnlyContainerResource(ImgurPhotosExporter.DEFAULT_ALBUM_ID))));
    page++;
    PhotosContainerResource page2Resource = page2Result.getExportedData();
    // 2th request returns 2 photos
    assertEquals(2, page2Resource.getPhotos().size());
    assertEquals(page, ((IntPaginationToken) page2Result.getContinuationData().getPaginationData()).getStart());
}
Also used : MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) ExportInformation(org.datatransferproject.types.common.ExportInformation) IntPaginationToken(org.datatransferproject.types.common.IntPaginationToken) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) Test(org.junit.Test)

Example 27 with IdOnlyContainerResource

use of org.datatransferproject.types.common.models.IdOnlyContainerResource 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)

Example 28 with IdOnlyContainerResource

use of org.datatransferproject.types.common.models.IdOnlyContainerResource in project data-transfer-project by google.

the class MicrosoftPhotosExporter method export.

@Override
public ExportResult<PhotosContainerResource> export(UUID jobId, TokensAndUrlAuthData authData, Optional<ExportInformation> exportInformation) throws IOException {
    if (!exportInformation.isPresent()) {
        return exportOneDrivePhotos(authData, Optional.empty(), Optional.empty(), jobId);
    }
    IdOnlyContainerResource idOnlyContainerResource = (IdOnlyContainerResource) exportInformation.get().getContainerResource();
    StringPaginationToken paginationToken = (StringPaginationToken) exportInformation.get().getPaginationData();
    return exportOneDrivePhotos(authData, Optional.ofNullable(idOnlyContainerResource), Optional.ofNullable(paginationToken), jobId);
}
Also used : IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken)

Example 29 with IdOnlyContainerResource

use of org.datatransferproject.types.common.models.IdOnlyContainerResource in project data-transfer-project by google.

the class RememberTheMilkTasksExporter method export.

@Override
public ExportResult<TaskContainerResource> export(UUID jobId, AuthData authData, Optional<ExportInformation> exportInformation) {
    // Create new service for the authorized user
    RememberTheMilkService service = getOrCreateService(authData);
    IdOnlyContainerResource resource = exportInformation.isPresent() ? (IdOnlyContainerResource) exportInformation.get().getContainerResource() : null;
    if (resource != null) {
        return exportTask(service, resource);
    } else {
        return exportTaskList(service);
    }
}
Also used : IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource)

Example 30 with IdOnlyContainerResource

use of org.datatransferproject.types.common.models.IdOnlyContainerResource in project data-transfer-project by google.

the class ContinuationDataTest method verifySerializeDeserialize.

@Test
public void verifySerializeDeserialize() throws Exception {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.registerSubtypes(ContinuationData.class, IntPaginationToken.class, IdOnlyContainerResource.class);
    ContinuationData continuationData = new ContinuationData(new IntPaginationToken(100));
    continuationData.addContainerResource(new IdOnlyContainerResource("123"));
    String serialized = objectMapper.writeValueAsString(continuationData);
    ContinuationData deserialized = objectMapper.readValue(serialized, ContinuationData.class);
    Assert.assertNotNull(deserialized);
    Assert.assertEquals(100, ((IntPaginationToken) deserialized.getPaginationData()).getStart());
    Assert.assertEquals("123", ((IdOnlyContainerResource) deserialized.getContainerResources().get(0)).getId());
}
Also used : IntPaginationToken(org.datatransferproject.types.common.IntPaginationToken) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

IdOnlyContainerResource (org.datatransferproject.types.common.models.IdOnlyContainerResource)43 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)29 ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)27 StringPaginationToken (org.datatransferproject.types.common.StringPaginationToken)23 Test (org.junit.Test)21 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)20 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)18 PaginationData (org.datatransferproject.types.common.PaginationData)17 ArrayList (java.util.ArrayList)12 ExportInformation (org.datatransferproject.types.common.ExportInformation)12 PhotoModel (org.datatransferproject.types.common.models.photos.PhotoModel)12 IOException (java.io.IOException)11 ContainerResource (org.datatransferproject.types.common.models.ContainerResource)10 ImmutableList (com.google.common.collect.ImmutableList)7 List (java.util.List)7 Optional (java.util.Optional)7 UUID (java.util.UUID)7 Collectors (java.util.stream.Collectors)7 ResultType (org.datatransferproject.spi.transfer.provider.ExportResult.ResultType)7 IntPaginationToken (org.datatransferproject.types.common.IntPaginationToken)7