Search in sources :

Example 21 with VideoModel

use of org.datatransferproject.types.common.models.videos.VideoModel in project data-transfer-project by google.

the class BackblazeVideosImporterTest method testImportVideo.

@Test
public void testImportVideo() throws Exception {
    String dataId = "dataId";
    String title = "title";
    String videoUrl = "videoUrl";
    String description = "description";
    String encodingFormat = "UTF-8";
    String albumName = "albumName";
    String albumId = "albumId";
    String response = "response";
    UUID jobId = UUID.randomUUID();
    VideoModel videoObject = new VideoModel(title, videoUrl, description, encodingFormat, dataId, albumId, false);
    ArrayList<VideoModel> videos = new ArrayList<>();
    videos.add(videoObject);
    VideosContainerResource data = mock(VideosContainerResource.class);
    when(data.getVideos()).thenReturn(videos);
    when(executor.getCachedValue(albumId)).thenReturn(albumName);
    HttpURLConnection connection = mock(HttpURLConnection.class);
    when(connection.getInputStream()).thenReturn(IOUtils.toInputStream("video content", "UTF-8"));
    when(streamProvider.getConnection(videoUrl)).thenReturn(connection);
    when(client.uploadFile(eq("Video Transfer/dataId.mp4"), any())).thenReturn(response);
    when(clientFactory.getOrCreateB2Client(jobId, authData)).thenReturn(client);
    BackblazeVideosImporter sut = new BackblazeVideosImporter(monitor, dataStore, streamProvider, clientFactory);
    sut.importItem(jobId, executor, authData, data);
    ArgumentCaptor<Callable<String>> importCapture = ArgumentCaptor.forClass(Callable.class);
    verify(executor, times(1)).executeAndSwallowIOExceptions(eq(dataId), eq(title), importCapture.capture());
    String actual = importCapture.getValue().call();
    assertEquals(response, actual);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) VideosContainerResource(org.datatransferproject.types.common.models.videos.VideosContainerResource) ArrayList(java.util.ArrayList) UUID(java.util.UUID) VideoModel(org.datatransferproject.types.common.models.videos.VideoModel) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Aggregations

VideoModel (org.datatransferproject.types.common.models.videos.VideoModel)21 Test (org.junit.Test)12 VideosContainerResource (org.datatransferproject.types.common.models.videos.VideosContainerResource)11 UUID (java.util.UUID)6 VideoAlbum (org.datatransferproject.types.common.models.videos.VideoAlbum)6 ArrayList (java.util.ArrayList)5 PhotosLibraryClient (com.google.photos.library.v1.PhotosLibraryClient)4 BatchCreateMediaItemsResponse (com.google.photos.library.v1.proto.BatchCreateMediaItemsResponse)4 NewMediaItemResult (com.google.photos.library.v1.proto.NewMediaItemResult)4 Monitor (org.datatransferproject.api.launcher.Monitor)4 NewMediaItem (com.google.photos.library.v1.proto.NewMediaItem)3 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 MockResponse (okhttp3.mockwebserver.MockResponse)3 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)3 InOrder (org.mockito.InOrder)3 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Status (com.google.rpc.Status)2 HttpURLConnection (java.net.HttpURLConnection)2