use of org.datatransferproject.types.common.models.photos.PhotoAlbum in project data-transfer-project by google.
the class MicrosoftPhotosExporterTest method exportPhotoWithNextPage.
@Test
public void exportPhotoWithNextPage() throws IOException {
// Setup
when(driveItemsResponse.getNextPageLink()).thenReturn(null);
MicrosoftDriveItem photoItem = setUpSinglePhoto(IMAGE_URI, PHOTO_ID);
when(driveItemsResponse.getDriveItems()).thenReturn(new MicrosoftDriveItem[] { photoItem });
when(driveItemsResponse.getNextPageLink()).thenReturn(DRIVE_PAGE_URL);
IdOnlyContainerResource idOnlyContainerResource = new IdOnlyContainerResource(FOLDER_ID);
// Run
ExportResult<PhotosContainerResource> result = microsoftPhotosExporter.exportOneDrivePhotos(null, Optional.of(idOnlyContainerResource), Optional.empty(), uuid);
// Verify method calls
verify(photosInterface).getDriveItems(Optional.of(FOLDER_ID), Optional.empty());
verify(driveItemsResponse).getDriveItems();
// Verify pagination token is set
ContinuationData continuationData = result.getContinuationData();
StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
assertThat(paginationToken.getToken()).isEqualTo(DRIVE_TOKEN_PREFIX + DRIVE_PAGE_URL);
// Verify no albums are exported
Collection<PhotoAlbum> actualAlbums = result.getExportedData().getAlbums();
assertThat(actualAlbums).isEmpty();
// Verify one photo (in an album) should be exported
Collection<PhotoModel> actualPhotos = result.getExportedData().getPhotos();
assertThat(actualPhotos.stream().map(PhotoModel::getFetchableUrl).collect(Collectors.toList())).containsExactly(IMAGE_URI);
assertThat(actualPhotos.stream().map(PhotoModel::getAlbumId).collect(Collectors.toList())).containsExactly(FOLDER_ID);
assertThat(actualPhotos.stream().map(PhotoModel::getTitle).collect(Collectors.toList())).containsExactly(FILENAME);
// Verify there are no containers ready for sub-processing
List<ContainerResource> actualResources = continuationData.getContainerResources();
assertThat(actualResources).isEmpty();
}
use of org.datatransferproject.types.common.models.photos.PhotoAlbum in project data-transfer-project by google.
the class MicrosoftPhotosExporterTest method exportAlbumWithoutNextPage.
@Test
public void exportAlbumWithoutNextPage() throws IOException {
// Setup
MicrosoftDriveItem folderItem = setUpSingleAlbum();
when(driveItemsResponse.getDriveItems()).thenReturn(new MicrosoftDriveItem[] { folderItem });
when(driveItemsResponse.getNextPageLink()).thenReturn(null);
StringPaginationToken inputPaginationToken = new StringPaginationToken(DRIVE_TOKEN_PREFIX + DRIVE_PAGE_URL);
// Run
ExportResult<PhotosContainerResource> result = microsoftPhotosExporter.exportOneDrivePhotos(null, Optional.empty(), Optional.of(inputPaginationToken), uuid);
// Verify method calls
verify(photosInterface).getDriveItems(Optional.empty(), Optional.of(DRIVE_PAGE_URL));
verify(driveItemsResponse).getDriveItems();
// Verify next pagination token is absent
ContinuationData continuationData = result.getContinuationData();
StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
assertThat(paginationToken).isEqualTo(null);
// Verify one album is ready for import
Collection<PhotoAlbum> actualAlbums = result.getExportedData().getAlbums();
assertThat(actualAlbums.stream().map(PhotoAlbum::getId).collect(Collectors.toList())).containsExactly(FOLDER_ID);
// Verify photos should be empty (in the root)
Collection<PhotoModel> actualPhotos = result.getExportedData().getPhotos();
assertThat(actualPhotos).isEmpty();
// Verify there is one container ready for sub-processing
List<ContainerResource> actualResources = continuationData.getContainerResources();
assertThat(actualResources.stream().map(a -> ((IdOnlyContainerResource) a).getId()).collect(Collectors.toList())).containsExactly(FOLDER_ID);
}
use of org.datatransferproject.types.common.models.photos.PhotoAlbum in project data-transfer-project by google.
the class MicrosoftPhotosExporterTest method exportPhotoWithoutNextPage.
@Test
public void exportPhotoWithoutNextPage() throws IOException {
// Setup
when(driveItemsResponse.getNextPageLink()).thenReturn(null);
MicrosoftDriveItem photoItem = setUpSinglePhoto(IMAGE_URI, PHOTO_ID);
when(driveItemsResponse.getDriveItems()).thenReturn(new MicrosoftDriveItem[] { photoItem });
when(driveItemsResponse.getNextPageLink()).thenReturn(null);
StringPaginationToken inputPaginationToken = new StringPaginationToken(DRIVE_TOKEN_PREFIX + DRIVE_PAGE_URL);
IdOnlyContainerResource idOnlyContainerResource = new IdOnlyContainerResource(FOLDER_ID);
// Run
ExportResult<PhotosContainerResource> result = microsoftPhotosExporter.exportOneDrivePhotos(null, Optional.of(idOnlyContainerResource), Optional.of(inputPaginationToken), uuid);
// Verify method calls
verify(photosInterface).getDriveItems(Optional.of(FOLDER_ID), Optional.of(DRIVE_PAGE_URL));
verify(driveItemsResponse).getDriveItems();
// Verify next pagination token is absent
ContinuationData continuationData = result.getContinuationData();
StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
assertThat(paginationToken).isEqualTo(null);
// Verify no albums are exported
Collection<PhotoAlbum> actualAlbums = result.getExportedData().getAlbums();
assertThat(actualAlbums).isEmpty();
// Verify one photo (in an album) should be exported
Collection<PhotoModel> actualPhotos = result.getExportedData().getPhotos();
assertThat(actualPhotos.stream().map(PhotoModel::getFetchableUrl).collect(Collectors.toList())).containsExactly(IMAGE_URI);
assertThat(actualPhotos.stream().map(PhotoModel::getAlbumId).collect(Collectors.toList())).containsExactly(FOLDER_ID);
assertThat(actualPhotos.stream().map(PhotoModel::getTitle).collect(Collectors.toList())).containsExactly(FILENAME);
// Verify there are no containers ready for sub-processing
List<ContainerResource> actualResources = continuationData.getContainerResources();
assertThat(actualResources).isEmpty();
}
use of org.datatransferproject.types.common.models.photos.PhotoAlbum in project data-transfer-project by google.
the class MicrosoftPhotosImporterTest method testCleanAlbumNames.
@Test
public void testCleanAlbumNames() throws Exception {
List<PhotoAlbum> albums = ImmutableList.of(new PhotoAlbum("id1", "album1.", "This is a fake albumb"));
PhotosContainerResource data = new PhotosContainerResource(albums, null);
Call call = mock(Call.class);
doReturn(call).when(client).newCall(argThat((Request r) -> {
String body = "";
try {
final Buffer buffer = new Buffer();
r.body().writeTo(buffer);
body = buffer.readUtf8();
} catch (IOException e) {
return false;
}
return r.url().toString().equals("https://www.baseurl.com/v1.0/me/drive/special/photos/children") && body.contains("album1_");
}));
Response response = mock(Response.class);
ResponseBody body = mock(ResponseBody.class);
when(body.bytes()).thenReturn(ResponseBody.create(MediaType.parse("application/json"), "{\"id\": \"id1\"}").bytes());
when(body.string()).thenReturn(ResponseBody.create(MediaType.parse("application/json"), "{\"id\": \"id1\"}").string());
when(response.code()).thenReturn(200);
when(response.body()).thenReturn(body);
when(call.execute()).thenReturn(response);
ImportResult result = importer.importItem(uuid, executor, authData, data);
verify(client, times(1)).newCall(any());
assertThat(result).isEqualTo(ImportResult.OK);
}
use of org.datatransferproject.types.common.models.photos.PhotoAlbum in project data-transfer-project by google.
the class MicrosoftPhotosImporterTest method testImportItemPermissionDenied.
@Test(expected = PermissionDeniedException.class)
public void testImportItemPermissionDenied() throws Exception {
List<PhotoAlbum> albums = ImmutableList.of(new PhotoAlbum("id1", "album1.", "This is a fake albumb"));
PhotosContainerResource data = new PhotosContainerResource(albums, null);
Call call = mock(Call.class);
doReturn(call).when(client).newCall(argThat((Request r) -> r.url().toString().equals("https://www.baseurl.com/v1.0/me/drive/special/photos/children")));
Response response = mock(Response.class);
ResponseBody body = mock(ResponseBody.class);
when(body.bytes()).thenReturn(ResponseBody.create(MediaType.parse("application/json"), "{\"id\": \"id1\"}").bytes());
when(body.string()).thenReturn(ResponseBody.create(MediaType.parse("application/json"), "{\"id\": \"id1\"}").string());
when(response.code()).thenReturn(403);
when(response.message()).thenReturn("Access Denied");
when(response.body()).thenReturn(body);
when(call.execute()).thenReturn(response);
ImportResult result = importer.importItem(uuid, executor, authData, data);
}
Aggregations