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();
}
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);
}
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);
}
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);
}
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);
}
Aggregations