Search in sources :

Example 6 with InputStreamWrapper

use of org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore.InputStreamWrapper in project data-transfer-project by google.

the class KoofrPhotosImporterTest method testImportItemFromJobStoreUserTimeZone.

@Test
public void testImportItemFromJobStoreUserTimeZone() throws Exception {
    ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[] { 0, 1, 2, 3, 4 });
    when(jobStore.getStream(any(), any())).thenReturn(new InputStreamWrapper(inputStream, 5L));
    UUID jobId = UUID.randomUUID();
    PortabilityJob job = mock(PortabilityJob.class);
    when(job.userTimeZone()).thenReturn(TimeZone.getTimeZone("Europe/Rome"));
    when(jobStore.findJob(jobId)).thenReturn(job);
    Collection<PhotoAlbum> albums = ImmutableList.of(new PhotoAlbum("id1", "Album 1", "This is a fake album"));
    DateFormat format = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
    format.setTimeZone(TimeZone.getTimeZone("Europe/Kiev"));
    Collection<PhotoModel> photos = ImmutableList.of(new PhotoModel("pic1.jpg", "http://fake.com/1.jpg", "A pic", "image/jpeg", "p1", "id1", true, format.parse("2021:02:16 11:55:00")));
    PhotosContainerResource resource = spy(new PhotosContainerResource(albums, photos));
    importer.importItem(jobId, executor, authData, resource);
    InOrder clientInOrder = Mockito.inOrder(client);
    clientInOrder.verify(client).uploadFile(any(), eq("2021-02-16 10.55.00 pic1.jpg"), any(), any(), any(), any());
}
Also used : PortabilityJob(org.datatransferproject.spi.cloud.types.PortabilityJob) PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) InputStreamWrapper(org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore.InputStreamWrapper) InOrder(org.mockito.InOrder) ByteArrayInputStream(java.io.ByteArrayInputStream) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) PhotoModel(org.datatransferproject.types.common.models.photos.PhotoModel) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) UUID(java.util.UUID) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 7 with InputStreamWrapper

use of org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore.InputStreamWrapper 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)

Aggregations

InputStreamWrapper (org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore.InputStreamWrapper)7 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)5 Test (org.junit.Test)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)4 PhotoModel (org.datatransferproject.types.common.models.photos.PhotoModel)4 UUID (java.util.UUID)3 InOrder (org.mockito.InOrder)3 InputStream (java.io.InputStream)2 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 PortabilityJob (org.datatransferproject.spi.cloud.types.PortabilityJob)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 UploadMetaData (com.flickr4java.flickr.uploader.UploadMetaData)1 ReadChannel (com.google.cloud.ReadChannel)1 Blob (com.google.cloud.storage.Blob)1 BufferedInputStream (java.io.BufferedInputStream)1 Call (okhttp3.Call)1 Request (okhttp3.Request)1 Response (okhttp3.Response)1