use of org.datatransferproject.spi.cloud.storage.JobStore in project data-transfer-project by google.
the class GooglePhotosImporterTest method retrieveAlbumStringOnlyOnce.
@Test
public void retrieveAlbumStringOnlyOnce() throws PermissionDeniedException, InvalidTokenException, IOException {
String albumId = "Album Id";
String albumName = "Album Name";
String albumDescription = "Album Description";
PhotoAlbum albumModel = new PhotoAlbum(albumId, albumName, albumDescription);
PortabilityJob portabilityJob = Mockito.mock(PortabilityJob.class);
Mockito.when(portabilityJob.userLocale()).thenReturn("it");
JobStore jobStore = Mockito.mock(JobStore.class);
Mockito.when(jobStore.findJob(uuid)).thenReturn(portabilityJob);
GoogleAlbum responseAlbum = new GoogleAlbum();
responseAlbum.setId(NEW_ALBUM_ID);
Mockito.when(googlePhotosInterface.createAlbum(any(GoogleAlbum.class))).thenReturn(responseAlbum);
GooglePhotosImporter sut = new GooglePhotosImporter(null, jobStore, null, null, googlePhotosInterface, imageStreamProvider, monitor, 1.0);
sut.importSingleAlbum(uuid, null, albumModel);
sut.importSingleAlbum(uuid, null, albumModel);
Mockito.verify(jobStore, atMostOnce()).findJob(uuid);
}
use of org.datatransferproject.spi.cloud.storage.JobStore in project data-transfer-project by google.
the class GooglePhotosImporterTest method importPhotoInTempStore.
@Test
public void importPhotoInTempStore() throws Exception {
PhotoModel photoModel = new PhotoModel(PHOTO_TITLE, IMG_URI, PHOTO_DESCRIPTION, JPEG_MEDIA_TYPE, "oldPhotoID1", OLD_ALBUM_ID, true);
Mockito.when(googlePhotosInterface.uploadPhotoContent(any())).thenReturn("token1");
JobStore jobStore = Mockito.mock(LocalJobStore.class);
Mockito.when(jobStore.getStream(any(), any())).thenReturn(new TemporaryPerJobDataStore.InputStreamWrapper(new ByteArrayInputStream("TestingBytes".getBytes())));
Mockito.doNothing().when(jobStore).removeData(any(), anyString());
GooglePhotosImporter googlePhotosImporter = new GooglePhotosImporter(null, jobStore, null, null, googlePhotosInterface, null, null, 1.0);
BatchMediaItemResponse batchMediaItemResponse = new BatchMediaItemResponse(new NewMediaItemResult[] { buildMediaItemResult("token1", Code.OK_VALUE) });
Mockito.when(googlePhotosInterface.createPhotos(any(NewMediaItemUpload.class))).thenReturn(batchMediaItemResponse);
UUID jobId = UUID.randomUUID();
long length = googlePhotosImporter.importPhotoBatch(jobId, Mockito.mock(TokensAndUrlAuthData.class), Lists.newArrayList(photoModel), executor, NEW_ALBUM_ID);
assertTrue(executor.isKeyCached(String.format("%s-%s", OLD_ALBUM_ID, "oldPhotoID1")));
Mockito.verify(jobStore, Mockito.times(1)).removeData(any(), anyString());
Mockito.verify(jobStore, Mockito.times(1)).getStream(any(), anyString());
}
use of org.datatransferproject.spi.cloud.storage.JobStore in project data-transfer-project by google.
the class GooglePhotosImporterTest method importAlbumWithITString.
@Test
public void importAlbumWithITString() throws PermissionDeniedException, InvalidTokenException, IOException {
String albumId = "Album Id";
String albumName = "Album Name";
String albumDescription = "Album Description";
PhotoAlbum albumModel = new PhotoAlbum(albumId, albumName, albumDescription);
PortabilityJob portabilityJob = Mockito.mock(PortabilityJob.class);
Mockito.when(portabilityJob.userLocale()).thenReturn("it");
JobStore jobStore = Mockito.mock(JobStore.class);
Mockito.when(jobStore.findJob(uuid)).thenReturn(portabilityJob);
GoogleAlbum responseAlbum = new GoogleAlbum();
responseAlbum.setId(NEW_ALBUM_ID);
Mockito.when(googlePhotosInterface.createAlbum(any(GoogleAlbum.class))).thenReturn(responseAlbum);
GooglePhotosImporter sut = new GooglePhotosImporter(null, jobStore, null, null, googlePhotosInterface, imageStreamProvider, monitor, 1.0);
sut.importSingleAlbum(uuid, null, albumModel);
ArgumentCaptor<GoogleAlbum> albumArgumentCaptor = ArgumentCaptor.forClass(GoogleAlbum.class);
Mockito.verify(googlePhotosInterface).createAlbum(albumArgumentCaptor.capture());
assertEquals(albumArgumentCaptor.getValue().getTitle(), albumName);
}
use of org.datatransferproject.spi.cloud.storage.JobStore in project data-transfer-project by google.
the class KoofrPhotosImporterTest method setUp.
@Before
public void setUp() throws Exception {
server = new MockWebServer();
server.start();
client = mock(KoofrClient.class);
clientFactory = mock(KoofrClientFactory.class);
when(clientFactory.create(any())).thenReturn(client);
monitor = mock(Monitor.class);
jobStore = mock(JobStore.class);
importer = new KoofrPhotosImporter(clientFactory, monitor, jobStore);
executor = mock(IdempotentImportExecutor.class);
when(executor.executeAndSwallowIOExceptions(any(), any(), any())).then((InvocationOnMock invocation) -> {
Callable<String> callable = invocation.getArgument(2);
return callable.call();
});
authData = new TokensAndUrlAuthData("acc", "refresh", "");
}
use of org.datatransferproject.spi.cloud.storage.JobStore in project data-transfer-project by google.
the class KoofrTransferExtension method initialize.
@Override
public void initialize(ExtensionContext context) {
// rather than throwing if called multiple times.
if (initialized)
return;
JobStore jobStore = context.getService(JobStore.class);
HttpTransport httpTransport = context.getService(HttpTransport.class);
JsonFactory jsonFactory = context.getService(JsonFactory.class);
OkHttpClient client = new OkHttpClient.Builder().build();
ObjectMapper mapper = new ObjectMapper();
AppCredentials appCredentials;
try {
appCredentials = context.getService(AppCredentialStore.class).getAppCredentials("KOOFR_KEY", "KOOFR_SECRET");
} catch (IOException e) {
Monitor monitor = context.getMonitor();
monitor.info(() -> "Unable to retrieve Koofr AppCredentials. Did you set KOOFR_KEY and KOOFR_SECRET?");
return;
}
// Create the KoofrCredentialFactory with the given {@link AppCredentials}.
KoofrCredentialFactory credentialFactory = new KoofrCredentialFactory(httpTransport, jsonFactory, appCredentials);
Monitor monitor = context.getMonitor();
int fileUploadReadTimeout = context.getSetting("koofrFileUploadReadTimeout", 60000);
int fileUploadWriteTimeout = context.getSetting("koofrFileUploadWriteTimeout", 60000);
monitor.info(() -> format("Configuring Koofr HTTP file upload client with read timeout %d ms and write timeout %d ms", fileUploadReadTimeout, fileUploadWriteTimeout));
OkHttpClient fileUploadClient = client.newBuilder().readTimeout(fileUploadReadTimeout, TimeUnit.MILLISECONDS).writeTimeout(fileUploadReadTimeout, TimeUnit.MILLISECONDS).build();
KoofrClientFactory koofrClientFactory = new KoofrClientFactory(BASE_API_URL, client, fileUploadClient, mapper, monitor, credentialFactory);
ImmutableMap.Builder<String, Importer> importBuilder = ImmutableMap.builder();
importBuilder.put(PHOTOS, new KoofrPhotosImporter(koofrClientFactory, monitor, jobStore));
importBuilder.put(VIDEOS, new KoofrVideosImporter(koofrClientFactory, monitor));
importerMap = importBuilder.build();
ImmutableMap.Builder<String, Exporter> exportBuilder = ImmutableMap.builder();
exportBuilder.put(PHOTOS, new KoofrPhotosExporter(koofrClientFactory, monitor));
exportBuilder.put(VIDEOS, new KoofrVideosExporter(koofrClientFactory, monitor));
exporterMap = exportBuilder.build();
initialized = true;
}
Aggregations