Search in sources :

Example 21 with ExportInformation

use of org.datatransferproject.types.common.ExportInformation in project data-transfer-project by google.

the class GoogleCalendarExporterTest method exportCalendarSubsequentSet.

@Test
public void exportCalendarSubsequentSet() throws IOException {
    setUpSingleCalendarResponse();
    // Looking at subsequent page, with no page after it
    PaginationData paginationData = new StringPaginationToken(CALENDAR_TOKEN_PREFIX + NEXT_TOKEN);
    ExportInformation exportInformation = new ExportInformation(paginationData, null);
    calendarListResponse.setNextPageToken(null);
    // Run test
    ExportResult<CalendarContainerResource> result = googleCalendarExporter.export(UUID.randomUUID(), null, Optional.of(exportInformation));
    // Check results
    // Verify correct calls were made
    InOrder inOrder = Mockito.inOrder(calendarListRequest);
    inOrder.verify(calendarListRequest).setPageToken(NEXT_TOKEN);
    inOrder.verify(calendarListRequest).execute();
    // Check pagination token
    ContinuationData continuationData = (ContinuationData) result.getContinuationData();
    StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
    assertThat(paginationToken).isNull();
}
Also used : ExportInformation(org.datatransferproject.types.common.ExportInformation) PaginationData(org.datatransferproject.types.common.PaginationData) InOrder(org.mockito.InOrder) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) CalendarContainerResource(org.datatransferproject.types.common.models.calendar.CalendarContainerResource) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) Test(org.junit.Test)

Example 22 with ExportInformation

use of org.datatransferproject.types.common.ExportInformation in project data-transfer-project by google.

the class ImgurPhotoExporterTest method testAlbumPhotosExport.

@Test
public void testAlbumPhotosExport() throws Exception {
    server.enqueue(new MockResponse().setBody(albumsResponse));
    server.enqueue(new MockResponse().setBody(album1ImagesResponse));
    // export albums
    exporter.export(UUID.randomUUID(), token, Optional.empty());
    // export album photos
    ExportResult<PhotosContainerResource> result = exporter.export(UUID.randomUUID(), token, Optional.of(new ExportInformation(null, new IdOnlyContainerResource("albumId1"))));
    assertThat(result.getExportedData().getPhotos()).containsExactly(ALBUM_PHOTO_1, ALBUM_PHOTO_2).inOrder();
}
Also used : MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) ExportInformation(org.datatransferproject.types.common.ExportInformation) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) Test(org.junit.Test)

Example 23 with ExportInformation

use of org.datatransferproject.types.common.ExportInformation in project data-transfer-project by google.

the class FlickrPhotosExporterTest method exportPhotosFromPhotoset.

@Test
public void exportPhotosFromPhotoset() throws FlickrException {
    // set up auth, flickr service
    when(user.getId()).thenReturn("userId");
    when(authInterface.checkToken(any(Token.class))).thenReturn(auth);
    when(flickr.getPhotosetsInterface()).thenReturn(photosetsInterface);
    when(flickr.getPhotosInterface()).thenReturn(photosInterface);
    when(flickr.getAuthInterface()).thenReturn(authInterface);
    // getting photos from a set with id photosetsId and page 1
    int page = 1;
    String photosetsId = "photosetsId";
    ExportInformation exportInformation = new ExportInformation(null, new IdOnlyContainerResource(photosetsId));
    // make lots of photos and add them to PhotoList (also adding pagination information)
    int numPhotos = 4;
    PhotoList<Photo> photosList = new PhotoList<>();
    for (int i = 0; i < numPhotos; i++) {
        photosList.add(FlickrTestUtils.initializePhoto("title" + 1, "url" + i, "description" + i, MEDIA_TYPE));
    }
    photosList.setPage(page);
    photosList.setPages(page + 1);
    when(photosetsInterface.getPhotos(anyString(), anySet(), anyInt(), anyInt(), anyInt())).thenReturn(photosList);
    // run test
    FlickrPhotosExporter exporter = new FlickrPhotosExporter(flickr, TransferServiceConfig.getDefaultInstance());
    ExportResult<PhotosContainerResource> result = exporter.export(UUID.randomUUID(), new TokenSecretAuthData("token", "secret"), Optional.of(exportInformation));
    assertThat(result.getExportedData().getPhotos().size()).isEqualTo(numPhotos);
    assertThat(result.getExportedData().getAlbums()).isEmpty();
    ContinuationData continuationData = (ContinuationData) result.getContinuationData();
    assertThat(continuationData.getContainerResources()).isEmpty();
    assertThat(((IntPaginationToken) continuationData.getPaginationData()).getStart()).isEqualTo(page + 1);
}
Also used : IntPaginationToken(org.datatransferproject.types.common.IntPaginationToken) IntPaginationToken(org.datatransferproject.types.common.IntPaginationToken) Token(org.scribe.model.Token) Photo(com.flickr4java.flickr.photos.Photo) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) ExportInformation(org.datatransferproject.types.common.ExportInformation) PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) PhotoList(com.flickr4java.flickr.photos.PhotoList) TokenSecretAuthData(org.datatransferproject.types.transfer.auth.TokenSecretAuthData) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) Test(org.junit.Test)

Example 24 with ExportInformation

use of org.datatransferproject.types.common.ExportInformation in project data-transfer-project by google.

the class FacebookPhotosExporterTest method testExportPhoto.

@Test
public void testExportPhoto() throws CopyExceptionWithFailureReason {
    ExportResult<PhotosContainerResource> result = facebookPhotosExporter.export(uuid, new TokensAndUrlAuthData("accessToken", null, null), Optional.of(new ExportInformation(null, new IdOnlyContainerResource(ALBUM_ID))));
    assertEquals(ExportResult.ResultType.END, result.getType());
    PhotosContainerResource exportedData = result.getExportedData();
    assertEquals(1, exportedData.getPhotos().size());
    assertEquals(new PhotoModel(PHOTO_ID + ".jpg", PHOTO_ID, PHOTO_NAME, "image/jpg", PHOTO_ID, ALBUM_ID, false, PHOTO_TIME), exportedData.getPhotos().toArray()[0]);
}
Also used : PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) ExportInformation(org.datatransferproject.types.common.ExportInformation) PhotoModel(org.datatransferproject.types.common.models.photos.PhotoModel) TokensAndUrlAuthData(org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) Test(org.junit.Test)

Example 25 with ExportInformation

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

Aggregations

ExportInformation (org.datatransferproject.types.common.ExportInformation)26 Test (org.junit.Test)20 ContainerResource (org.datatransferproject.types.common.models.ContainerResource)10 InOrder (org.mockito.InOrder)10 ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)9 IdOnlyContainerResource (org.datatransferproject.types.common.models.IdOnlyContainerResource)9 PaginationData (org.datatransferproject.types.common.PaginationData)8 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)8 StringPaginationToken (org.datatransferproject.types.common.StringPaginationToken)7 MockResponse (com.squareup.okhttp.mockwebserver.MockResponse)4 CalendarContainerResource (org.datatransferproject.types.common.models.calendar.CalendarContainerResource)3 TokensAndUrlAuthData (org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Stack (java.util.Stack)2 UUID (java.util.UUID)2 PortabilityJob (org.datatransferproject.spi.cloud.types.PortabilityJob)2 IntPaginationToken (org.datatransferproject.types.common.IntPaginationToken)2 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1