Search in sources :

Example 16 with PaginationData

use of org.datatransferproject.types.common.PaginationData 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 17 with PaginationData

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

the class ImgurPhotosExporter method requestAlbums.

/**
 * Exports albums.
 *
 * @param authData authentication information
 * @param paginationData pagination information to use for subsequent calls
 */
private ExportResult<PhotosContainerResource> requestAlbums(TokensAndUrlAuthData authData, PaginationData paginationData) throws IOException {
    ImmutableList.Builder<PhotoAlbum> albumBuilder = ImmutableList.builder();
    List<IdOnlyContainerResource> albumIds = new ArrayList<>();
    int page = paginationData == null ? 0 : ((IntPaginationToken) paginationData).getStart();
    String url = format(ALBUMS_URL_TEMPLATE, page);
    List<Map<String, Object>> items = requestData(authData, url);
    // Request result doesn't indicate if it's the last page
    boolean hasMore = (items != null && items.size() != 0);
    for (Map<String, Object> item : items) {
        albumBuilder.add(new PhotoAlbum((String) item.get("id"), (String) item.get("title"), (String) item.get("description")));
        // Save album id for recalling export to get all the photos in albums
        albumIds.add(new IdOnlyContainerResource((String) item.get("id")));
    }
    if (page == 0) {
        // For checking non-album photos. Their export should be performed after all the others
        // Album will be created later
        albumIds.add(new IdOnlyContainerResource(DEFAULT_ALBUM_ID));
    }
    PaginationData newPage = null;
    if (hasMore) {
        newPage = new IntPaginationToken(page + 1);
        int start = ((IntPaginationToken) newPage).getStart();
        monitor.info(() -> format("albums size: %s, newPage: %s", items.size(), start));
    }
    PhotosContainerResource photosContainerResource = new PhotosContainerResource(albumBuilder.build(), null);
    ContinuationData continuationData = new ContinuationData(newPage);
    albumIds.forEach(continuationData::addContainerResource);
    ExportResult.ResultType resultType = ExportResult.ResultType.CONTINUE;
    if (newPage == null) {
        resultType = ExportResult.ResultType.END;
    }
    return new ExportResult<>(resultType, photosContainerResource, continuationData);
}
Also used : IntPaginationToken(org.datatransferproject.types.common.IntPaginationToken) PaginationData(org.datatransferproject.types.common.PaginationData) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) Map(java.util.Map) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult)

Example 18 with PaginationData

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

the class PortabilityInMemoryDataCopierTest method continuationDataWithPaginationData.

@Test
public void continuationDataWithPaginationData() throws CopyException, IOException {
    // Arrange
    PaginationData paginationData = Mockito.mock(PaginationData.class);
    ExportInformation paginationExportInfo = new ExportInformation(paginationData, null);
    Mockito.when(continuationData.getPaginationData()).thenReturn(paginationData);
    Mockito.when(initialExportResult.getContinuationData()).thenReturn(continuationData);
    Mockito.doReturn(initialExportResult).when(inMemoryDataCopier).copyIteration(jobId, exportAuthData, importAuthData, Optional.of(exportInfo), jobIdPrefix, 1);
    // 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);
}
Also used : ExportInformation(org.datatransferproject.types.common.ExportInformation) PaginationData(org.datatransferproject.types.common.PaginationData) InOrder(org.mockito.InOrder) Test(org.junit.Test)

Example 19 with PaginationData

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

the class PortabilityInMemoryDataCopierTest method storeStackContainingPaginationDataAndMultipleSubResourcesInJobStore.

@Test
public void storeStackContainingPaginationDataAndMultipleSubResourcesInJobStore() throws CopyException, IOException {
    // Arrange
    PaginationData paginationData = Mockito.mock(PaginationData.class);
    ContainerResource subResource1 = Mockito.mock(ContainerResource.class);
    ContainerResource subResource2 = Mockito.mock(ContainerResource.class);
    ExportInformation paginationExportInfo = new ExportInformation(paginationData, null);
    ExportInformation subResource1ExportInfo = new ExportInformation(null, subResource1);
    ExportInformation subResource2ExportInfo = new ExportInformation(null, subResource2);
    Stack<ExportInformation> jobStack = new Stack<>();
    jobStack.push(subResource2ExportInfo);
    jobStack.push(subResource1ExportInfo);
    jobStack.push(paginationExportInfo);
    Mockito.when(continuationData.getPaginationData()).thenReturn(paginationData);
    Mockito.when(continuationData.getContainerResources()).thenReturn(Arrays.asList(subResource1, subResource2));
    Mockito.when(initialExportResult.getContinuationData()).thenReturn(continuationData);
    Mockito.doReturn(initialExportResult).when(stackInMemoryDataCopier).copyIteration(jobId, exportAuthData, importAuthData, Optional.of(exportInfo), jobIdPrefix, 1);
    // Act
    stackInMemoryDataCopier.copy(exportAuthData, importAuthData, jobId, Optional.of(exportInfo));
    // Assert
    InOrder orderVerifier = Mockito.inOrder(stackInMemoryDataCopier.jobStore);
    orderVerifier.verify(stackInMemoryDataCopier.jobStore).storeJobStack(jobId, jobStack);
    jobStack.pop();
    orderVerifier.verify(stackInMemoryDataCopier.jobStore).storeJobStack(jobId, jobStack);
    jobStack.pop();
    orderVerifier.verify(stackInMemoryDataCopier.jobStore).storeJobStack(jobId, jobStack);
    jobStack.pop();
    orderVerifier.verify(stackInMemoryDataCopier.jobStore).storeJobStack(jobId, jobStack);
}
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) Stack(java.util.Stack) Test(org.junit.Test)

Example 20 with PaginationData

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

Aggregations

PaginationData (org.datatransferproject.types.common.PaginationData)30 ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)23 StringPaginationToken (org.datatransferproject.types.common.StringPaginationToken)18 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)17 IdOnlyContainerResource (org.datatransferproject.types.common.models.IdOnlyContainerResource)15 ArrayList (java.util.ArrayList)12 ResultType (org.datatransferproject.spi.transfer.provider.ExportResult.ResultType)11 ExportInformation (org.datatransferproject.types.common.ExportInformation)11 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)11 Test (org.junit.Test)9 InOrder (org.mockito.InOrder)8 VisibleForTesting (com.google.common.annotations.VisibleForTesting)7 IOException (java.io.IOException)7 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)7 ImmutableList (com.google.common.collect.ImmutableList)5 PhotoModel (org.datatransferproject.types.common.models.photos.PhotoModel)5 IntPaginationToken (org.datatransferproject.types.common.IntPaginationToken)4 ContainerResource (org.datatransferproject.types.common.models.ContainerResource)4 CalendarContainerResource (org.datatransferproject.types.common.models.calendar.CalendarContainerResource)4 FlickrException (com.flickr4java.flickr.FlickrException)3