use of com.google.photos.library.v1.PhotosLibraryClient in project data-transfer-project by google.
the class GoogleVideosImporterTest method failOneVideo.
@Test
public void failOneVideo() throws Exception {
PhotosLibraryClient photosLibraryClient = mock(PhotosLibraryClient.class);
// Mock uploads
when(photosLibraryClient.uploadMediaItem(any())).thenReturn(UploadMediaItemResponse.newBuilder().setUploadToken("token1").build(), UploadMediaItemResponse.newBuilder().setUploadToken("token2").build());
// Mock creation response
final NewMediaItemResult newMediaItemResult = NewMediaItemResult.newBuilder().setStatus(Status.newBuilder().setCode(Code.OK_VALUE).build()).setMediaItem(MediaItem.newBuilder().setId("RESULT_ID_1").build()).setUploadToken("token1").build();
final NewMediaItemResult newMediaItemResult2 = NewMediaItemResult.newBuilder().setStatus(Status.newBuilder().setCode(Code.INVALID_ARGUMENT_VALUE).build()).setUploadToken("token2").build();
BatchCreateMediaItemsResponse response = BatchCreateMediaItemsResponse.newBuilder().addNewMediaItemResults(newMediaItemResult).addNewMediaItemResults(newMediaItemResult2).build();
when(photosLibraryClient.batchCreateMediaItems(ArgumentMatchers.anyList())).thenReturn(response);
InMemoryIdempotentImportExecutor executor = new InMemoryIdempotentImportExecutor(mock(Monitor.class));
long length = googleVideosImporter.importVideoBatch(Lists.newArrayList(new VideoModel(VIDEO_TITLE, VIDEO_URI, VIDEO_DESCRIPTION, MP4_MEDIA_TYPE, VIDEO_ID, null, false), new VideoModel(VIDEO_TITLE, VIDEO_URI, VIDEO_DESCRIPTION, MP4_MEDIA_TYPE, "myId2", null, false)), photosLibraryClient, executor);
assertEquals("Expected the number of bytes to be the one files of 32L.", 32L, length);
assertEquals("Expected executor to have one error.", 1, executor.getErrors().size());
ErrorDetail errorDetail = executor.getErrors().iterator().next();
assertEquals("myId2", errorDetail.id());
assertThat(errorDetail.exception(), CoreMatchers.containsString("Video item could not be created."));
}
Aggregations