Search in sources :

Example 11 with VideosContainerResource

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

the class FacebookVideosExporterTest method testExportVideo.

@Test
public void testExportVideo() throws CopyExceptionWithFailureReason {
    ExportResult<VideosContainerResource> result = facebookVideosExporter.export(uuid, new TokensAndUrlAuthData("accessToken", null, null), Optional.of(new ExportInformation(null, null)));
    assertEquals(ExportResult.ResultType.END, result.getType());
    VideosContainerResource exportedData = result.getExportedData();
    assertEquals(1, exportedData.getVideos().size());
    assertEquals(new VideoModel(VIDEO_ID + ".mp4", VIDEO_SOURCE, VIDEO_NAME, "video/mp4", VIDEO_ID, null, false), exportedData.getVideos().toArray()[0]);
}
Also used : ExportInformation(org.datatransferproject.types.common.ExportInformation) VideosContainerResource(org.datatransferproject.types.common.models.videos.VideosContainerResource) TokensAndUrlAuthData(org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData) VideoModel(org.datatransferproject.types.common.models.videos.VideoModel) Test(org.junit.Test)

Example 12 with VideosContainerResource

use of org.datatransferproject.types.common.models.videos.VideosContainerResource 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)

Example 13 with VideosContainerResource

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

the class BackblazeVideosImporterTest method testEmptyVideos.

@Test
public void testEmptyVideos() throws Exception {
    VideosContainerResource data = mock(VideosContainerResource.class);
    when(data.getVideos()).thenReturn(new ArrayList<>());
    BackblazeVideosImporter sut = new BackblazeVideosImporter(monitor, dataStore, streamProvider, clientFactory);
    ImportResult result = sut.importItem(UUID.randomUUID(), executor, authData, data);
    assertEquals(ImportResult.OK, result);
}
Also used : ImportResult(org.datatransferproject.spi.transfer.provider.ImportResult) VideosContainerResource(org.datatransferproject.types.common.models.videos.VideosContainerResource) Test(org.junit.Test)

Aggregations

VideosContainerResource (org.datatransferproject.types.common.models.videos.VideosContainerResource)13 VideoModel (org.datatransferproject.types.common.models.videos.VideoModel)11 Test (org.junit.Test)9 UUID (java.util.UUID)6 VideoAlbum (org.datatransferproject.types.common.models.videos.VideoAlbum)5 ArrayList (java.util.ArrayList)3 MockResponse (okhttp3.mockwebserver.MockResponse)3 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)3 ImportResult (org.datatransferproject.spi.transfer.provider.ImportResult)3 InOrder (org.mockito.InOrder)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 IOException (java.io.IOException)2 ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)2 StringPaginationToken (org.datatransferproject.types.common.StringPaginationToken)2 TokensAndUrlAuthData (org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData)2 FixedCredentialsProvider (com.google.api.gax.core.FixedCredentialsProvider)1 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)1 AccessToken (com.google.auth.oauth2.AccessToken)1 UserCredentials (com.google.auth.oauth2.UserCredentials)1 Preconditions (com.google.common.base.Preconditions)1