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());
}
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");
}
Aggregations