use of org.datatransferproject.types.common.models.photos.PhotosContainerResource in project data-transfer-project by google.
the class KoofrPhotosExporterTest method testExport.
@Test
public void testExport() throws Exception {
when(client.getRootPath()).thenReturn("/Data transfer");
when(client.listRecursive("/Data transfer")).thenReturn(Fixtures.listRecursiveItems);
when(client.fileLink("/Data transfer/Album 1/Photo 1.jpg")).thenReturn("https://app-1.koofr.net/content/files/get/Photo+1.jpg?base=TESTBASE");
when(client.fileLink("/Data transfer/Album 1/Photo 2.jpg")).thenReturn("https://app-1.koofr.net/content/files/get/Photo+2.jpg?base=TESTBASE");
when(client.fileLink("/Data transfer/Album 2 :heart:/Photo 3.jpg")).thenReturn("https://app-1.koofr.net/content/files/get/Photo+3.jpg?base=TESTBASE");
UUID jobId = UUID.randomUUID();
ExportResult<PhotosContainerResource> result = exporter.export(jobId, authData, Optional.empty());
assertEquals(ExportResult.ResultType.END, result.getType());
assertNull(result.getContinuationData());
PhotosContainerResource exportedData = result.getExportedData();
List<PhotoAlbum> expectedAlbums = ImmutableList.of(new PhotoAlbum("/Album 1", "Album 1", null), new PhotoAlbum("/Album 2 :heart:", "Album 2 ❤️", "Album 2 description ❤️"));
assertEquals(expectedAlbums, exportedData.getAlbums());
List<PhotoModel> expectedPhotos = ImmutableList.of(new PhotoModel("Photo 1.jpg", "https://app-1.koofr.net/content/files/get/Photo+1.jpg?base=TESTBASE", "Photo 1 description", "image/jpeg", "/Album 1/Photo 1.jpg", "/Album 1", false, new Date(1324824491000L)), new PhotoModel("Photo 2.jpg", "https://app-1.koofr.net/content/files/get/Photo+2.jpg?base=TESTBASE", null, "image/jpeg", "/Album 1/Photo 2.jpg", "/Album 1", false, new Date(1368774569000L)), new PhotoModel("Photo 3.jpg", "https://app-1.koofr.net/content/files/get/Photo+3.jpg?base=TESTBASE", "Photo 3 description", "image/jpeg", "/Album 2 :heart:/Photo 3.jpg", "/Album 2 :heart:", false, new Date(1489345497000L)));
assertEquals(expectedPhotos, exportedData.getPhotos());
}
use of org.datatransferproject.types.common.models.photos.PhotosContainerResource in project data-transfer-project by google.
the class KoofrPhotosImporterTest method testImportItemFromJobStore.
@Test
public void testImportItemFromJobStore() throws Exception {
ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[] { 0, 1, 2, 3, 4 });
when(client.ensureRootFolder()).thenReturn("/root");
when(jobStore.getStream(any(), any())).thenReturn(new InputStreamWrapper(inputStream, 5L));
doNothing().when(jobStore).removeData(any(), anyString());
when(executor.getCachedValue(eq("id1"))).thenReturn("/root/Album 1");
UUID jobId = UUID.randomUUID();
Collection<PhotoAlbum> albums = ImmutableList.of(new PhotoAlbum("id1", "Album 1", "This is a fake album"));
Collection<PhotoModel> photos = ImmutableList.of(new PhotoModel("pic1.jpg", "http://fake.com/1.jpg", "A pic", "image/jpeg", "p1", "id1", true), new PhotoModel("pic2.png", "https://fake.com/2.png", "fine art", "image/png", "p2", "id1", true));
PhotosContainerResource resource = spy(new PhotosContainerResource(albums, photos));
importer.importItem(jobId, executor, authData, resource);
InOrder clientInOrder = Mockito.inOrder(client);
verify(resource).transmogrify(any(KoofrTransmogrificationConfig.class));
clientInOrder.verify(client).ensureRootFolder();
clientInOrder.verify(client).ensureFolder("/root", "Album 1");
clientInOrder.verify(client).uploadFile(eq("/root/Album 1"), eq("pic1.jpg"), any(), eq("image/jpeg"), isNull(), eq("A pic"));
clientInOrder.verify(client).uploadFile(eq("/root/Album 1"), eq("pic2.png"), any(), eq("image/png"), isNull(), eq("fine art"));
verify(jobStore, Mockito.times(2)).removeData(any(), anyString());
}
use of org.datatransferproject.types.common.models.photos.PhotosContainerResource in project data-transfer-project by google.
the class KoofrTransmogrificationConfigTest method testPhotoTitleName.
@Test
public void testPhotoTitleName() {
Collection<PhotoAlbum> albums = ImmutableList.of(new PhotoAlbum("id1", "Album ~\"#%&*:<>?/\\{|}1", "This is a fake album"));
Collection<PhotoModel> photos = ImmutableList.of(new PhotoModel("pic1~\"#%&*:<>?/\\{|}.jpg", "http://fake.com/1.jpg", "A pic", "image/jpg", "p1", "id1", true), new PhotoModel("pic2~\"#%&*:<>?/\\{|}.jpg", "https://fake.com/2.png", "fine art", "image/png", "p2", "id1", true));
PhotosContainerResource container = new PhotosContainerResource(albums, photos);
KoofrTransmogrificationConfig config = new KoofrTransmogrificationConfig();
container.transmogrify(config);
PhotoAlbum[] albumsArray = container.getAlbums().toArray(new PhotoAlbum[0]);
PhotoModel[] photosArray = container.getPhotos().toArray(new PhotoModel[0]);
Assert.assertEquals(1, albumsArray.length);
Assert.assertEquals("Album _______________1", albumsArray[0].getName());
Assert.assertEquals(2, photosArray.length);
Assert.assertEquals("pic1_______________.jpg", photosArray[0].getTitle());
Assert.assertEquals("pic2_______________.jpg", photosArray[1].getTitle());
}
use of org.datatransferproject.types.common.models.photos.PhotosContainerResource in project data-transfer-project by google.
the class ImgurPhotosExporter method requestAlbums.
/**
* Exports albums.
*
* @param authData authentication information
* @param paginationData pagination information to use for subsequent calls
*/
private ExportResult<PhotosContainerResource> requestAlbums(TokensAndUrlAuthData authData, PaginationData paginationData) throws IOException {
ImmutableList.Builder<PhotoAlbum> albumBuilder = ImmutableList.builder();
List<IdOnlyContainerResource> albumIds = new ArrayList<>();
int page = paginationData == null ? 0 : ((IntPaginationToken) paginationData).getStart();
String url = format(ALBUMS_URL_TEMPLATE, page);
List<Map<String, Object>> items = requestData(authData, url);
// Request result doesn't indicate if it's the last page
boolean hasMore = (items != null && items.size() != 0);
for (Map<String, Object> item : items) {
albumBuilder.add(new PhotoAlbum((String) item.get("id"), (String) item.get("title"), (String) item.get("description")));
// Save album id for recalling export to get all the photos in albums
albumIds.add(new IdOnlyContainerResource((String) item.get("id")));
}
if (page == 0) {
// For checking non-album photos. Their export should be performed after all the others
// Album will be created later
albumIds.add(new IdOnlyContainerResource(DEFAULT_ALBUM_ID));
}
PaginationData newPage = null;
if (hasMore) {
newPage = new IntPaginationToken(page + 1);
int start = ((IntPaginationToken) newPage).getStart();
monitor.info(() -> format("albums size: %s, newPage: %s", items.size(), start));
}
PhotosContainerResource photosContainerResource = new PhotosContainerResource(albumBuilder.build(), null);
ContinuationData continuationData = new ContinuationData(newPage);
albumIds.forEach(continuationData::addContainerResource);
ExportResult.ResultType resultType = ExportResult.ResultType.CONTINUE;
if (newPage == null) {
resultType = ExportResult.ResultType.END;
}
return new ExportResult<>(resultType, photosContainerResource, continuationData);
}
use of org.datatransferproject.types.common.models.photos.PhotosContainerResource in project data-transfer-project by google.
the class ImgurPhotoExporterTest method testNonAlbumPhotoExport.
@Test
public void testNonAlbumPhotoExport() throws Exception {
// all photos are non-album
server.enqueue(new MockResponse().setBody(allImagesResponse));
ExportResult<PhotosContainerResource> nonAlbumPhotosResult = exporter.export(UUID.randomUUID(), token, Optional.of(new ExportInformation(null, new IdOnlyContainerResource(ImgurPhotosExporter.DEFAULT_ALBUM_ID))));
PhotosContainerResource resource = nonAlbumPhotosResult.getExportedData();
assertEquals(3, resource.getPhotos().size());
}
Aggregations