use of org.datatransferproject.types.common.models.IdOnlyContainerResource in project data-transfer-project by google.
the class ImgurPhotoExporterTest method testPagination.
@Test
public void testPagination() throws Exception {
server.enqueue(new MockResponse().setBody(page1Response));
server.enqueue(new MockResponse().setBody(page2Response));
int page = 0;
ExportResult<PhotosContainerResource> page1Result = exporter.export(UUID.randomUUID(), token, Optional.of(new ExportInformation(new IntPaginationToken(page), new IdOnlyContainerResource(ImgurPhotosExporter.DEFAULT_ALBUM_ID))));
page++;
PhotosContainerResource page1Resource = page1Result.getExportedData();
// 1th request returns 10 photos
assertEquals(10, page1Resource.getPhotos().size());
assertEquals(page, ((IntPaginationToken) page1Result.getContinuationData().getPaginationData()).getStart());
ExportResult<PhotosContainerResource> page2Result = exporter.export(UUID.randomUUID(), token, Optional.of(new ExportInformation(new IntPaginationToken(page), new IdOnlyContainerResource(ImgurPhotosExporter.DEFAULT_ALBUM_ID))));
page++;
PhotosContainerResource page2Resource = page2Result.getExportedData();
// 2th request returns 2 photos
assertEquals(2, page2Resource.getPhotos().size());
assertEquals(page, ((IntPaginationToken) page2Result.getContinuationData().getPaginationData()).getStart());
}
use of org.datatransferproject.types.common.models.IdOnlyContainerResource in project data-transfer-project by google.
the class MicrosoftPhotosExporterTest method exportAlbumAndPhotoWithNextPage.
@Test
public void exportAlbumAndPhotoWithNextPage() throws IOException {
// Setup
MicrosoftDriveItem folderItem = setUpSingleAlbum();
MicrosoftDriveItem photoItem = setUpSinglePhoto(IMAGE_URI, PHOTO_ID);
when(driveItemsResponse.getDriveItems()).thenReturn(new MicrosoftDriveItem[] { folderItem, photoItem });
when(driveItemsResponse.getNextPageLink()).thenReturn(DRIVE_PAGE_URL);
// Run
ExportResult<PhotosContainerResource> result = microsoftPhotosExporter.exportOneDrivePhotos(null, Optional.empty(), Optional.empty(), uuid);
// Verify method calls
verify(photosInterface).getDriveItemsFromSpecialFolder(MicrosoftSpecialFolder.FolderType.photos);
verify(driveItemsResponse).getDriveItems();
// Verify pagination token is set
ContinuationData continuationData = result.getContinuationData();
StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
assertThat(paginationToken.getToken()).isEqualTo(DRIVE_TOKEN_PREFIX + DRIVE_PAGE_URL);
// 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 one photo should be present (in the root Photos special folder)
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(null);
assertThat(actualPhotos.stream().map(PhotoModel::getTitle).collect(Collectors.toList())).containsExactly(FILENAME);
// 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.IdOnlyContainerResource in project data-transfer-project by google.
the class MicrosoftPhotosExporter method export.
@Override
public ExportResult<PhotosContainerResource> export(UUID jobId, TokensAndUrlAuthData authData, Optional<ExportInformation> exportInformation) throws IOException {
if (!exportInformation.isPresent()) {
return exportOneDrivePhotos(authData, Optional.empty(), Optional.empty(), jobId);
}
IdOnlyContainerResource idOnlyContainerResource = (IdOnlyContainerResource) exportInformation.get().getContainerResource();
StringPaginationToken paginationToken = (StringPaginationToken) exportInformation.get().getPaginationData();
return exportOneDrivePhotos(authData, Optional.ofNullable(idOnlyContainerResource), Optional.ofNullable(paginationToken), jobId);
}
use of org.datatransferproject.types.common.models.IdOnlyContainerResource in project data-transfer-project by google.
the class RememberTheMilkTasksExporter method export.
@Override
public ExportResult<TaskContainerResource> export(UUID jobId, AuthData authData, Optional<ExportInformation> exportInformation) {
// Create new service for the authorized user
RememberTheMilkService service = getOrCreateService(authData);
IdOnlyContainerResource resource = exportInformation.isPresent() ? (IdOnlyContainerResource) exportInformation.get().getContainerResource() : null;
if (resource != null) {
return exportTask(service, resource);
} else {
return exportTaskList(service);
}
}
use of org.datatransferproject.types.common.models.IdOnlyContainerResource in project data-transfer-project by google.
the class ContinuationDataTest method verifySerializeDeserialize.
@Test
public void verifySerializeDeserialize() throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerSubtypes(ContinuationData.class, IntPaginationToken.class, IdOnlyContainerResource.class);
ContinuationData continuationData = new ContinuationData(new IntPaginationToken(100));
continuationData.addContainerResource(new IdOnlyContainerResource("123"));
String serialized = objectMapper.writeValueAsString(continuationData);
ContinuationData deserialized = objectMapper.readValue(serialized, ContinuationData.class);
Assert.assertNotNull(deserialized);
Assert.assertEquals(100, ((IntPaginationToken) deserialized.getPaginationData()).getStart());
Assert.assertEquals("123", ((IdOnlyContainerResource) deserialized.getContainerResources().get(0)).getId());
}
Aggregations