Search in sources :

Example 11 with ExportInformation

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

the class FacebookPhotosExporterTest method testSpecifiedAlbums.

@Test
public void testSpecifiedAlbums() throws CopyExceptionWithFailureReason {
    ExportResult<PhotosContainerResource> result = facebookPhotosExporter.export(uuid, new TokensAndUrlAuthData("accessToken", null, null), Optional.of(new ExportInformation(new StringPaginationToken(PHOTO_TOKEN_PREFIX), new PhotosContainerResource(Lists.newArrayList(new PhotoAlbum(ALBUM_ID, ALBUM_NAME, ALBUM_DESCRIPTION)), new ArrayList<>()))));
    assertEquals(ExportResult.ResultType.CONTINUE, result.getType());
    PhotosContainerResource exportedData = result.getExportedData();
    assertEquals(1, exportedData.getAlbums().size());
    assertEquals(new PhotoAlbum(ALBUM_ID, ALBUM_NAME, ALBUM_DESCRIPTION), exportedData.getAlbums().toArray()[0]);
    assertNull((result.getContinuationData().getPaginationData()));
    assertThat(result.getContinuationData().getContainerResources()).contains(new IdOnlyContainerResource(ALBUM_ID));
}
Also used : PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) ExportInformation(org.datatransferproject.types.common.ExportInformation) TokensAndUrlAuthData(org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData) ArrayList(java.util.ArrayList) 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 12 with ExportInformation

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

the class GoogleMailExporterTest method exportMessagesSubsequentSet.

@Test
public void exportMessagesSubsequentSet() throws IOException {
    setUpSingleMessageResponse();
    // Looking at subsequent page, with no page after it
    PaginationData paginationData = new StringPaginationToken(NEXT_TOKEN);
    ExportInformation exportInformation = new ExportInformation(paginationData, null);
    messageListResponse.setNextPageToken(null);
    // Run test
    ExportResult<MailContainerResource> result = googleMailExporter.export(JOB_ID, null, Optional.of(exportInformation));
    // Check results
    // Verify correct calls were made (i.e., token was set before execution)
    InOrder inOrder = Mockito.inOrder(messageListRequest);
    inOrder.verify(messageListRequest).setPageToken(NEXT_TOKEN);
    inOrder.verify(messageListRequest).execute();
    // Check pagination token (should be null)
    ContinuationData continuationData = (ContinuationData) result.getContinuationData();
    StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
    assertThat(paginationToken).isNull();
}
Also used : ExportInformation(org.datatransferproject.types.common.ExportInformation) PaginationData(org.datatransferproject.types.common.PaginationData) InOrder(org.mockito.InOrder) MailContainerResource(org.datatransferproject.types.common.models.mail.MailContainerResource) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) Test(org.junit.Test)

Example 13 with ExportInformation

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

the class ImgurPhotoExporterTest method testNonAlbumPhotoExport.

@Test
public void testNonAlbumPhotoExport() throws Exception {
    // all photos are non-album
    server.enqueue(new MockResponse().setBody(allImagesResponse));
    ExportResult<PhotosContainerResource> nonAlbumPhotosResult = exporter.export(UUID.randomUUID(), token, Optional.of(new ExportInformation(null, new IdOnlyContainerResource(ImgurPhotosExporter.DEFAULT_ALBUM_ID))));
    PhotosContainerResource resource = nonAlbumPhotosResult.getExportedData();
    assertEquals(3, resource.getPhotos().size());
}
Also used : MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) ExportInformation(org.datatransferproject.types.common.ExportInformation) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) Test(org.junit.Test)

Example 14 with ExportInformation

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

the class ImgurPhotoExporterTest method testAlbumAndNonAlbumPhotoExport.

@Test
public void testAlbumAndNonAlbumPhotoExport() throws Exception {
    server.enqueue(new MockResponse().setBody(albumsResponse));
    server.enqueue(new MockResponse().setBody(album1ImagesResponse));
    server.enqueue(new MockResponse().setBody(allImagesResponse));
    // export albums
    exporter.export(UUID.randomUUID(), token, Optional.empty());
    // export album photos
    ExportResult<PhotosContainerResource> albumPhotosResult = exporter.export(UUID.randomUUID(), token, Optional.of(new ExportInformation(null, new IdOnlyContainerResource("albumId1"))));
    assertEquals(2, albumPhotosResult.getExportedData().getPhotos().size());
    // export non-album photos
    ExportResult<PhotosContainerResource> nonAlbumPhotosResult = exporter.export(UUID.randomUUID(), token, Optional.of(new ExportInformation(null, new IdOnlyContainerResource(ImgurPhotosExporter.DEFAULT_ALBUM_ID))));
    PhotosContainerResource resource = nonAlbumPhotosResult.getExportedData();
    assertThat(resource.getPhotos()).containsExactly(NON_ALBUM_PHOTO);
}
Also used : MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) ExportInformation(org.datatransferproject.types.common.ExportInformation) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) Test(org.junit.Test)

Example 15 with ExportInformation

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

Aggregations

ExportInformation (org.datatransferproject.types.common.ExportInformation)26 Test (org.junit.Test)20 ContainerResource (org.datatransferproject.types.common.models.ContainerResource)10 InOrder (org.mockito.InOrder)10 ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)9 IdOnlyContainerResource (org.datatransferproject.types.common.models.IdOnlyContainerResource)9 PaginationData (org.datatransferproject.types.common.PaginationData)8 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)8 StringPaginationToken (org.datatransferproject.types.common.StringPaginationToken)7 MockResponse (com.squareup.okhttp.mockwebserver.MockResponse)4 CalendarContainerResource (org.datatransferproject.types.common.models.calendar.CalendarContainerResource)3 TokensAndUrlAuthData (org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Stack (java.util.Stack)2 UUID (java.util.UUID)2 PortabilityJob (org.datatransferproject.spi.cloud.types.PortabilityJob)2 IntPaginationToken (org.datatransferproject.types.common.IntPaginationToken)2 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1