use of com.flickr4java.flickr.uploader.UploadMetaData in project data-transfer-project by google.
the class FlickrPhotoService method uploadPhoto.
private String uploadPhoto(PhotoModel photo) throws IOException, FlickrException {
BufferedInputStream inStream = imageStreamProvider.get(photo.getFetchableUrl());
UploadMetaData uploadMetaData = new UploadMetaData().setAsync(false).setPublicFlag(false).setFriendFlag(false).setFamilyFlag(false).setTitle(COPY_PREFIX + photo.getTitle()).setDescription(photo.getDescription());
return uploader.upload(inStream, uploadMetaData);
}
use of com.flickr4java.flickr.uploader.UploadMetaData in project data-transfer-project by google.
the class FlickrPhotosImporter method uploadPhoto.
private String uploadPhoto(PhotoModel photo) throws IOException, FlickrException {
BufferedInputStream inStream = imageStreamProvider.get(photo.getFetchableUrl());
UploadMetaData uploadMetaData = new UploadMetaData().setAsync(false).setPublicFlag(false).setFriendFlag(false).setFamilyFlag(false).setTitle(COPY_PREFIX + photo.getTitle()).setDescription(photo.getDescription());
return uploader.upload(inStream, uploadMetaData);
}
use of com.flickr4java.flickr.uploader.UploadMetaData in project data-transfer-project by google.
the class FlickrPhotosImporterTest method importStoresAlbumInJobStore.
@Test
public void importStoresAlbumInJobStore() throws FlickrException, IOException {
UUID jobId = UUID.randomUUID();
PhotosContainerResource photosContainerResource = new PhotosContainerResource(Collections.singletonList(PHOTO_ALBUM), Collections.singletonList(PHOTO_MODEL));
// Setup Mock
when(user.getId()).thenReturn("userId");
when(authInterface.checkToken(any(Token.class))).thenReturn(auth);
when(flickr.getPhotosetsInterface()).thenReturn(photosetsInterface);
when(flickr.getUploader()).thenReturn(uploader);
when(flickr.getAuthInterface()).thenReturn(authInterface);
when(imageStreamProvider.get(FETCHABLE_URL)).thenReturn(bufferedInputStream);
when(uploader.upload(any(BufferedInputStream.class), any(UploadMetaData.class))).thenReturn(FLICKR_PHOTO_ID);
String flickrAlbumTitle = FlickrPhotosImporter.COPY_PREFIX + ALBUM_NAME;
Photoset photoset = FlickrTestUtils.initializePhotoset(FLICKR_ALBUM_ID, ALBUM_DESCRIPTION, FLICKR_PHOTO_ID);
when(photosetsInterface.create(flickrAlbumTitle, ALBUM_DESCRIPTION, FLICKR_PHOTO_ID)).thenReturn(photoset);
// Run test
FlickrPhotosImporter importer = new FlickrPhotosImporter(flickr, jobStore, imageStreamProvider);
ImportResult result = importer.importItem(jobId, new TokenSecretAuthData("token", "secret"), photosContainerResource);
// Verify that the image stream provider got the correct URL and that the correct info was uploaded
verify(imageStreamProvider).get(FETCHABLE_URL);
ArgumentCaptor<UploadMetaData> uploadMetaDataArgumentCaptor = ArgumentCaptor.forClass(UploadMetaData.class);
verify(uploader).upload(eq(bufferedInputStream), uploadMetaDataArgumentCaptor.capture());
UploadMetaData actualUploadMetaData = uploadMetaDataArgumentCaptor.getValue();
assertThat(actualUploadMetaData.getTitle()).isEqualTo(FlickrPhotosImporter.COPY_PREFIX + PHOTO_TITLE);
assertThat(actualUploadMetaData.getDescription()).isEqualTo(PHOTO_DESCRIPTION);
// Verify the photosets interface got the command to create the correct album
verify(photosetsInterface).create(flickrAlbumTitle, ALBUM_DESCRIPTION, FLICKR_PHOTO_ID);
// Check contents of JobStore
TempPhotosData tempPhotosData = jobStore.findData(TempPhotosData.class, jobId);
assertThat(tempPhotosData).isNotNull();
String expectedAlbumKey = FlickrPhotosImporter.CACHE_ALBUM_METADATA_PREFIX + ALBUM_ID;
assertThat(tempPhotosData.lookupAlbum(expectedAlbumKey)).isNotNull();
assertThat(tempPhotosData.lookupAlbum(expectedAlbumKey)).isEqualTo(PHOTO_ALBUM);
assertThat(tempPhotosData.lookupNewAlbumId(ALBUM_ID)).isEqualTo(FLICKR_ALBUM_ID);
}
use of com.flickr4java.flickr.uploader.UploadMetaData in project data-transfer-project by google.
the class FlickrPhotoServiceTest method importStoresAlbumsInJobCache.
@Test
public void importStoresAlbumsInJobCache() throws IOException, FlickrException {
// Set up input: a single photo album with a single photo
PhotosModelWrapper wrapper = new PhotosModelWrapper(Collections.singletonList(PHOTO_ALBUM), Collections.singletonList(PHOTO_MODEL), new ContinuationInformation(null, null));
// Set up mocks
when(imageStreamProvider.get(FETCHABLE_URL)).thenReturn(bufferedInputStream);
when(uploader.upload(any(BufferedInputStream.class), any(UploadMetaData.class))).thenReturn(FLICKR_PHOTO_ID);
String flickrAlbumTitle = FlickrPhotoService.COPY_PREFIX + ALBUM_NAME;
Photoset photoSet = initializePhotoset(FLICKR_ALBUM_ID, flickrAlbumTitle, ALBUM_DESCRIPTION);
when(photosetsInterface.create(flickrAlbumTitle, ALBUM_DESCRIPTION, FLICKR_PHOTO_ID)).thenReturn(photoSet);
// Run test
photoService.importItem(wrapper);
// Verify the image stream provider got the correct url
verify(imageStreamProvider).get(FETCHABLE_URL);
// Verify the correct photo information was uploaded
ArgumentCaptor<UploadMetaData> uploadMetaDataArgumentCaptor = ArgumentCaptor.forClass(UploadMetaData.class);
verify(uploader).upload(eq(bufferedInputStream), uploadMetaDataArgumentCaptor.capture());
UploadMetaData actualUploadMetaData = uploadMetaDataArgumentCaptor.getValue();
assertThat(actualUploadMetaData.getTitle()).isEqualTo(FlickrPhotoService.COPY_PREFIX + PHOTO_TITLE);
assertThat(actualUploadMetaData.getDescription()).isEqualTo(PHOTO_DESCRIPTION);
// Verify the photosets interface got the command to create the correct album
verify(photosetsInterface).create(flickrAlbumTitle, ALBUM_DESCRIPTION, FLICKR_PHOTO_ID);
// Check jobDataCache contents
String expectedAlbumKey = FlickrPhotoService.CACHE_ALBUM_METADATA_PREFIX + ALBUM_ID;
assertThat(jobDataCache.hasKey(expectedAlbumKey)).isTrue();
assertThat(jobDataCache.getData(expectedAlbumKey, PhotoAlbum.class)).isEqualTo(PHOTO_ALBUM);
assertThat(jobDataCache.getData(ALBUM_ID, String.class)).isEqualTo(FLICKR_ALBUM_ID);
}
Aggregations