use of org.datatransferproject.types.common.models.photos.PhotosContainerResource 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);
}
use of org.datatransferproject.types.common.models.photos.PhotosContainerResource in project data-transfer-project by google.
the class MicrosoftPhotosExporter method exportOneDrivePhotos.
@VisibleForTesting
ExportResult<PhotosContainerResource> exportOneDrivePhotos(TokensAndUrlAuthData authData, Optional<IdOnlyContainerResource> albumData, Optional<PaginationData> paginationData, UUID jobId) throws IOException {
Optional<String> albumId = Optional.empty();
if (albumData.isPresent()) {
albumId = Optional.of(albumData.get().getId());
}
Optional<String> paginationUrl = getDrivePaginationToken(paginationData);
MicrosoftDriveItemsResponse driveItemsResponse;
if (paginationData.isPresent() || albumData.isPresent()) {
driveItemsResponse = getOrCreatePhotosInterface(authData).getDriveItems(albumId, paginationUrl);
} else {
driveItemsResponse = getOrCreatePhotosInterface(authData).getDriveItemsFromSpecialFolder(MicrosoftSpecialFolder.FolderType.photos);
}
PaginationData nextPageData = SetNextPageToken(driveItemsResponse);
ContinuationData continuationData = new ContinuationData(nextPageData);
PhotosContainerResource containerResource;
MicrosoftDriveItem[] driveItems = driveItemsResponse.getDriveItems();
List<PhotoAlbum> albums = new ArrayList<>();
List<PhotoModel> photos = new ArrayList<>();
if (driveItems != null && driveItems.length > 0) {
for (MicrosoftDriveItem driveItem : driveItems) {
PhotoAlbum album = tryConvertDriveItemToPhotoAlbum(driveItem, jobId);
if (album != null) {
albums.add(album);
continuationData.addContainerResource(new IdOnlyContainerResource(driveItem.id));
}
PhotoModel photo = tryConvertDriveItemToPhotoModel(albumId, driveItem, jobId);
if (photo != null) {
photos.add(photo);
}
}
}
ExportResult.ResultType result = nextPageData == null ? ExportResult.ResultType.END : ExportResult.ResultType.CONTINUE;
containerResource = new PhotosContainerResource(albums, photos);
return new ExportResult<>(result, containerResource, continuationData);
}
use of org.datatransferproject.types.common.models.photos.PhotosContainerResource in project data-transfer-project by google.
the class PortabilityJobTest method verifySerializeDeserializeWithAlbum.
@Test
public void verifySerializeDeserializeWithAlbum() throws IOException {
ObjectMapper objectMapper = ObjectMapperFactory.createObjectMapper();
Instant date = Instant.now();
JobAuthorization jobAuthorization = JobAuthorization.builder().setState(JobAuthorization.State.INITIAL).setSessionSecretKey("foo").build();
PortabilityJob job = PortabilityJob.builder().setState(State.NEW).setExportService("fooService").setImportService("barService").setTransferDataType("PHOTOS").setExportInformation(objectMapper.writeValueAsString(new ExportInformation(null, new PhotosContainerResource(Lists.newArrayList(new PhotoAlbum("album_id", "album name", "album description")), null)))).setCreatedTimestamp(date).setLastUpdateTimestamp(date.plusSeconds(120)).setJobAuthorization(jobAuthorization).build();
String serializedJobAuthorization = objectMapper.writeValueAsString(jobAuthorization);
JobAuthorization deserializedJobAuthorization = objectMapper.readValue(serializedJobAuthorization, JobAuthorization.class);
assertThat(deserializedJobAuthorization).isEqualTo(jobAuthorization);
String serializedJob = objectMapper.writeValueAsString(job);
PortabilityJob deserializedJob = objectMapper.readValue(serializedJob, PortabilityJob.class);
assertThat(deserializedJob).isEqualTo(job);
}
use of org.datatransferproject.types.common.models.photos.PhotosContainerResource in project data-transfer-project by google.
the class FlickrPhotosImporterTest method importStoresAlbumInJobStore.
@Test
public void importStoresAlbumInJobStore() throws FlickrException, Exception {
UUID jobId = UUID.randomUUID();
PhotosContainerResource photosContainerResource = new PhotosContainerResource(Collections.singletonList(PHOTO_ALBUM), Collections.singletonList(PHOTO_MODEL));
// Setup Mock
when(user.getId()).thenReturn("userId");
when(authInterface.checkToken(any(Token.class))).thenReturn(auth);
when(flickr.getPhotosetsInterface()).thenReturn(photosetsInterface);
when(flickr.getUploader()).thenReturn(uploader);
when(flickr.getAuthInterface()).thenReturn(authInterface);
when(imageStreamProvider.get(FETCHABLE_URL)).thenReturn(bufferedInputStream);
when(uploader.upload(any(BufferedInputStream.class), any(UploadMetaData.class))).thenReturn(FLICKR_PHOTO_ID);
String flickrAlbumTitle = ALBUM_NAME;
Photoset photoset = FlickrTestUtils.initializePhotoset(FLICKR_ALBUM_ID, ALBUM_DESCRIPTION, FLICKR_PHOTO_ID);
when(photosetsInterface.create(flickrAlbumTitle, ALBUM_DESCRIPTION, FLICKR_PHOTO_ID)).thenReturn(photoset);
// Run test
FlickrPhotosImporter importer = new FlickrPhotosImporter(flickr, jobStore, imageStreamProvider, monitor, TransferServiceConfig.getDefaultInstance());
ImportResult result = importer.importItem(jobId, EXECUTOR, new TokenSecretAuthData("token", "secret"), photosContainerResource);
// Verify that the image stream provider got the correct URL and that the correct info was
// uploaded
verify(imageStreamProvider).get(FETCHABLE_URL);
ArgumentCaptor<UploadMetaData> uploadMetaDataArgumentCaptor = ArgumentCaptor.forClass(UploadMetaData.class);
verify(uploader).upload(eq(bufferedInputStream), uploadMetaDataArgumentCaptor.capture());
UploadMetaData actualUploadMetaData = uploadMetaDataArgumentCaptor.getValue();
assertThat(actualUploadMetaData.getTitle()).isEqualTo(PHOTO_TITLE);
assertThat(actualUploadMetaData.getDescription()).isEqualTo(PHOTO_DESCRIPTION);
// Verify the photosets interface got the command to create the correct album
verify(photosetsInterface).create(flickrAlbumTitle, ALBUM_DESCRIPTION, FLICKR_PHOTO_ID);
assertThat((String) EXECUTOR.getCachedValue(ALBUM_ID)).isEqualTo(FLICKR_ALBUM_ID);
}
use of org.datatransferproject.types.common.models.photos.PhotosContainerResource in project data-transfer-project by google.
the class FacebookPhotosExporterTest method testExportAlbum.
@Test
public void testExportAlbum() throws CopyExceptionWithFailureReason {
ExportResult<PhotosContainerResource> result = facebookPhotosExporter.export(uuid, new TokensAndUrlAuthData("accessToken", null, null), Optional.empty());
assertEquals(ExportResult.ResultType.CONTINUE, result.getType());
PhotosContainerResource exportedData = result.getExportedData();
assertEquals(1, exportedData.getAlbums().size());
assertEquals(new PhotoAlbum(ALBUM_ID, ALBUM_NAME, ALBUM_DESCRIPTION), exportedData.getAlbums().toArray()[0]);
assertNull(result.getContinuationData().getPaginationData());
assertThat(result.getContinuationData().getContainerResources()).contains(new IdOnlyContainerResource(ALBUM_ID));
}
Aggregations