use of org.datatransferproject.types.common.models.IdOnlyContainerResource 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.types.common.models.IdOnlyContainerResource in project data-transfer-project by google.
the class GooglePhotosExporterTest method exportPhotoFirstSet.
@Test
public void exportPhotoFirstSet() 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(PHOTO_TOKEN);
IdOnlyContainerResource idOnlyContainerResource = new IdOnlyContainerResource(ALBUM_ID);
ExportResult<PhotosContainerResource> result = googlePhotosExporter.exportPhotos(null, Optional.of(idOnlyContainerResource), Optional.empty(), uuid);
// Check results
// Verify correct methods were called
verify(photosInterface).listMediaItems(Optional.of(ALBUM_ID), Optional.empty());
verify(mediaItemSearchResponse).getMediaItems();
// Check pagination
ContinuationData continuationData = result.getContinuationData();
StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
assertThat(paginationToken.getToken()).isEqualTo(PHOTO_TOKEN_PREFIX + PHOTO_TOKEN);
// Check albums field of container (should be empty)
Collection<PhotoAlbum> actualAlbums = result.getExportedData().getAlbums();
assertThat(actualAlbums).isEmpty();
// Check photos field of container
Collection<PhotoModel> actualPhotos = result.getExportedData().getPhotos();
assertThat(actualPhotos.stream().map(PhotoModel::getFetchableUrl).collect(Collectors.toList())).containsExactly(// for download
IMG_URI + "=d");
assertThat(actualPhotos.stream().map(PhotoModel::getAlbumId).collect(Collectors.toList())).containsExactly(ALBUM_ID);
assertThat(actualPhotos.stream().map(PhotoModel::getTitle).collect(Collectors.toList())).containsExactly(FILENAME);
}
use of org.datatransferproject.types.common.models.IdOnlyContainerResource in project data-transfer-project by google.
the class GoogleCalendarExporterTest method exportCalendarFirstSet.
@Test
public void exportCalendarFirstSet() throws IOException {
setUpSingleCalendarResponse();
// Looking at first page, with at least one page after it
calendarListResponse.setNextPageToken(NEXT_TOKEN);
// Run test
ExportResult<CalendarContainerResource> result = googleCalendarExporter.export(JOB_ID, null, Optional.empty());
// Check results
// Verify correct methods were called
verify(calendarClient).calendarList();
verify(calendarCalendarList).list();
verify(calendarListRequest).execute();
// Check pagination token
ContinuationData continuationData = (ContinuationData) result.getContinuationData();
StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
assertThat(paginationToken.getToken()).isEqualTo(CALENDAR_TOKEN_PREFIX + NEXT_TOKEN);
// Check calendars
Collection<CalendarModel> actualCalendars = result.getExportedData().getCalendars();
assertThat(actualCalendars.stream().map(CalendarModel::getId).collect(Collectors.toList())).containsExactly(CALENDAR_ID);
// Check events (should be empty, even though there is an event in the calendar)
Collection<CalendarEventModel> actualEvents = result.getExportedData().getEvents();
assertThat(actualEvents).isEmpty();
// Should be one container in the resource list
List<ContainerResource> actualResources = continuationData.getContainerResources();
assertThat(actualResources.stream().map(a -> ((IdOnlyContainerResource) a).getId()).collect(Collectors.toList())).containsExactly(CALENDAR_ID);
}
use of org.datatransferproject.types.common.models.IdOnlyContainerResource in project data-transfer-project by google.
the class ImgurPhotosExporter method export.
/**
* Exports albums and photos. Gets albums first, then photos which are contained in albums and
* non-album photos
*
* @param jobId the job id
* @param authData authentication data for the operation
* @param exportInformation info about what data to export, see {@link ExportInformation} for more
*/
@Override
public ExportResult<PhotosContainerResource> export(UUID jobId, TokensAndUrlAuthData authData, Optional<ExportInformation> exportInformation) throws Exception {
PaginationData paginationData = exportInformation.isPresent() ? exportInformation.get().getPaginationData() : null;
IdOnlyContainerResource resource = exportInformation.isPresent() ? (IdOnlyContainerResource) exportInformation.get().getContainerResource() : null;
if (resource != null) {
return requestPhotos(authData, resource, paginationData, jobId);
} else {
return requestAlbums(authData, paginationData);
}
}
use of org.datatransferproject.types.common.models.IdOnlyContainerResource in project data-transfer-project by google.
the class ImgurPhotoExporterTest method testAlbumPhotosExport.
@Test
public void testAlbumPhotosExport() throws Exception {
server.enqueue(new MockResponse().setBody(albumsResponse));
server.enqueue(new MockResponse().setBody(album1ImagesResponse));
// export albums
exporter.export(UUID.randomUUID(), token, Optional.empty());
// export album photos
ExportResult<PhotosContainerResource> result = exporter.export(UUID.randomUUID(), token, Optional.of(new ExportInformation(null, new IdOnlyContainerResource("albumId1"))));
assertThat(result.getExportedData().getPhotos()).containsExactly(ALBUM_PHOTO_1, ALBUM_PHOTO_2).inOrder();
}
Aggregations