Search in sources :

Example 26 with PhotosContainerResource

use of org.datatransferproject.types.common.models.photos.PhotosContainerResource in project data-transfer-project by google.

the class ImgurPhotoExporterTest method testAlbumAndNonAlbumPhotoExport.

@Test
public void testAlbumAndNonAlbumPhotoExport() throws Exception {
    server.enqueue(new MockResponse().setBody(albumsResponse));
    server.enqueue(new MockResponse().setBody(album1ImagesResponse));
    server.enqueue(new MockResponse().setBody(allImagesResponse));
    // export albums
    exporter.export(UUID.randomUUID(), token, Optional.empty());
    // export album photos
    ExportResult<PhotosContainerResource> albumPhotosResult = exporter.export(UUID.randomUUID(), token, Optional.of(new ExportInformation(null, new IdOnlyContainerResource("albumId1"))));
    assertEquals(2, albumPhotosResult.getExportedData().getPhotos().size());
    // export non-album photos
    ExportResult<PhotosContainerResource> nonAlbumPhotosResult = exporter.export(UUID.randomUUID(), token, Optional.of(new ExportInformation(null, new IdOnlyContainerResource(ImgurPhotosExporter.DEFAULT_ALBUM_ID))));
    PhotosContainerResource resource = nonAlbumPhotosResult.getExportedData();
    assertThat(resource.getPhotos()).containsExactly(NON_ALBUM_PHOTO);
}
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 27 with PhotosContainerResource

use of org.datatransferproject.types.common.models.photos.PhotosContainerResource in project data-transfer-project by google.

the class ImgurPhotoExporterTest method testPagination.

@Test
public void testPagination() throws Exception {
    server.enqueue(new MockResponse().setBody(page1Response));
    server.enqueue(new MockResponse().setBody(page2Response));
    int page = 0;
    ExportResult<PhotosContainerResource> page1Result = exporter.export(UUID.randomUUID(), token, Optional.of(new ExportInformation(new IntPaginationToken(page), new IdOnlyContainerResource(ImgurPhotosExporter.DEFAULT_ALBUM_ID))));
    page++;
    PhotosContainerResource page1Resource = page1Result.getExportedData();
    // 1th request returns 10 photos
    assertEquals(10, page1Resource.getPhotos().size());
    assertEquals(page, ((IntPaginationToken) page1Result.getContinuationData().getPaginationData()).getStart());
    ExportResult<PhotosContainerResource> page2Result = exporter.export(UUID.randomUUID(), token, Optional.of(new ExportInformation(new IntPaginationToken(page), new IdOnlyContainerResource(ImgurPhotosExporter.DEFAULT_ALBUM_ID))));
    page++;
    PhotosContainerResource page2Resource = page2Result.getExportedData();
    // 2th request returns 2 photos
    assertEquals(2, page2Resource.getPhotos().size());
    assertEquals(page, ((IntPaginationToken) page2Result.getContinuationData().getPaginationData()).getStart());
}
Also used : MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) ExportInformation(org.datatransferproject.types.common.ExportInformation) IntPaginationToken(org.datatransferproject.types.common.IntPaginationToken) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) Test(org.junit.Test)

Example 28 with PhotosContainerResource

use of org.datatransferproject.types.common.models.photos.PhotosContainerResource in project data-transfer-project by google.

the class InstagramPhotoExporter method exportPhotos.

private ExportResult<PhotosContainerResource> exportPhotos(TokensAndUrlAuthData authData, Optional<PaginationData> pageData) {
    Preconditions.checkNotNull(authData);
    MediaResponse response;
    try {
        response = makeRequest(MEDIA_URL, MediaResponse.class, authData);
    } catch (IOException e) {
        return new ExportResult<>(e);
    }
    List<PhotoModel> photos = new ArrayList<>();
    // TODO: check out paging.
    for (MediaFeedData photo : response.getData()) {
        // TODO json mapping is broken.
        String photoId = photo.getId();
        String url = photo.getImages().getStandardResolution().getUrl();
        String text = (photo.getCaption() != null) ? photo.getCaption().getText() : null;
        photos.add(new PhotoModel("Instagram photo: " + photoId, url, text, null, photoId, FAKE_ALBUM_ID, false));
    }
    List<PhotoAlbum> albums = new ArrayList<>();
    if (!photos.isEmpty() && !pageData.isPresent()) {
        albums.add(new PhotoAlbum(FAKE_ALBUM_ID, "Imported Instagram Photos", "Photos imported from instagram"));
    }
    return new ExportResult<>(ResultType.END, new PhotosContainerResource(albums, photos));
}
Also used : PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) MediaResponse(org.datatransferproject.transfer.instagram.photos.model.MediaResponse) PhotoModel(org.datatransferproject.types.common.models.photos.PhotoModel) ArrayList(java.util.ArrayList) MediaFeedData(org.datatransferproject.transfer.instagram.photos.model.MediaFeedData) IOException(java.io.IOException) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult)

Example 29 with PhotosContainerResource

use of org.datatransferproject.types.common.models.photos.PhotosContainerResource in project data-transfer-project by google.

the class BackblazePhotosImporterTest method testNullPhotosAndAlbums.

@Test
public void testNullPhotosAndAlbums() throws Exception {
    PhotosContainerResource data = mock(PhotosContainerResource.class);
    when(data.getAlbums()).thenReturn(null);
    when(data.getPhotos()).thenReturn(null);
    BackblazePhotosImporter sut = new BackblazePhotosImporter(monitor, dataStore, streamProvider, clientFactory);
    ImportResult result = sut.importItem(UUID.randomUUID(), executor, authData, data);
    assertEquals(ImportResult.OK, result);
}
Also used : PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) ImportResult(org.datatransferproject.spi.transfer.provider.ImportResult) Test(org.junit.Test)

Example 30 with PhotosContainerResource

use of org.datatransferproject.types.common.models.photos.PhotosContainerResource in project data-transfer-project by google.

the class BackblazePhotosImporterTest method testEmptyPhotosAndAlbums.

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

Aggregations

PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)57 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)37 Test (org.junit.Test)37 IdOnlyContainerResource (org.datatransferproject.types.common.models.IdOnlyContainerResource)29 PhotoModel (org.datatransferproject.types.common.models.photos.PhotoModel)29 ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)27 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)21 ArrayList (java.util.ArrayList)18 StringPaginationToken (org.datatransferproject.types.common.StringPaginationToken)18 UUID (java.util.UUID)14 PaginationData (org.datatransferproject.types.common.PaginationData)12 IOException (java.io.IOException)10 ExportInformation (org.datatransferproject.types.common.ExportInformation)9 ImportResult (org.datatransferproject.spi.transfer.provider.ImportResult)8 IntPaginationToken (org.datatransferproject.types.common.IntPaginationToken)8 InputStreamWrapper (org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore.InputStreamWrapper)6 ContainerResource (org.datatransferproject.types.common.models.ContainerResource)6 TokensAndUrlAuthData (org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData)6 Photoset (com.flickr4java.flickr.photosets.Photoset)5 ImmutableList (com.google.common.collect.ImmutableList)5