use of org.datatransferproject.types.common.models.photos.PhotosContainerResource in project data-transfer-project by google.
the class ImgurPhotoExporterTest method testAlbumAndNonAlbumPhotoExport.
@Test
public void testAlbumAndNonAlbumPhotoExport() throws Exception {
server.enqueue(new MockResponse().setBody(albumsResponse));
server.enqueue(new MockResponse().setBody(album1ImagesResponse));
server.enqueue(new MockResponse().setBody(allImagesResponse));
// export albums
exporter.export(UUID.randomUUID(), token, Optional.empty());
// export album photos
ExportResult<PhotosContainerResource> albumPhotosResult = exporter.export(UUID.randomUUID(), token, Optional.of(new ExportInformation(null, new IdOnlyContainerResource("albumId1"))));
assertEquals(2, albumPhotosResult.getExportedData().getPhotos().size());
// export non-album photos
ExportResult<PhotosContainerResource> nonAlbumPhotosResult = exporter.export(UUID.randomUUID(), token, Optional.of(new ExportInformation(null, new IdOnlyContainerResource(ImgurPhotosExporter.DEFAULT_ALBUM_ID))));
PhotosContainerResource resource = nonAlbumPhotosResult.getExportedData();
assertThat(resource.getPhotos()).containsExactly(NON_ALBUM_PHOTO);
}
use of org.datatransferproject.types.common.models.photos.PhotosContainerResource 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.photos.PhotosContainerResource in project data-transfer-project by google.
the class InstagramPhotoExporter method exportPhotos.
private ExportResult<PhotosContainerResource> exportPhotos(TokensAndUrlAuthData authData, Optional<PaginationData> pageData) {
Preconditions.checkNotNull(authData);
MediaResponse response;
try {
response = makeRequest(MEDIA_URL, MediaResponse.class, authData);
} catch (IOException e) {
return new ExportResult<>(e);
}
List<PhotoModel> photos = new ArrayList<>();
// TODO: check out paging.
for (MediaFeedData photo : response.getData()) {
// TODO json mapping is broken.
String photoId = photo.getId();
String url = photo.getImages().getStandardResolution().getUrl();
String text = (photo.getCaption() != null) ? photo.getCaption().getText() : null;
photos.add(new PhotoModel("Instagram photo: " + photoId, url, text, null, photoId, FAKE_ALBUM_ID, false));
}
List<PhotoAlbum> albums = new ArrayList<>();
if (!photos.isEmpty() && !pageData.isPresent()) {
albums.add(new PhotoAlbum(FAKE_ALBUM_ID, "Imported Instagram Photos", "Photos imported from instagram"));
}
return new ExportResult<>(ResultType.END, new PhotosContainerResource(albums, photos));
}
use of org.datatransferproject.types.common.models.photos.PhotosContainerResource in project data-transfer-project by google.
the class BackblazePhotosImporterTest method testNullPhotosAndAlbums.
@Test
public void testNullPhotosAndAlbums() throws Exception {
PhotosContainerResource data = mock(PhotosContainerResource.class);
when(data.getAlbums()).thenReturn(null);
when(data.getPhotos()).thenReturn(null);
BackblazePhotosImporter sut = new BackblazePhotosImporter(monitor, dataStore, streamProvider, clientFactory);
ImportResult result = sut.importItem(UUID.randomUUID(), executor, authData, data);
assertEquals(ImportResult.OK, result);
}
use of org.datatransferproject.types.common.models.photos.PhotosContainerResource in project data-transfer-project by google.
the class BackblazePhotosImporterTest method testEmptyPhotosAndAlbums.
@Test
public void testEmptyPhotosAndAlbums() throws Exception {
PhotosContainerResource data = mock(PhotosContainerResource.class);
when(data.getAlbums()).thenReturn(new ArrayList<>());
when(data.getPhotos()).thenReturn(new ArrayList<>());
BackblazePhotosImporter sut = new BackblazePhotosImporter(monitor, dataStore, streamProvider, clientFactory);
ImportResult result = sut.importItem(UUID.randomUUID(), executor, authData, data);
assertEquals(ImportResult.OK, result);
}
Aggregations