Search in sources :

Example 1 with ImportResult

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);
}
Also used : ImportResult(org.datatransferproject.spi.transfer.provider.ImportResult) VideosContainerResource(org.datatransferproject.types.common.models.videos.VideosContainerResource) Test(org.junit.Test)

Example 2 with ImportResult

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);
}
Also used : ImportResult(org.datatransferproject.spi.transfer.provider.ImportResult) Test(org.junit.Test)

Example 3 with ImportResult

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);
}
Also used : StatusUpdate(twitter4j.StatusUpdate) ImportResult(org.datatransferproject.spi.transfer.provider.ImportResult) PhotoModel(org.datatransferproject.types.common.models.photos.PhotoModel) InputStreamContent(com.google.api.client.http.InputStreamContent) Twitter(twitter4j.Twitter) IOException(java.io.IOException)

Example 4 with ImportResult

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);
}
Also used : ImportResult(org.datatransferproject.spi.transfer.provider.ImportResult) TokenAuthData(org.datatransferproject.types.transfer.auth.TokenAuthData) FakeIdempotentImportExecutor(org.datatransferproject.test.types.FakeIdempotentImportExecutor) MicrosoftTransferExtension(org.datatransferproject.transfer.microsoft.MicrosoftTransferExtension) ContactsModelWrapper(org.datatransferproject.types.common.models.contacts.ContactsModelWrapper) AuthTestDriver(org.datatransferproject.auth.microsoft.harness.AuthTestDriver) Importer(org.datatransferproject.spi.transfer.provider.Importer)

Example 5 with ImportResult

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);
}
Also used : Buffer(okio.Buffer) Response(okhttp3.Response) PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) Call(okhttp3.Call) ImportResult(org.datatransferproject.spi.transfer.provider.ImportResult) Request(okhttp3.Request) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) IOException(java.io.IOException) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Aggregations

ImportResult (org.datatransferproject.spi.transfer.provider.ImportResult)27 Test (org.junit.Test)14 IOException (java.io.IOException)11 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)8 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)6 UUID (java.util.UUID)5 Map (java.util.Map)4 PhotoModel (org.datatransferproject.types.common.models.photos.PhotoModel)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 List (java.util.List)3 Request (okhttp3.Request)3 Response (okhttp3.Response)3 ResponseBody (okhttp3.ResponseBody)3 AppCredentials (org.datatransferproject.types.transfer.auth.AppCredentials)3 Stopwatch (com.google.common.base.Stopwatch)2 LinkedHashMap (java.util.LinkedHashMap)2 Call (okhttp3.Call)2 Importer (org.datatransferproject.spi.transfer.provider.Importer)2 ContactsModelWrapper (org.datatransferproject.types.common.models.contacts.ContactsModelWrapper)2 TaskListModel (org.datatransferproject.types.common.models.tasks.TaskListModel)2