Search in sources :

Example 6 with GoogleMediaItem

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);
}
Also used : PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) PhotoModel(org.datatransferproject.types.common.models.photos.PhotoModel) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) GoogleMediaItem(org.datatransferproject.datatransfer.google.mediaModels.GoogleMediaItem) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) Test(org.junit.Test)

Example 7 with GoogleMediaItem

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");
}
Also used : PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) TempPhotosData(org.datatransferproject.spi.transfer.types.TempPhotosData) InputStreamWrapper(org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore.InputStreamWrapper) InputStream(java.io.InputStream) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) GoogleMediaItem(org.datatransferproject.datatransfer.google.mediaModels.GoogleMediaItem) MediaItemSearchResponse(org.datatransferproject.datatransfer.google.mediaModels.MediaItemSearchResponse) Test(org.junit.Test)

Example 8 with GoogleMediaItem

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;
}
Also used : MediaMetadata(org.datatransferproject.datatransfer.google.mediaModels.MediaMetadata) Photo(org.datatransferproject.datatransfer.google.mediaModels.Photo) GoogleMediaItem(org.datatransferproject.datatransfer.google.mediaModels.GoogleMediaItem)

Example 9 with GoogleMediaItem

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;
}
Also used : Status(org.datatransferproject.datatransfer.google.mediaModels.Status) NewMediaItemResult(org.datatransferproject.datatransfer.google.mediaModels.NewMediaItemResult) GoogleMediaItem(org.datatransferproject.datatransfer.google.mediaModels.GoogleMediaItem)

Example 10 with GoogleMediaItem

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;
}
Also used : Video(org.datatransferproject.datatransfer.google.mediaModels.Video) MediaMetadata(org.datatransferproject.datatransfer.google.mediaModels.MediaMetadata) GoogleMediaItem(org.datatransferproject.datatransfer.google.mediaModels.GoogleMediaItem)

Aggregations

GoogleMediaItem (org.datatransferproject.datatransfer.google.mediaModels.GoogleMediaItem)13 ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)6 MediaItemSearchResponse (org.datatransferproject.datatransfer.google.mediaModels.MediaItemSearchResponse)5 StringPaginationToken (org.datatransferproject.types.common.StringPaginationToken)5 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)5 Test (org.junit.Test)5 InputStream (java.io.InputStream)4 TempPhotosData (org.datatransferproject.spi.transfer.types.TempPhotosData)4 PhotoModel (org.datatransferproject.types.common.models.photos.PhotoModel)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)3 PaginationData (org.datatransferproject.types.common.PaginationData)3 IdOnlyContainerResource (org.datatransferproject.types.common.models.IdOnlyContainerResource)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ArrayList (java.util.ArrayList)2 GoogleAlbum (org.datatransferproject.datatransfer.google.mediaModels.GoogleAlbum)2 MediaMetadata (org.datatransferproject.datatransfer.google.mediaModels.MediaMetadata)2 ResultType (org.datatransferproject.spi.transfer.provider.ExportResult.ResultType)2 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)2