use of org.datatransferproject.datatransfer.google.mediaModels.GoogleMediaItem 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.datatransfer.google.mediaModels.GoogleMediaItem in project data-transfer-project by google.
the class GooglePhotosExporterTest method onlyExportAlbumlessPhoto.
@Test
public /* Tests that when there is no album information passed along to exportPhotos, only albumless
photos are exported.
*/
void onlyExportAlbumlessPhoto() throws IOException, InvalidTokenException, PermissionDeniedException {
// Set up - two photos will be returned by a media item search without an album id, but one of
// them will have already been put into the list of contained photos
String containedPhotoUri = "contained photo uri";
String containedPhotoId = "contained photo id";
GoogleMediaItem containedPhoto = setUpSinglePhoto(containedPhotoUri, containedPhotoId);
String albumlessPhotoUri = "albumless photo uri";
String albumlessPhotoId = "albumless photo id";
GoogleMediaItem albumlessPhoto = setUpSinglePhoto(albumlessPhotoUri, albumlessPhotoId);
MediaItemSearchResponse mediaItemSearchResponse = mock(MediaItemSearchResponse.class);
when(photosInterface.listMediaItems(eq(Optional.empty()), eq(Optional.empty()))).thenReturn(mediaItemSearchResponse);
when(mediaItemSearchResponse.getMediaItems()).thenReturn(new GoogleMediaItem[] { containedPhoto, albumlessPhoto });
when(mediaItemSearchResponse.getNextPageToken()).thenReturn(null);
TempPhotosData tempPhotosData = new TempPhotosData(uuid);
tempPhotosData.addContainedPhotoId(containedPhotoId);
InputStream stream = GooglePhotosExporter.convertJsonToInputStream(tempPhotosData);
when(jobStore.getStream(uuid, "tempPhotosData")).thenReturn(new InputStreamWrapper(stream));
// Run test
ExportResult<PhotosContainerResource> result = googlePhotosExporter.exportPhotos(null, Optional.empty(), Optional.empty(), uuid);
// Check results
assertThat(result.getExportedData().getPhotos().stream().map(PhotoModel::getFetchableUrl).collect(Collectors.toList())).containsExactly(// download
albumlessPhotoUri + "=d");
}
use of org.datatransferproject.datatransfer.google.mediaModels.GoogleMediaItem in project data-transfer-project by google.
the class GooglePhotosExporterTest method setUpSinglePhoto.
/**
* Sets up a response for a single photo
*/
private GoogleMediaItem setUpSinglePhoto(String imageUri, String photoId) {
GoogleMediaItem photoEntry = new GoogleMediaItem();
photoEntry.setDescription("Description");
photoEntry.setMimeType("image/jpeg");
photoEntry.setBaseUrl(imageUri);
photoEntry.setId(photoId);
photoEntry.setFilename(FILENAME);
MediaMetadata mediaMetadata = new MediaMetadata();
mediaMetadata.setPhoto(new Photo());
photoEntry.setMediaMetadata(mediaMetadata);
return photoEntry;
}
use of org.datatransferproject.datatransfer.google.mediaModels.GoogleMediaItem in project data-transfer-project by google.
the class GooglePhotosImporterTest method buildMediaItemResult.
private NewMediaItemResult buildMediaItemResult(String uploadToken, int code) {
// We do a lot of mocking as building the actual objects would require changing the constructors
// which messed up deserialization so best to leave them unchanged.
GoogleMediaItem mediaItem = Mockito.mock(GoogleMediaItem.class);
Mockito.when(mediaItem.getId()).thenReturn("newId");
Status status = Mockito.mock(Status.class);
Mockito.when(status.getCode()).thenReturn(code);
NewMediaItemResult result = Mockito.mock(NewMediaItemResult.class);
Mockito.when(result.getUploadToken()).thenReturn(uploadToken);
Mockito.when(result.getStatus()).thenReturn(status);
Mockito.when(result.getMediaItem()).thenReturn(mediaItem);
return result;
}
use of org.datatransferproject.datatransfer.google.mediaModels.GoogleMediaItem in project data-transfer-project by google.
the class GoogleVideosExporterTest method setUpSingleVideo.
/**
* Sets up a response for a single video
*/
private GoogleMediaItem setUpSingleVideo(String videoUri, String videoId) {
GoogleMediaItem videoEntry = new GoogleMediaItem();
videoEntry.setDescription("Description");
videoEntry.setMimeType("video/mp4");
videoEntry.setBaseUrl(videoUri);
videoEntry.setId(videoId);
MediaMetadata mediaMetadata = new MediaMetadata();
mediaMetadata.setVideo(new Video());
videoEntry.setMediaMetadata(mediaMetadata);
return videoEntry;
}
Aggregations