Search in sources :

Example 31 with ContinuationData

use of org.datatransferproject.spi.transfer.types.ContinuationData in project data-transfer-project by google.

the class PortabilityInMemoryDataCopierTest method continuationDataWithPaginationDataAndNestedSubResource.

@Test
public void continuationDataWithPaginationDataAndNestedSubResource() throws CopyException, IOException {
    // Arrange
    PaginationData paginationData = Mockito.mock(PaginationData.class);
    ContinuationData paginationContinuationData = Mockito.mock(ContinuationData.class);
    ExportResult<?> paginationExportResult = Mockito.mock(ExportResult.class);
    ContainerResource subResource = Mockito.mock(ContainerResource.class);
    ContainerResource paginationSubResource = Mockito.mock(ContainerResource.class);
    ExportInformation paginationExportInfo = new ExportInformation(paginationData, null);
    ExportInformation subResourceExportInfo = new ExportInformation(null, subResource);
    ExportInformation paginationSubResourceExportInfo = new ExportInformation(null, paginationSubResource);
    Mockito.when(continuationData.getPaginationData()).thenReturn(paginationData);
    Mockito.when(continuationData.getContainerResources()).thenReturn(Arrays.asList(subResource));
    Mockito.when(paginationContinuationData.getContainerResources()).thenReturn(Arrays.asList(paginationSubResource));
    Mockito.when(initialExportResult.getContinuationData()).thenReturn(continuationData);
    Mockito.when(paginationExportResult.getContinuationData()).thenReturn(paginationContinuationData);
    Mockito.doReturn(initialExportResult).when(inMemoryDataCopier).copyIteration(jobId, exportAuthData, importAuthData, Optional.of(exportInfo), jobIdPrefix, 1);
    Mockito.doReturn(paginationExportResult).when(inMemoryDataCopier).copyIteration(jobId, exportAuthData, importAuthData, Optional.of(paginationExportInfo), jobIdPrefix, 2);
    // Act
    inMemoryDataCopier.copy(exportAuthData, importAuthData, jobId, Optional.of(exportInfo));
    // Assert
    InOrder orderVerifier = Mockito.inOrder(inMemoryDataCopier);
    orderVerifier.verify(inMemoryDataCopier).copyIteration(jobId, exportAuthData, importAuthData, Optional.of(exportInfo), jobIdPrefix, 1);
    orderVerifier.verify(inMemoryDataCopier).copyIteration(jobId, exportAuthData, importAuthData, Optional.of(paginationExportInfo), jobIdPrefix, 2);
    orderVerifier.verify(inMemoryDataCopier).copyIteration(jobId, exportAuthData, importAuthData, Optional.of(paginationSubResourceExportInfo), jobIdPrefix, 3);
    orderVerifier.verify(inMemoryDataCopier).copyIteration(jobId, exportAuthData, importAuthData, Optional.of(subResourceExportInfo), jobIdPrefix, 4);
}
Also used : ExportInformation(org.datatransferproject.types.common.ExportInformation) PaginationData(org.datatransferproject.types.common.PaginationData) InOrder(org.mockito.InOrder) ContainerResource(org.datatransferproject.types.common.models.ContainerResource) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) Test(org.junit.Test)

Example 32 with ContinuationData

use of org.datatransferproject.spi.transfer.types.ContinuationData in project data-transfer-project by google.

the class GoogleVideosExporter method exportVideos.

@VisibleForTesting
ExportResult<VideosContainerResource> exportVideos(TokensAndUrlAuthData authData, Optional<StringPaginationToken> paginationData) throws IOException {
    Optional<String> paginationToken = paginationData.map(StringPaginationToken::getToken);
    MediaItemSearchResponse mediaItemSearchResponse = getOrCreateVideosInterface(authData).listVideoItems(paginationToken);
    PaginationData nextPageData = null;
    if (!Strings.isNullOrEmpty(mediaItemSearchResponse.getNextPageToken())) {
        nextPageData = new StringPaginationToken(mediaItemSearchResponse.getNextPageToken());
    }
    ContinuationData continuationData = new ContinuationData(nextPageData);
    VideosContainerResource containerResource = null;
    GoogleMediaItem[] mediaItems = mediaItemSearchResponse.getMediaItems();
    if (mediaItems != null && mediaItems.length > 0) {
        List<VideoModel> videos = convertVideosList(mediaItems);
        containerResource = new VideosContainerResource(null, videos);
    }
    ResultType resultType = ResultType.CONTINUE;
    if (nextPageData == null) {
        resultType = ResultType.END;
    }
    return new ExportResult<>(resultType, containerResource, continuationData);
}
Also used : PaginationData(org.datatransferproject.types.common.PaginationData) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) ResultType(org.datatransferproject.spi.transfer.provider.ExportResult.ResultType) VideoModel(org.datatransferproject.types.common.models.videos.VideoModel) MediaItemSearchResponse(org.datatransferproject.datatransfer.google.mediaModels.MediaItemSearchResponse) VideosContainerResource(org.datatransferproject.types.common.models.videos.VideosContainerResource) GoogleMediaItem(org.datatransferproject.datatransfer.google.mediaModels.GoogleMediaItem) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 33 with ContinuationData

use of org.datatransferproject.spi.transfer.types.ContinuationData in project data-transfer-project by google.

the class GoogleMailExporterTest method exportMessagesFirstSet.

@Test
public void exportMessagesFirstSet() throws IOException {
    setUpSingleMessageResponse();
    // Looking at first page, with at least one page after it
    messageListResponse.setNextPageToken(NEXT_TOKEN);
    // Run test
    ExportResult<MailContainerResource> result = googleMailExporter.export(JOB_ID, null, Optional.empty());
    // Check results
    // Verify correct methods were called
    InOrder inOrder = Mockito.inOrder(messages, messageListRequest, get);
    // First request
    inOrder.verify(messages).list(GoogleMailExporter.USER);
    inOrder.verify(messageListRequest).setMaxResults(GoogleMailExporter.PAGE_SIZE);
    verify(messageListRequest, never()).setPageToken(anyString());
    // Second request
    inOrder.verify(messages).get(GoogleMailExporter.USER, MESSAGE_ID);
    inOrder.verify(get).setFormat("raw");
    inOrder.verify(get).execute();
    // Check pagination token
    ContinuationData continuationData = (ContinuationData) result.getContinuationData();
    StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
    assertThat(paginationToken.getToken()).isEqualTo(NEXT_TOKEN);
    // Check messages
    Collection<MailMessageModel> actualMail = result.getExportedData().getMessages();
    assertThat(actualMail.stream().map(MailMessageModel::getRawString).collect(Collectors.toList())).containsExactly(MESSAGE_RAW);
    assertThat(actualMail.stream().map(MailMessageModel::getContainerIds).collect(Collectors.toList())).containsExactly(MESSAGE_LABELS);
}
Also used : InOrder(org.mockito.InOrder) MailContainerResource(org.datatransferproject.types.common.models.mail.MailContainerResource) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) MailMessageModel(org.datatransferproject.types.common.models.mail.MailMessageModel) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) Test(org.junit.Test)

Example 34 with ContinuationData

use of org.datatransferproject.spi.transfer.types.ContinuationData in project data-transfer-project by google.

the class GooglePhotosExporterTest method exportPhotoSubsequentSet.

@Test
public void exportPhotoSubsequentSet() throws IOException, InvalidTokenException, PermissionDeniedException {
    setUpSingleAlbum();
    when(albumListResponse.getNextPageToken()).thenReturn(null);
    GoogleMediaItem mediaItem = setUpSinglePhoto(IMG_URI, PHOTO_ID);
    when(mediaItemSearchResponse.getMediaItems()).thenReturn(new GoogleMediaItem[] { mediaItem });
    when(mediaItemSearchResponse.getNextPageToken()).thenReturn(null);
    StringPaginationToken inputPaginationToken = new StringPaginationToken(PHOTO_TOKEN_PREFIX + PHOTO_TOKEN);
    IdOnlyContainerResource idOnlyContainerResource = new IdOnlyContainerResource(ALBUM_ID);
    // Run test
    ExportResult<PhotosContainerResource> result = googlePhotosExporter.exportPhotos(null, Optional.of(idOnlyContainerResource), Optional.of(inputPaginationToken), uuid);
    // Check results
    // Verify correct methods were called
    verify(photosInterface).listMediaItems(Optional.of(ALBUM_ID), Optional.of(PHOTO_TOKEN));
    verify(mediaItemSearchResponse).getMediaItems();
    // Check pagination token
    ContinuationData continuationData = result.getContinuationData();
    PaginationData paginationToken = continuationData.getPaginationData();
    assertNull(paginationToken);
}
Also used : PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) PaginationData(org.datatransferproject.types.common.PaginationData) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) GoogleMediaItem(org.datatransferproject.datatransfer.google.mediaModels.GoogleMediaItem) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) Test(org.junit.Test)

Example 35 with ContinuationData

use of org.datatransferproject.spi.transfer.types.ContinuationData in project data-transfer-project by google.

the class GooglePhotosExporterTest method exportAlbumSubsequentSet.

@Test
public void exportAlbumSubsequentSet() throws IOException, InvalidTokenException, PermissionDeniedException {
    setUpSingleAlbum();
    when(albumListResponse.getNextPageToken()).thenReturn(null);
    StringPaginationToken inputPaginationToken = new StringPaginationToken(ALBUM_TOKEN_PREFIX + ALBUM_TOKEN);
    // Run test
    ExportResult<PhotosContainerResource> result = googlePhotosExporter.exportAlbums(null, Optional.of(inputPaginationToken), uuid);
    // Check results
    // Verify correct methods were called
    verify(photosInterface).listAlbums(Optional.of(ALBUM_TOKEN));
    verify(albumListResponse).getAlbums();
    // Check pagination token - should be absent
    ContinuationData continuationData = result.getContinuationData();
    StringPaginationToken paginationData = (StringPaginationToken) continuationData.getPaginationData();
    assertThat(paginationData.getToken()).isEqualTo(GooglePhotosExporter.PHOTO_TOKEN_PREFIX);
}
Also used : PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) Test(org.junit.Test)

Aggregations

ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)51 StringPaginationToken (org.datatransferproject.types.common.StringPaginationToken)36 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)33 IdOnlyContainerResource (org.datatransferproject.types.common.models.IdOnlyContainerResource)27 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)27 PaginationData (org.datatransferproject.types.common.PaginationData)25 ArrayList (java.util.ArrayList)22 Test (org.junit.Test)21 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)19 PhotoModel (org.datatransferproject.types.common.models.photos.PhotoModel)17 IOException (java.io.IOException)16 ResultType (org.datatransferproject.spi.transfer.provider.ExportResult.ResultType)14 ExportInformation (org.datatransferproject.types.common.ExportInformation)13 ContainerResource (org.datatransferproject.types.common.models.ContainerResource)12 List (java.util.List)9 Optional (java.util.Optional)8 UUID (java.util.UUID)8 Collectors (java.util.stream.Collectors)8 InOrder (org.mockito.InOrder)8 VisibleForTesting (com.google.common.annotations.VisibleForTesting)7