use of org.datatransferproject.datatransfer.google.mediaModels.MediaItemSearchResponse in project data-transfer-project by google.
the class GooglePhotosExporterTest method populateContainedPhotosList.
@Test
public void populateContainedPhotosList() throws IOException, InvalidTokenException, PermissionDeniedException {
// Set up an album with two photos
setUpSingleAlbum();
when(albumListResponse.getNextPageToken()).thenReturn(null);
MediaItemSearchResponse albumMediaResponse = mock(MediaItemSearchResponse.class);
GoogleMediaItem firstPhoto = setUpSinglePhoto(IMG_URI, PHOTO_ID);
String secondUri = "second uri";
String secondId = "second id";
GoogleMediaItem secondPhoto = setUpSinglePhoto(secondUri, secondId);
when(photosInterface.listMediaItems(eq(Optional.of(ALBUM_ID)), any(Optional.class))).thenReturn(albumMediaResponse);
when(albumMediaResponse.getMediaItems()).thenReturn(new GoogleMediaItem[] { firstPhoto, secondPhoto });
when(albumMediaResponse.getNextPageToken()).thenReturn(null);
// Run test
googlePhotosExporter.populateContainedPhotosList(uuid, null);
// Check contents of job store
ArgumentCaptor<InputStream> inputStreamArgumentCaptor = ArgumentCaptor.forClass(InputStream.class);
verify(jobStore).create(eq(uuid), eq("tempPhotosData"), inputStreamArgumentCaptor.capture());
TempPhotosData tempPhotosData = new ObjectMapper().readValue(inputStreamArgumentCaptor.getValue(), TempPhotosData.class);
assertThat(tempPhotosData.lookupContainedPhotoIds()).containsExactly(PHOTO_ID, secondId);
}
use of org.datatransferproject.datatransfer.google.mediaModels.MediaItemSearchResponse in project data-transfer-project by google.
the class GoogleVideosExporter method exportVideos.
@VisibleForTesting
ExportResult<VideosContainerResource> exportVideos(TokensAndUrlAuthData authData, Optional<StringPaginationToken> paginationData) throws IOException {
Optional<String> paginationToken = paginationData.map(StringPaginationToken::getToken);
MediaItemSearchResponse mediaItemSearchResponse = getOrCreateVideosInterface(authData).listVideoItems(paginationToken);
PaginationData nextPageData = null;
if (!Strings.isNullOrEmpty(mediaItemSearchResponse.getNextPageToken())) {
nextPageData = new StringPaginationToken(mediaItemSearchResponse.getNextPageToken());
}
ContinuationData continuationData = new ContinuationData(nextPageData);
VideosContainerResource containerResource = null;
GoogleMediaItem[] mediaItems = mediaItemSearchResponse.getMediaItems();
if (mediaItems != null && mediaItems.length > 0) {
List<VideoModel> videos = convertVideosList(mediaItems);
containerResource = new VideosContainerResource(null, videos);
}
ResultType resultType = ResultType.CONTINUE;
if (nextPageData == null) {
resultType = ResultType.END;
}
return new ExportResult<>(resultType, containerResource, continuationData);
}
use of org.datatransferproject.datatransfer.google.mediaModels.MediaItemSearchResponse in project data-transfer-project by google.
the class GooglePhotosExporterTest method setup.
@Before
public void setup() throws IOException, InvalidTokenException, PermissionDeniedException {
GoogleCredentialFactory credentialFactory = mock(GoogleCredentialFactory.class);
jobStore = mock(TemporaryPerJobDataStore.class);
when(jobStore.getStream(any(), anyString())).thenReturn(mock(InputStreamWrapper.class));
photosInterface = mock(GooglePhotosInterface.class);
albumListResponse = mock(AlbumListResponse.class);
mediaItemSearchResponse = mock(MediaItemSearchResponse.class);
Monitor monitor = mock(Monitor.class);
googlePhotosExporter = new GooglePhotosExporter(credentialFactory, jobStore, new JacksonFactory(), photosInterface, monitor);
when(photosInterface.listAlbums(any(Optional.class))).thenReturn(albumListResponse);
when(photosInterface.listMediaItems(any(Optional.class), any(Optional.class))).thenReturn(mediaItemSearchResponse);
verifyNoInteractions(credentialFactory);
}
use of org.datatransferproject.datatransfer.google.mediaModels.MediaItemSearchResponse 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.MediaItemSearchResponse in project data-transfer-project by google.
the class GoogleVideosExporterTest method setup.
@Before
public void setup() throws IOException {
GoogleCredentialFactory credentialFactory = mock(GoogleCredentialFactory.class);
jobStore = mock(TemporaryPerJobDataStore.class);
videosInterface = mock(GoogleVideosInterface.class);
albumListResponse = mock(AlbumListResponse.class);
mediaItemSearchResponse = mock(MediaItemSearchResponse.class);
googleVideosExporter = new GoogleVideosExporter(credentialFactory, videosInterface);
when(videosInterface.listVideoItems(any(Optional.class))).thenReturn(mediaItemSearchResponse);
verifyNoInteractions(credentialFactory);
}
Aggregations