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