use of org.datatransferproject.spi.transfer.provider.ImportResult in project data-transfer-project by google.
the class BackblazeVideosImporterTest method testNullVideos.
@Test
public void testNullVideos() throws Exception {
VideosContainerResource data = mock(VideosContainerResource.class);
when(data.getVideos()).thenReturn(null);
BackblazeVideosImporter sut = new BackblazeVideosImporter(monitor, dataStore, streamProvider, clientFactory);
ImportResult result = sut.importItem(UUID.randomUUID(), executor, authData, data);
assertEquals(ImportResult.OK, result);
}
use of org.datatransferproject.spi.transfer.provider.ImportResult in project data-transfer-project by google.
the class BackblazePhotosImporterTest method testNullData.
@Test
public void testNullData() throws Exception {
BackblazePhotosImporter sut = new BackblazePhotosImporter(monitor, dataStore, streamProvider, clientFactory);
ImportResult result = sut.importItem(UUID.randomUUID(), executor, authData, null);
assertEquals(ImportResult.OK, result);
}
use of org.datatransferproject.spi.transfer.provider.ImportResult in project data-transfer-project by google.
the class TwitterPhotosImporter method importItem.
@Override
public ImportResult importItem(UUID jobId, IdempotentImportExecutor idempotentExecutor, TokenSecretAuthData authData, PhotosContainerResource data) throws Exception {
Twitter twitterApi = TwitterApiWrapper.getInstance(appCredentials, authData);
for (PhotoModel image : data.getPhotos()) {
try {
StatusUpdate update = new StatusUpdate(image.getDescription());
InputStreamContent content = new InputStreamContent(null, getImageAsStream(image.getFetchableUrl()));
update.media(image.getTitle(), content.getInputStream());
idempotentExecutor.executeAndSwallowIOExceptions(IdempotentImportExecutorHelper.getPhotoIdempotentId(image), image.getTitle(), () -> twitterApi.tweets().updateStatus(update));
} catch (IOException e) {
monitor.severe(() -> "Error importing twitter photo", e);
return new ImportResult(e);
}
}
return new ImportResult(ResultType.OK);
}
use of org.datatransferproject.spi.transfer.provider.ImportResult in project data-transfer-project by google.
the class LocalImportTestRunner method main.
@SuppressWarnings("unchecked")
public static void main(String... args) throws Exception {
AuthTestDriver authTestDriver = new AuthTestDriver();
MicrosoftTransferExtension serviceProvider = new MicrosoftTransferExtension();
TokenAuthData token = authTestDriver.getOAuthTokenCode();
Importer<TokenAuthData, ContactsModelWrapper> contacts = (Importer<TokenAuthData, ContactsModelWrapper>) serviceProvider.getImporter("CONTACTS");
ContactsModelWrapper wrapper = new ContactsModelWrapper(createCards());
FakeIdempotentImportExecutor executor = new FakeIdempotentImportExecutor();
ImportResult result = contacts.importItem(UUID.randomUUID(), executor, token, wrapper);
}
use of org.datatransferproject.spi.transfer.provider.ImportResult 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);
}
Aggregations