use of org.datatransferproject.types.common.models.ContainerResource in project data-transfer-project by google.
the class MicrosoftPhotosExporterTest method exportAlbumWithoutNextPage.
@Test
public void exportAlbumWithoutNextPage() throws IOException {
// Setup
MicrosoftDriveItem folderItem = setUpSingleAlbum();
when(driveItemsResponse.getDriveItems()).thenReturn(new MicrosoftDriveItem[] { folderItem });
when(driveItemsResponse.getNextPageLink()).thenReturn(null);
StringPaginationToken inputPaginationToken = new StringPaginationToken(DRIVE_TOKEN_PREFIX + DRIVE_PAGE_URL);
// Run
ExportResult<PhotosContainerResource> result = microsoftPhotosExporter.exportOneDrivePhotos(null, Optional.empty(), Optional.of(inputPaginationToken), uuid);
// Verify method calls
verify(photosInterface).getDriveItems(Optional.empty(), Optional.of(DRIVE_PAGE_URL));
verify(driveItemsResponse).getDriveItems();
// Verify next pagination token is absent
ContinuationData continuationData = result.getContinuationData();
StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
assertThat(paginationToken).isEqualTo(null);
// Verify one album is ready for import
Collection<PhotoAlbum> actualAlbums = result.getExportedData().getAlbums();
assertThat(actualAlbums.stream().map(PhotoAlbum::getId).collect(Collectors.toList())).containsExactly(FOLDER_ID);
// Verify photos should be empty (in the root)
Collection<PhotoModel> actualPhotos = result.getExportedData().getPhotos();
assertThat(actualPhotos).isEmpty();
// Verify there is one container ready for sub-processing
List<ContainerResource> actualResources = continuationData.getContainerResources();
assertThat(actualResources.stream().map(a -> ((IdOnlyContainerResource) a).getId()).collect(Collectors.toList())).containsExactly(FOLDER_ID);
}
use of org.datatransferproject.types.common.models.ContainerResource in project data-transfer-project by google.
the class MicrosoftPhotosExporterTest method exportPhotoWithoutNextPage.
@Test
public void exportPhotoWithoutNextPage() throws IOException {
// Setup
when(driveItemsResponse.getNextPageLink()).thenReturn(null);
MicrosoftDriveItem photoItem = setUpSinglePhoto(IMAGE_URI, PHOTO_ID);
when(driveItemsResponse.getDriveItems()).thenReturn(new MicrosoftDriveItem[] { photoItem });
when(driveItemsResponse.getNextPageLink()).thenReturn(null);
StringPaginationToken inputPaginationToken = new StringPaginationToken(DRIVE_TOKEN_PREFIX + DRIVE_PAGE_URL);
IdOnlyContainerResource idOnlyContainerResource = new IdOnlyContainerResource(FOLDER_ID);
// Run
ExportResult<PhotosContainerResource> result = microsoftPhotosExporter.exportOneDrivePhotos(null, Optional.of(idOnlyContainerResource), Optional.of(inputPaginationToken), uuid);
// Verify method calls
verify(photosInterface).getDriveItems(Optional.of(FOLDER_ID), Optional.of(DRIVE_PAGE_URL));
verify(driveItemsResponse).getDriveItems();
// Verify next pagination token is absent
ContinuationData continuationData = result.getContinuationData();
StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
assertThat(paginationToken).isEqualTo(null);
// Verify no albums are exported
Collection<PhotoAlbum> actualAlbums = result.getExportedData().getAlbums();
assertThat(actualAlbums).isEmpty();
// Verify one photo (in an album) should be exported
Collection<PhotoModel> actualPhotos = result.getExportedData().getPhotos();
assertThat(actualPhotos.stream().map(PhotoModel::getFetchableUrl).collect(Collectors.toList())).containsExactly(IMAGE_URI);
assertThat(actualPhotos.stream().map(PhotoModel::getAlbumId).collect(Collectors.toList())).containsExactly(FOLDER_ID);
assertThat(actualPhotos.stream().map(PhotoModel::getTitle).collect(Collectors.toList())).containsExactly(FILENAME);
// Verify there are no containers ready for sub-processing
List<ContainerResource> actualResources = continuationData.getContainerResources();
assertThat(actualResources).isEmpty();
}
use of org.datatransferproject.types.common.models.ContainerResource in project data-transfer-project by google.
the class PortabilityInMemoryDataCopierTest method continuationDataWithMultipleSubResources.
@Test
public void continuationDataWithMultipleSubResources() throws CopyException, IOException {
// Arrange
ContainerResource subResource1 = Mockito.mock(ContainerResource.class);
ContainerResource subResource2 = Mockito.mock(ContainerResource.class);
ExportInformation subResource1ExportInfo = new ExportInformation(null, subResource1);
ExportInformation subResource2ExportInfo = new ExportInformation(null, subResource2);
Mockito.when(continuationData.getContainerResources()).thenReturn(Arrays.asList(subResource1, subResource2));
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(subResource1ExportInfo), jobIdPrefix, 2);
orderVerifier.verify(inMemoryDataCopier).copyIteration(jobId, exportAuthData, importAuthData, Optional.of(subResource2ExportInfo), jobIdPrefix, 3);
}
use of org.datatransferproject.types.common.models.ContainerResource in project data-transfer-project by google.
the class PortabilityInMemoryDataCopierTest method continuationDataWithPaginationDataAndMultipleSubResources.
@Test
public void continuationDataWithPaginationDataAndMultipleSubResources() 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);
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(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);
orderVerifier.verify(inMemoryDataCopier).copyIteration(jobId, exportAuthData, importAuthData, Optional.of(subResource1ExportInfo), jobIdPrefix, 3);
orderVerifier.verify(inMemoryDataCopier).copyIteration(jobId, exportAuthData, importAuthData, Optional.of(subResource2ExportInfo), jobIdPrefix, 4);
}
use of org.datatransferproject.types.common.models.ContainerResource in project data-transfer-project by google.
the class PortabilityInMemoryDataCopier method copyHelper.
/**
* Transfers data from the given {@code exporter} optionally starting at the point specified in
* the provided {@code exportInfo}. Imports the data using the provided {@code importer}. If there
* is more data to required to be exported, recursively copies using the specific {@link
* ExportInformation} to continue the process.
*
* @param exportAuthData The auth data for the export
* @param importAuthData The auth data for the import
* @param exportInfo Any pagination or resource information to use for subsequent calls.
*/
private Collection<ErrorDetail> copyHelper(AuthData exportAuthData, AuthData importAuthData, UUID jobId, Optional<ExportInformation> exportInfo) throws CopyException {
String jobIdPrefix = "Job " + jobId + ": ";
final int copyIteration = COPY_ITERATION_COUNTER.incrementAndGet();
// NOTE: order is important below, do the import of all the items, then do continuation
// then do sub resources, this ensures all parents are populated before children get
// processed.
ExportResult<?> exportResult = copyIteration(jobId, exportAuthData, importAuthData, exportInfo, jobIdPrefix, copyIteration);
// Import and Export were successful, determine what to do next
ContinuationData continuationData = exportResult.getContinuationData();
if (null != continuationData) {
// Process the next page of items for the resource
if (null != continuationData.getPaginationData()) {
monitor.debug(() -> jobIdPrefix + "Starting off a new copy iteration with pagination info, copy iteration: " + copyIteration);
copyHelper(exportAuthData, importAuthData, jobId, Optional.of(new ExportInformation(continuationData.getPaginationData(), exportInfo.isPresent() ? exportInfo.get().getContainerResource() : null)));
}
// Start processing sub-resources
if (continuationData.getContainerResources() != null && !continuationData.getContainerResources().isEmpty()) {
for (ContainerResource resource : continuationData.getContainerResources()) {
monitor.debug(() -> jobIdPrefix + "Starting off a new copy iteration with a new container resource, copy iteration: " + copyIteration);
copyHelper(exportAuthData, importAuthData, jobId, Optional.of(new ExportInformation(null, resource)));
}
}
}
return idempotentImportExecutor.getErrors();
}
Aggregations