use of org.datatransferproject.types.transfer.auth.AppCredentials in project data-transfer-project by google.
the class SmugMugPhotosImporterTest method importEmptyAlbumName.
@Test
public void importEmptyAlbumName() throws Exception {
UUID jobId = UUID.randomUUID();
PhotoAlbum photoAlbum = new PhotoAlbum("albumid", "", "albumDescription");
PhotosContainerResource photosContainerResource = new PhotosContainerResource(Collections.singletonList(photoAlbum), ImmutableList.of());
SmugMugAlbum smugMugAlbum = new SmugMugAlbum("date", photoAlbum.getDescription(), "Untitled Album", "privacy", "albumUri1", "urlname", "weburi");
SmugMugAlbumResponse mockAlbumResponse = new SmugMugAlbumResponse(smugMugAlbum.getUri(), "Locator", "LocatorType", smugMugAlbum);
when(smugMugInterface.createAlbum(eq(smugMugAlbum.getName()))).thenReturn(mockAlbumResponse);
// Run test
SmugMugPhotosImporter importer = new SmugMugPhotosImporter(smugMugInterface, config, jobStore, new AppCredentials("key", "secret"), mock(ObjectMapper.class), monitor);
ImportResult result = importer.importItem(jobId, EXECUTOR, new TokenSecretAuthData("token", "secret"), photosContainerResource);
// Verify
verify(smugMugInterface, atLeastOnce()).createAlbum(ArgumentCaptor.forClass(String.class).capture());
}
use of org.datatransferproject.types.transfer.auth.AppCredentials in project data-transfer-project by google.
the class SmugMugPhotosImporterTest method importStoresAlbumInJobStore.
@Test
public void importStoresAlbumInJobStore() throws Exception {
// setup test objects
UUID jobId = UUID.randomUUID();
PhotoAlbum photoAlbum1 = new PhotoAlbum("albumId1", "albumName1", "albumDescription1");
PhotoModel photoModel1 = new PhotoModel("PHOTO_TITLE", "FETCHABLE_URL", "PHOTO_DESCRIPTION", "MEDIA_TYPE", "photoId1", photoAlbum1.getId(), false);
PhotoModel photoModel2 = new PhotoModel("PHOTO_TITLE", "FETCHABLE_URL", "PHOTO_DESCRIPTION", "MEDIA_TYPE", "photoId2", photoAlbum1.getId(), false);
PhotoModel photoModel3 = new PhotoModel("PHOTO_TITLE", "FETCHABLE_URL", "PHOTO_DESCRIPTION", "MEDIA_TYPE", "photoId3", photoAlbum1.getId(), false);
PhotosContainerResource photosContainerResource1 = new PhotosContainerResource(Collections.singletonList(photoAlbum1), ImmutableList.of());
PhotosContainerResource photosContainerResource2 = new PhotosContainerResource(ImmutableList.of(), ImmutableList.of(photoModel1, photoModel2, photoModel3));
SmugMugAlbum smugMugAlbum1 = new SmugMugAlbum("date", photoAlbum1.getDescription(), photoAlbum1.getName(), "privacy", "albumUri1", "urlname", "weburi");
String overflowAlbumName = smugMugAlbum1.getName() + " (1)";
SmugMugAlbum smugMugAlbum2 = new SmugMugAlbum("date", photoAlbum1.getDescription(), overflowAlbumName, "privacy", "albumUri2", "urlname", "weburi");
SmugMugAlbumResponse mockAlbumResponse1 = new SmugMugAlbumResponse(smugMugAlbum1.getUri(), "Locator", "LocatorType", smugMugAlbum1);
SmugMugAlbumResponse mockAlbumResponse2 = new SmugMugAlbumResponse(smugMugAlbum2.getUri(), "Locator", "LocatorType", smugMugAlbum2);
when(smugMugInterface.createAlbum(eq(smugMugAlbum1.getName()))).thenReturn(mockAlbumResponse1);
when(smugMugInterface.createAlbum(eq(smugMugAlbum2.getName()))).thenReturn(mockAlbumResponse2);
SmugMugImageUploadResponse smugMugUploadImageResponse = new SmugMugImageUploadResponse("imageUri", "albumImageUri", new ImageInfo("imageUri", "albumImageUri", "statusImageReplaceUri", "url"));
when(smugMugInterface.uploadImage(any(), any(), any())).thenReturn(smugMugUploadImageResponse);
when(smugMugInterface.getImageAsStream(any())).thenReturn(bufferedInputStream);
// Run test
SmugMugPhotosImporter importer = new SmugMugPhotosImporter(smugMugInterface, config, jobStore, new AppCredentials("key", "secret"), mock(ObjectMapper.class), monitor);
ImportResult result = importer.importItem(jobId, EXECUTOR, new TokenSecretAuthData("token", "secret"), photosContainerResource1);
result = importer.importItem(jobId, EXECUTOR, new TokenSecretAuthData("token", "secret"), photosContainerResource2);
// Verify
ArgumentCaptor<String> photoUrlsCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> albumNamesCaptor = ArgumentCaptor.forClass(String.class);
verify(smugMugInterface, atLeastOnce()).createAlbum(albumNamesCaptor.capture());
verify(smugMugInterface, atLeastOnce()).getImageAsStream(photoUrlsCaptor.capture());
List<String> capturedAlbumNames = albumNamesCaptor.getAllValues();
assertTrue(capturedAlbumNames.contains(smugMugAlbum1.getName()));
assertTrue(capturedAlbumNames.contains(smugMugAlbum2.getName()));
List<String> capturedPhotoUrls = photoUrlsCaptor.getAllValues();
assertTrue(capturedPhotoUrls.contains(photoModel1.getFetchableUrl()));
assertTrue(capturedPhotoUrls.contains(photoModel2.getFetchableUrl()));
assertTrue(capturedPhotoUrls.contains(photoModel3.getFetchableUrl()));
String overflowAlbumId = photoAlbum1.getId() + "-overflow-1";
assertThat((String) EXECUTOR.getCachedValue(photoAlbum1.getId())).isEqualTo(smugMugAlbum1.getUri());
assertThat((String) EXECUTOR.getCachedValue(overflowAlbumId)).isEqualTo(smugMugAlbum2.getUri());
SmugMugPhotoTempData tempData1 = new SmugMugPhotoTempData(photoAlbum1.getId(), smugMugAlbum1.getName(), smugMugAlbum1.getDescription(), smugMugAlbum1.getUri(), 2, overflowAlbumId);
SmugMugPhotoTempData tempData2 = new SmugMugPhotoTempData(overflowAlbumId, smugMugAlbum2.getName(), smugMugAlbum2.getDescription(), smugMugAlbum2.getUri(), 1, null);
assertThat(jobStore.findData(jobId, String.format(TEMP_DATA_FORMAT, photoAlbum1.getId()), SmugMugPhotoTempData.class).toString()).isEqualTo(tempData1.toString());
assertThat(jobStore.findData(jobId, String.format(TEMP_DATA_FORMAT, overflowAlbumId), SmugMugPhotoTempData.class).toString()).isEqualTo(tempData2.toString());
}
use of org.datatransferproject.types.transfer.auth.AppCredentials in project data-transfer-project by google.
the class GoogleTransferExtension method initialize.
@Override
public void initialize(ExtensionContext context) {
// times.
if (initialized)
return;
JobStore jobStore = context.getService(JobStore.class);
HttpTransport httpTransport = context.getService(HttpTransport.class);
JsonFactory jsonFactory = context.getService(JsonFactory.class);
AppCredentials appCredentials;
try {
appCredentials = context.getService(AppCredentialStore.class).getAppCredentials("GOOGLE_KEY", "GOOGLE_SECRET");
} catch (IOException e) {
Monitor monitor = context.getMonitor();
monitor.info(() -> "Unable to retrieve Google AppCredentials. Did you set GOOGLE_KEY and GOOGLE_SECRET?");
return;
}
Monitor monitor = context.getMonitor();
// Create the GoogleCredentialFactory with the given {@link AppCredentials}.
GoogleCredentialFactory credentialFactory = new GoogleCredentialFactory(httpTransport, jsonFactory, appCredentials, monitor);
ImmutableMap.Builder<String, Importer> importerBuilder = ImmutableMap.builder();
importerBuilder.put("BLOBS", new DriveImporter(credentialFactory, jobStore, monitor));
importerBuilder.put("CONTACTS", new GoogleContactsImporter(credentialFactory));
importerBuilder.put("CALENDAR", new GoogleCalendarImporter(credentialFactory));
importerBuilder.put("MAIL", new GoogleMailImporter(credentialFactory, monitor));
importerBuilder.put("TASKS", new GoogleTasksImporter(credentialFactory));
importerBuilder.put("PHOTOS", new GooglePhotosImporter(credentialFactory, jobStore, jsonFactory, monitor, context.getSetting("googleWritesPerSecond", 1.0)));
importerBuilder.put("VIDEOS", new GoogleVideosImporter(appCredentials, jobStore, monitor));
importerMap = importerBuilder.build();
ImmutableMap.Builder<String, Exporter> exporterBuilder = ImmutableMap.builder();
exporterBuilder.put("BLOBS", new DriveExporter(credentialFactory, jobStore, monitor));
exporterBuilder.put("CONTACTS", new GoogleContactsExporter(credentialFactory));
exporterBuilder.put("CALENDAR", new GoogleCalendarExporter(credentialFactory));
exporterBuilder.put("MAIL", new GoogleMailExporter(credentialFactory));
exporterBuilder.put("SOCIAL-POSTS", new GooglePlusExporter(credentialFactory));
exporterBuilder.put("TASKS", new GoogleTasksExporter(credentialFactory, monitor));
exporterBuilder.put("PHOTOS", new GooglePhotosExporter(credentialFactory, jobStore, jsonFactory, monitor));
exporterBuilder.put("VIDEOS", new GoogleVideosExporter(credentialFactory, jsonFactory));
exporterMap = exporterBuilder.build();
initialized = true;
}
use of org.datatransferproject.types.transfer.auth.AppCredentials in project data-transfer-project by google.
the class FacebookPhotosExporterTest method setUp.
@Before
public void setUp() throws IOException {
FacebookPhotosInterface photosInterface = mock(FacebookPhotosInterface.class);
// Set up example album
Album album = new Album();
album.setId(ALBUM_ID);
album.setName(ALBUM_NAME);
album.setDescription(ALBUM_DESCRIPTION);
ArrayList<Album> albums = new ArrayList<>();
albums.add(album);
@SuppressWarnings("unchecked") Connection<Album> albumConnection = mock(Connection.class);
when(photosInterface.getAlbums(Mockito.any())).thenReturn(albumConnection);
when(albumConnection.getData()).thenReturn(albums);
// Set up example photo
Photo photo = new Photo();
photo.setId(PHOTO_ID);
photo.setCreatedTime(PHOTO_TIME);
Photo.Image image = new Photo.Image();
image.setSource(PHOTO_SOURCE);
photo.addImage(image);
photo.setName(PHOTO_NAME);
ArrayList<Photo> photos = new ArrayList<>();
photos.add(photo);
@SuppressWarnings("unchecked") Connection<Photo> photoConnection = mock(Connection.class);
when(photosInterface.getPhotos(ALBUM_ID, Optional.empty())).thenReturn(photoConnection);
when(photoConnection.getData()).thenReturn(photos);
final ImageStreamProvider imageStreamProvider = mock(ImageStreamProvider.class);
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("test.jpeg");
HttpURLConnection connection = mock(HttpURLConnection.class);
when(imageStreamProvider.getConnection(ArgumentMatchers.anyString())).thenReturn(connection);
when(connection.getInputStream()).thenReturn(inputStream);
final TemporaryPerJobDataStore store = mock(TemporaryPerJobDataStore.class);
facebookPhotosExporter = new FacebookPhotosExporter(new AppCredentials("key", "secret"), photosInterface, null, store, imageStreamProvider);
}
use of org.datatransferproject.types.transfer.auth.AppCredentials in project data-transfer-project by google.
the class FacebookVideosExporterTest method setUp.
@Before
public void setUp() throws CopyExceptionWithFailureReason {
FacebookVideosInterface videosInterface = mock(FacebookVideosInterface.class);
// Set up example video
Video video = new Video();
video.setId(VIDEO_ID);
video.setSource(VIDEO_SOURCE);
video.setDescription(VIDEO_NAME);
ArrayList<Video> videos = new ArrayList<>();
videos.add(video);
@SuppressWarnings("unchecked") Connection<Video> videoConnection = mock(Connection.class);
when(videosInterface.getVideos(Optional.empty())).thenReturn(videoConnection);
when(videoConnection.getData()).thenReturn(videos);
facebookVideosExporter = new FacebookVideosExporter(new AppCredentials("key", "secret"), videosInterface, null);
}
Aggregations